mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-08 10:08:08 +02:00
Add temperature property for batteries
Linux's power_supply class supports a temperature attribute, which is supported by many battery drivers. Add a new property to export this information and support this property in Linux. https://bugs.freedesktop.org/show_bug.cgi?id=68338 Signed-off-by: Seth Forshee <seth.forshee@canonical.com> Signed-off-by: Martin Pitt <martinpitt@gnome.org>
This commit is contained in:
parent
03f67aabfe
commit
eaf86482a9
4 changed files with 59 additions and 0 deletions
|
|
@ -85,6 +85,7 @@ struct _UpDevicePrivate
|
|||
gint64 time_to_empty; /* seconds */
|
||||
gint64 time_to_full; /* seconds */
|
||||
gdouble percentage; /* percent */
|
||||
gdouble temperature; /* degrees C */
|
||||
gboolean recall_notice;
|
||||
gchar *recall_vendor;
|
||||
gchar *recall_url;
|
||||
|
|
@ -117,6 +118,7 @@ enum {
|
|||
PROP_TIME_TO_EMPTY,
|
||||
PROP_TIME_TO_FULL,
|
||||
PROP_PERCENTAGE,
|
||||
PROP_TEMPERATURE,
|
||||
PROP_RECALL_NOTICE,
|
||||
PROP_RECALL_VENDOR,
|
||||
PROP_RECALL_URL,
|
||||
|
|
@ -205,6 +207,8 @@ up_device_collect_props_cb (const char *key, const GValue *value, UpDevice *devi
|
|||
device->priv->time_to_empty = g_value_get_int64 (value);
|
||||
} else if (g_strcmp0 (key, "Percentage") == 0) {
|
||||
device->priv->percentage = g_value_get_double (value);
|
||||
} else if (g_strcmp0 (key, "Temperature") == 0) {
|
||||
device->priv->temperature = g_value_get_double (value);
|
||||
} else if (g_strcmp0 (key, "Technology") == 0) {
|
||||
device->priv->technology = g_value_get_uint (value);
|
||||
} else if (g_strcmp0 (key, "IsPresent") == 0) {
|
||||
|
|
@ -512,6 +516,8 @@ up_device_to_text (UpDevice *device)
|
|||
device->priv->kind == UP_DEVICE_KIND_UPS)
|
||||
g_string_append_printf (string, " percentage: %g%%\n", device->priv->percentage);
|
||||
if (device->priv->kind == UP_DEVICE_KIND_BATTERY) {
|
||||
if (device->priv->temperature > 0)
|
||||
g_string_append_printf (string, " temperature: %g degrees C\n", device->priv->temperature);
|
||||
if (device->priv->capacity > 0)
|
||||
g_string_append_printf (string, " capacity: %g%%\n", device->priv->capacity);
|
||||
}
|
||||
|
|
@ -827,6 +833,9 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa
|
|||
case PROP_PERCENTAGE:
|
||||
device->priv->percentage = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_TEMPERATURE:
|
||||
device->priv->temperature = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_TECHNOLOGY:
|
||||
device->priv->technology = g_value_get_uint (value);
|
||||
break;
|
||||
|
|
@ -931,6 +940,9 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
|
|||
case PROP_PERCENTAGE:
|
||||
g_value_set_double (value, device->priv->percentage);
|
||||
break;
|
||||
case PROP_TEMPERATURE:
|
||||
g_value_set_double (value, device->priv->temperature);
|
||||
break;
|
||||
case PROP_RECALL_NOTICE:
|
||||
g_value_set_boolean (value, device->priv->recall_notice);
|
||||
break;
|
||||
|
|
@ -1297,6 +1309,18 @@ up_device_class_init (UpDeviceClass *klass)
|
|||
g_param_spec_double ("percentage", NULL, NULL,
|
||||
0.0, 100.f, 100.0,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpDevice:temperature:
|
||||
*
|
||||
* The temperature of the device in degrees Celsius.
|
||||
*
|
||||
* Since: 0.9.22
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_TEMPERATURE,
|
||||
g_param_spec_double ("temperature", NULL, NULL,
|
||||
0.0, G_MAXDOUBLE, 0.0,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpDevice:recall-notice:
|
||||
*
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ up_device_supply_reset_values (UpDeviceSupply *supply)
|
|||
"time-to-empty", (gint64) 0,
|
||||
"time-to-full", (gint64) 0,
|
||||
"percentage", (gdouble) 0.0,
|
||||
"temperature", (gdouble) 0.0,
|
||||
"technology", UP_DEVICE_TECHNOLOGY_UNKNOWN,
|
||||
NULL);
|
||||
}
|
||||
|
|
@ -490,6 +491,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
|
|||
gdouble voltage;
|
||||
gint64 time_to_empty;
|
||||
gint64 time_to_full;
|
||||
gdouble temp;
|
||||
gchar *manufacturer = NULL;
|
||||
gchar *model_name = NULL;
|
||||
gchar *serial_number = NULL;
|
||||
|
|
@ -785,6 +787,9 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
|
|||
if (time_to_full > (20 * 60 * 60)) /* 20 hours for charging */
|
||||
time_to_full = 0;
|
||||
|
||||
/* get temperature */
|
||||
temp = sysfs_get_double(native_path, "temp") / 10.0;
|
||||
|
||||
/* check if the energy value has changed and, if that's the case,
|
||||
* store the new values in the buffer. */
|
||||
if (up_device_supply_push_new_energy (supply, energy))
|
||||
|
|
@ -811,6 +816,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
|
|||
"voltage", voltage,
|
||||
"time-to-empty", time_to_empty,
|
||||
"time-to-full", time_to_full,
|
||||
"temperature", temp,
|
||||
NULL);
|
||||
|
||||
out:
|
||||
|
|
|
|||
|
|
@ -544,6 +544,19 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2
|
|||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="Temperature" type="d" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The temperature of the device in degrees Celsius. This property is
|
||||
only valid if the property
|
||||
<doc:ref type="property" to="Source:Type">type</doc:ref>
|
||||
has the value "battery".
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="IsPresent" type="b" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ struct UpDevicePrivate
|
|||
gint64 time_to_empty; /* seconds */
|
||||
gint64 time_to_full; /* seconds */
|
||||
gdouble percentage; /* percent */
|
||||
gdouble temperature; /* degrees C */
|
||||
gboolean recall_notice;
|
||||
gchar *recall_vendor;
|
||||
gchar *recall_url;
|
||||
|
|
@ -110,6 +111,7 @@ enum {
|
|||
PROP_TIME_TO_EMPTY,
|
||||
PROP_TIME_TO_FULL,
|
||||
PROP_PERCENTAGE,
|
||||
PROP_TEMPERATURE,
|
||||
PROP_TECHNOLOGY,
|
||||
PROP_RECALL_NOTICE,
|
||||
PROP_RECALL_VENDOR,
|
||||
|
|
@ -249,6 +251,9 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
|
|||
case PROP_PERCENTAGE:
|
||||
g_value_set_double (value, device->priv->percentage);
|
||||
break;
|
||||
case PROP_TEMPERATURE:
|
||||
g_value_set_double (value, device->priv->temperature);
|
||||
break;
|
||||
case PROP_TECHNOLOGY:
|
||||
g_value_set_uint (value, device->priv->technology);
|
||||
break;
|
||||
|
|
@ -352,6 +357,9 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa
|
|||
case PROP_PERCENTAGE:
|
||||
device->priv->percentage = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_TEMPERATURE:
|
||||
device->priv->temperature = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_TECHNOLOGY:
|
||||
device->priv->technology = g_value_get_uint (value);
|
||||
break;
|
||||
|
|
@ -1169,6 +1177,14 @@ up_device_class_init (UpDeviceClass *klass)
|
|||
g_param_spec_double ("percentage", NULL, NULL,
|
||||
0.0, 100.f, 100.0,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpDevice:temperature:
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_TEMPERATURE,
|
||||
g_param_spec_double ("temperature", NULL, NULL,
|
||||
0.0, G_MAXDOUBLE, 0.0,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpDevice:recall-notice:
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue