Fix Daikin sensor temperature_unit & cleanup (#34116)
This commit is contained in:
parent
5d649b2541
commit
fffda27385
1 changed files with 7 additions and 24 deletions
|
@ -1,17 +1,11 @@
|
||||||
"""Support for Daikin AC sensors."""
|
"""Support for Daikin AC sensors."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.const import CONF_ICON, CONF_NAME, CONF_TYPE
|
from homeassistant.const import CONF_ICON, CONF_NAME, TEMP_CELSIUS
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util.unit_system import UnitSystem
|
|
||||||
|
|
||||||
from . import DOMAIN as DAIKIN_DOMAIN
|
from . import DOMAIN as DAIKIN_DOMAIN
|
||||||
from .const import (
|
from .const import ATTR_INSIDE_TEMPERATURE, ATTR_OUTSIDE_TEMPERATURE, SENSOR_TYPES
|
||||||
ATTR_INSIDE_TEMPERATURE,
|
|
||||||
ATTR_OUTSIDE_TEMPERATURE,
|
|
||||||
SENSOR_TYPE_TEMPERATURE,
|
|
||||||
SENSOR_TYPES,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -30,30 +24,19 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
sensors = [ATTR_INSIDE_TEMPERATURE]
|
sensors = [ATTR_INSIDE_TEMPERATURE]
|
||||||
if daikin_api.device.support_outside_temperature:
|
if daikin_api.device.support_outside_temperature:
|
||||||
sensors.append(ATTR_OUTSIDE_TEMPERATURE)
|
sensors.append(ATTR_OUTSIDE_TEMPERATURE)
|
||||||
async_add_entities(
|
async_add_entities([DaikinClimateSensor(daikin_api, sensor) for sensor in sensors])
|
||||||
[
|
|
||||||
DaikinClimateSensor(daikin_api, sensor, hass.config.units)
|
|
||||||
for sensor in sensors
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class DaikinClimateSensor(Entity):
|
class DaikinClimateSensor(Entity):
|
||||||
"""Representation of a Sensor."""
|
"""Representation of a Sensor."""
|
||||||
|
|
||||||
def __init__(self, api, monitored_state, units: UnitSystem, name=None) -> None:
|
def __init__(self, api, monitored_state) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._api = api
|
self._api = api
|
||||||
self._sensor = SENSOR_TYPES.get(monitored_state)
|
self._sensor = SENSOR_TYPES[monitored_state]
|
||||||
if name is None:
|
self._name = f"{api.name} {self._sensor[CONF_NAME]}"
|
||||||
name = f"{self._sensor[CONF_NAME]} {api.name}"
|
|
||||||
|
|
||||||
self._name = f"{name} {monitored_state.replace('_', ' ')}"
|
|
||||||
self._device_attribute = monitored_state
|
self._device_attribute = monitored_state
|
||||||
|
|
||||||
if self._sensor[CONF_TYPE] == SENSOR_TYPE_TEMPERATURE:
|
|
||||||
self._unit_of_measurement = units.temperature_unit
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
|
@ -81,7 +64,7 @@ class DaikinClimateSensor(Entity):
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return self._unit_of_measurement
|
return TEMP_CELSIUS
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue