mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +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
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
||||
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
|
||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, PERCENTAGE, TEMP_CELSIUS
|
||||
|
||||
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 temp_type in types:
|
||||
new_sensor = OctoPrintSensor(
|
||||
octoprint_api,
|
||||
temp_type,
|
||||
temp_type,
|
||||
name,
|
||||
SENSOR_TYPES[octo_type][3],
|
||||
SENSOR_TYPES[octo_type][0],
|
||||
SENSOR_TYPES[octo_type][1],
|
||||
tool,
|
||||
api=octoprint_api,
|
||||
condition=temp_type,
|
||||
sensor_type=temp_type,
|
||||
sensor_name=name,
|
||||
unit=SENSOR_TYPES[octo_type][3],
|
||||
endpoint=SENSOR_TYPES[octo_type][0],
|
||||
group=SENSOR_TYPES[octo_type][1],
|
||||
tool=tool,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
)
|
||||
devices.append(new_sensor)
|
||||
else:
|
||||
new_sensor = OctoPrintSensor(
|
||||
octoprint_api,
|
||||
octo_type,
|
||||
SENSOR_TYPES[octo_type][2],
|
||||
name,
|
||||
SENSOR_TYPES[octo_type][3],
|
||||
SENSOR_TYPES[octo_type][0],
|
||||
SENSOR_TYPES[octo_type][1],
|
||||
None,
|
||||
SENSOR_TYPES[octo_type][4],
|
||||
api=octoprint_api,
|
||||
condition=octo_type,
|
||||
sensor_type=SENSOR_TYPES[octo_type][2],
|
||||
sensor_name=name,
|
||||
unit=SENSOR_TYPES[octo_type][3],
|
||||
endpoint=SENSOR_TYPES[octo_type][0],
|
||||
group=SENSOR_TYPES[octo_type][1],
|
||||
icon=SENSOR_TYPES[octo_type][4],
|
||||
)
|
||||
devices.append(new_sensor)
|
||||
add_entities(devices, True)
|
||||
@ -84,6 +85,8 @@ class OctoPrintSensor(SensorEntity):
|
||||
group,
|
||||
tool=None,
|
||||
icon=None,
|
||||
device_class=None,
|
||||
state_class=None,
|
||||
):
|
||||
"""Initialize a new OctoPrint sensor."""
|
||||
self.sensor_name = sensor_name
|
||||
@ -99,6 +102,8 @@ class OctoPrintSensor(SensorEntity):
|
||||
self.api_group = group
|
||||
self.api_tool = tool
|
||||
self._icon = icon
|
||||
self._attr_device_class = device_class
|
||||
self._attr_state_class = state_class
|
||||
_LOGGER.debug("Created OctoPrint sensor %r", self)
|
||||
|
||||
@property
|
||||
|
Loading…
x
Reference in New Issue
Block a user