mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add device class to temperature sensors for octoprint (#56997)
This commit is contained in:
parent
42803e6ac0
commit
f8d0f76721
@ -3,8 +3,8 @@ import logging
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
|
||||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, PERCENTAGE, TEMP_CELSIUS
|
||||||
|
|
||||||
from . import DOMAIN as COMPONENT_DOMAIN, SENSOR_TYPES
|
from . import DOMAIN as COMPONENT_DOMAIN, SENSOR_TYPES
|
||||||
|
|
||||||
@ -44,27 +44,28 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
for tool in tools:
|
for tool in tools:
|
||||||
for temp_type in types:
|
for temp_type in types:
|
||||||
new_sensor = OctoPrintSensor(
|
new_sensor = OctoPrintSensor(
|
||||||
octoprint_api,
|
api=octoprint_api,
|
||||||
temp_type,
|
condition=temp_type,
|
||||||
temp_type,
|
sensor_type=temp_type,
|
||||||
name,
|
sensor_name=name,
|
||||||
SENSOR_TYPES[octo_type][3],
|
unit=SENSOR_TYPES[octo_type][3],
|
||||||
SENSOR_TYPES[octo_type][0],
|
endpoint=SENSOR_TYPES[octo_type][0],
|
||||||
SENSOR_TYPES[octo_type][1],
|
group=SENSOR_TYPES[octo_type][1],
|
||||||
tool,
|
tool=tool,
|
||||||
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
)
|
)
|
||||||
devices.append(new_sensor)
|
devices.append(new_sensor)
|
||||||
else:
|
else:
|
||||||
new_sensor = OctoPrintSensor(
|
new_sensor = OctoPrintSensor(
|
||||||
octoprint_api,
|
api=octoprint_api,
|
||||||
octo_type,
|
condition=octo_type,
|
||||||
SENSOR_TYPES[octo_type][2],
|
sensor_type=SENSOR_TYPES[octo_type][2],
|
||||||
name,
|
sensor_name=name,
|
||||||
SENSOR_TYPES[octo_type][3],
|
unit=SENSOR_TYPES[octo_type][3],
|
||||||
SENSOR_TYPES[octo_type][0],
|
endpoint=SENSOR_TYPES[octo_type][0],
|
||||||
SENSOR_TYPES[octo_type][1],
|
group=SENSOR_TYPES[octo_type][1],
|
||||||
None,
|
icon=SENSOR_TYPES[octo_type][4],
|
||||||
SENSOR_TYPES[octo_type][4],
|
|
||||||
)
|
)
|
||||||
devices.append(new_sensor)
|
devices.append(new_sensor)
|
||||||
add_entities(devices, True)
|
add_entities(devices, True)
|
||||||
@ -84,6 +85,8 @@ class OctoPrintSensor(SensorEntity):
|
|||||||
group,
|
group,
|
||||||
tool=None,
|
tool=None,
|
||||||
icon=None,
|
icon=None,
|
||||||
|
device_class=None,
|
||||||
|
state_class=None,
|
||||||
):
|
):
|
||||||
"""Initialize a new OctoPrint sensor."""
|
"""Initialize a new OctoPrint sensor."""
|
||||||
self.sensor_name = sensor_name
|
self.sensor_name = sensor_name
|
||||||
@ -99,6 +102,8 @@ class OctoPrintSensor(SensorEntity):
|
|||||||
self.api_group = group
|
self.api_group = group
|
||||||
self.api_tool = tool
|
self.api_tool = tool
|
||||||
self._icon = icon
|
self._icon = icon
|
||||||
|
self._attr_device_class = device_class
|
||||||
|
self._attr_state_class = state_class
|
||||||
_LOGGER.debug("Created OctoPrint sensor %r", self)
|
_LOGGER.debug("Created OctoPrint sensor %r", self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user