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."""
|
||||
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.util.unit_system import UnitSystem
|
||||
|
||||
from . import DOMAIN as DAIKIN_DOMAIN
|
||||
from .const import (
|
||||
ATTR_INSIDE_TEMPERATURE,
|
||||
ATTR_OUTSIDE_TEMPERATURE,
|
||||
SENSOR_TYPE_TEMPERATURE,
|
||||
SENSOR_TYPES,
|
||||
)
|
||||
from .const import ATTR_INSIDE_TEMPERATURE, ATTR_OUTSIDE_TEMPERATURE, SENSOR_TYPES
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -30,30 +24,19 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
sensors = [ATTR_INSIDE_TEMPERATURE]
|
||||
if daikin_api.device.support_outside_temperature:
|
||||
sensors.append(ATTR_OUTSIDE_TEMPERATURE)
|
||||
async_add_entities(
|
||||
[
|
||||
DaikinClimateSensor(daikin_api, sensor, hass.config.units)
|
||||
for sensor in sensors
|
||||
]
|
||||
)
|
||||
async_add_entities([DaikinClimateSensor(daikin_api, sensor) for sensor in sensors])
|
||||
|
||||
|
||||
class DaikinClimateSensor(Entity):
|
||||
"""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."""
|
||||
self._api = api
|
||||
self._sensor = SENSOR_TYPES.get(monitored_state)
|
||||
if name is None:
|
||||
name = f"{self._sensor[CONF_NAME]} {api.name}"
|
||||
|
||||
self._name = f"{name} {monitored_state.replace('_', ' ')}"
|
||||
self._sensor = SENSOR_TYPES[monitored_state]
|
||||
self._name = f"{api.name} {self._sensor[CONF_NAME]}"
|
||||
self._device_attribute = monitored_state
|
||||
|
||||
if self._sensor[CONF_TYPE] == SENSOR_TYPE_TEMPERATURE:
|
||||
self._unit_of_measurement = units.temperature_unit
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique ID."""
|
||||
|
@ -81,7 +64,7 @@ class DaikinClimateSensor(Entity):
|
|||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit_of_measurement
|
||||
return TEMP_CELSIUS
|
||||
|
||||
async def async_update(self):
|
||||
"""Retrieve latest state."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue