mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Use _attr_* in hddtemp (#61721)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
482e457814
commit
782229ff44
@ -6,13 +6,16 @@ from telnetlib import Telnet
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import (
|
||||||
|
PLATFORM_SCHEMA,
|
||||||
|
SensorDeviceClass,
|
||||||
|
SensorEntity,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_DISKS,
|
CONF_DISKS,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
)
|
)
|
||||||
@ -63,34 +66,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class HddTempSensor(SensorEntity):
|
class HddTempSensor(SensorEntity):
|
||||||
"""Representation of a HDDTemp sensor."""
|
"""Representation of a HDDTemp sensor."""
|
||||||
|
|
||||||
|
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
|
|
||||||
def __init__(self, name, disk, hddtemp):
|
def __init__(self, name, disk, hddtemp):
|
||||||
"""Initialize a HDDTemp sensor."""
|
"""Initialize a HDDTemp sensor."""
|
||||||
self.hddtemp = hddtemp
|
self.hddtemp = hddtemp
|
||||||
self.disk = disk
|
self.disk = disk
|
||||||
self._name = f"{name} {disk}"
|
self._attr_name = f"{name} {disk}"
|
||||||
self._state = None
|
|
||||||
self._details = None
|
self._details = None
|
||||||
self._unit = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def native_value(self):
|
|
||||||
"""Return the state of the device."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return DEVICE_CLASS_TEMPERATURE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def native_unit_of_measurement(self):
|
|
||||||
"""Return the unit the value is expressed in."""
|
|
||||||
return self._unit
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
@ -104,13 +87,13 @@ class HddTempSensor(SensorEntity):
|
|||||||
|
|
||||||
if self.hddtemp.data and self.disk in self.hddtemp.data:
|
if self.hddtemp.data and self.disk in self.hddtemp.data:
|
||||||
self._details = self.hddtemp.data[self.disk].split("|")
|
self._details = self.hddtemp.data[self.disk].split("|")
|
||||||
self._state = self._details[2]
|
self._attr_native_value = self._details[2]
|
||||||
if self._details is not None and self._details[3] == "F":
|
if self._details is not None and self._details[3] == "F":
|
||||||
self._unit = TEMP_FAHRENHEIT
|
self._attr_native_unit_of_measurement = TEMP_FAHRENHEIT
|
||||||
else:
|
else:
|
||||||
self._unit = TEMP_CELSIUS
|
self._attr_native_unit_of_measurement = TEMP_CELSIUS
|
||||||
else:
|
else:
|
||||||
self._state = None
|
self._attr_native_value = None
|
||||||
|
|
||||||
|
|
||||||
class HddTempData:
|
class HddTempData:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user