Add daiking humidity sensor
This commit is contained in:
40
src/components/daikin/const.py
Normal file
40
src/components/daikin/const.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
"""Constants for Daikin."""
|
||||||
|
from homeassistant.const import CONF_ICON, CONF_NAME, CONF_TYPE
|
||||||
|
|
||||||
|
ATTR_TARGET_TEMPERATURE = "target_temperature"
|
||||||
|
ATTR_INSIDE_TEMPERATURE = "inside_temperature"
|
||||||
|
ATTR_OUTSIDE_TEMPERATURE = "outside_temperature"
|
||||||
|
|
||||||
|
ATTR_STATE_ON = "on"
|
||||||
|
ATTR_STATE_OFF = "off"
|
||||||
|
|
||||||
|
SENSOR_TYPE_TEMPERATURE = "temperature"
|
||||||
|
SENSOR_TYPE_HUMIDITY = "humidity"
|
||||||
|
|
||||||
|
SENSOR_TYPES = {
|
||||||
|
ATTR_INSIDE_TEMPERATURE: {
|
||||||
|
CONF_NAME: "Inside Temperature",
|
||||||
|
CONF_ICON: "mdi:thermometer",
|
||||||
|
CONF_TYPE: SENSOR_TYPE_TEMPERATURE,
|
||||||
|
},
|
||||||
|
ATTR_OUTSIDE_TEMPERATURE: {
|
||||||
|
CONF_NAME: "Outside Temperature",
|
||||||
|
CONF_ICON: "mdi:thermometer",
|
||||||
|
CONF_TYPE: SENSOR_TYPE_TEMPERATURE,
|
||||||
|
},
|
||||||
|
"hhum": {
|
||||||
|
CONF_NAME: "Humidity",
|
||||||
|
CONF_ICON: "mdi:percent",
|
||||||
|
CONF_TYPE: SENSOR_TYPE_HUMIDITY,
|
||||||
|
},
|
||||||
|
"shum": {
|
||||||
|
CONF_NAME: "Target Humidity",
|
||||||
|
CONF_ICON: "mdi:percent",
|
||||||
|
CONF_TYPE: SENSOR_TYPE_HUMIDITY,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
KEY_MAC = "mac"
|
||||||
|
KEY_IP = "ip"
|
||||||
|
|
||||||
|
TIMEOUT = 60
|
||||||
88
src/components/daikin/sensor.py
Normal file
88
src/components/daikin/sensor.py
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
"""Support for Daikin AC sensors."""
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from homeassistant.const import CONF_ICON, CONF_NAME, CONF_TYPE, TEMP_CELSIUS, UNIT_PERCENTAGE
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
from . import DOMAIN as DAIKIN_DOMAIN
|
||||||
|
from .const import ATTR_INSIDE_TEMPERATURE, ATTR_OUTSIDE_TEMPERATURE, SENSOR_TYPES, SENSOR_TYPE_HUMIDITY
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
|
"""Old way of setting up the Daikin sensors.
|
||||||
|
|
||||||
|
Can only be called when a user accidentally mentions the platform in their
|
||||||
|
config. But even in that case it would have been ignored.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
|
"""Set up Daikin climate based on config_entry."""
|
||||||
|
daikin_api = hass.data[DAIKIN_DOMAIN].get(entry.entry_id)
|
||||||
|
sensors = [ATTR_INSIDE_TEMPERATURE]
|
||||||
|
if daikin_api.device.support_outside_temperature:
|
||||||
|
sensors.append(ATTR_OUTSIDE_TEMPERATURE)
|
||||||
|
|
||||||
|
if daikin_api.device.values.get("hhum").replace("-", ""):
|
||||||
|
sensors.append("hhum")
|
||||||
|
sensors.append("shum")
|
||||||
|
|
||||||
|
async_add_entities([DaikinClimateSensor(daikin_api, sensor) for sensor in sensors])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DaikinClimateSensor(Entity):
|
||||||
|
"""Representation of a Sensor."""
|
||||||
|
|
||||||
|
def __init__(self, api, monitored_state) -> None:
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
self._api = api
|
||||||
|
self._sensor = SENSOR_TYPES[monitored_state]
|
||||||
|
self._name = f"{api.name} {self._sensor[CONF_NAME]}"
|
||||||
|
self._device_attribute = monitored_state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return a unique ID."""
|
||||||
|
return f"{self._api.mac}-{self._device_attribute}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Icon to use in the frontend, if any."""
|
||||||
|
return self._sensor[CONF_ICON]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the sensor."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
"""Return the state of the sensor."""
|
||||||
|
if self._device_attribute == "hhum":
|
||||||
|
return int(self._api.device.values.get("hhum").replace("-", "0"))
|
||||||
|
if self._device_attribute == "bhum":
|
||||||
|
return int(self._api.device.values.get("bhum").replace("-", "0"))
|
||||||
|
if self._device_attribute == ATTR_INSIDE_TEMPERATURE:
|
||||||
|
return self._api.device.inside_temperature
|
||||||
|
if self._device_attribute == ATTR_OUTSIDE_TEMPERATURE:
|
||||||
|
return self._api.device.outside_temperature
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unit_of_measurement(self):
|
||||||
|
"""Return the unit of measurement."""
|
||||||
|
if self._sensor[CONF_TYPE] == SENSOR_TYPE_HUMIDITY:
|
||||||
|
return UNIT_PERCENTAGE
|
||||||
|
return TEMP_CELSIUS
|
||||||
|
|
||||||
|
async def async_update(self):
|
||||||
|
"""Retrieve latest state."""
|
||||||
|
await self._api.async_update()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self):
|
||||||
|
"""Return a device description for device registry."""
|
||||||
|
return self._api.device_info
|
||||||
Reference in New Issue
Block a user