From f8d0f76721340f174333d180931586c537fce227 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 15 Oct 2021 09:45:04 -0700 Subject: [PATCH] Add device class to temperature sensors for octoprint (#56997) --- homeassistant/components/octoprint/sensor.py | 43 +++++++++++--------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/octoprint/sensor.py b/homeassistant/components/octoprint/sensor.py index 5b2b0af494c..d456813a4ff 100644 --- a/homeassistant/components/octoprint/sensor.py +++ b/homeassistant/components/octoprint/sensor.py @@ -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