Răsfoiți Sursa

Add binary_sensor for Tank Full status of dehumidifiers

Incude a fault_code attribute for debugging/further info
Jason Rumney 5 ani în urmă
părinte
comite
5fd6dcde1d

+ 6 - 0
README.md

@@ -31,6 +31,9 @@ Current temperature is displayed, and current humidity is available as a propert
 **Lock** (heaters and dehumidifiers)
 **Lock** (heaters and dehumidifiers)
 * **Child lock** (on/off)
 * **Child lock** (on/off)
 
 
+**Binary Sensor** (dehumidifiers)
+* **Tank full** (on/off)
+
 There was previously a sensor option, however this is easily achieved using a [template sensor](https://www.home-assistant.io/integrations/template/) and therefore is no longer supported.
 There was previously a sensor option, however this is easily achieved using a [template sensor](https://www.home-assistant.io/integrations/template/) and therefore is no longer supported.
 
 
 ---
 ---
@@ -101,6 +104,9 @@ goldair_climate:
 
 
     *Default value: false* 
     *Default value: false* 
 
 
+#### tank_full
+    *(boolean) (Optional)* Whether to surface this appliances's tank full sensor as a binary_sensor device (only supported for dehumidifiers).
+
 Heater gotchas
 Heater gotchas
 --------------
 --------------
 Goldair heaters have individual target temperatures for their Comfort and Eco modes, whereas Home Assistant only supports
 Goldair heaters have individual target temperatures for their Comfort and Eco modes, whereas Home Assistant only supports

+ 4 - 0
custom_components/goldair_climate/__init__.py

@@ -33,6 +33,7 @@ CONF_TYPE_FAN = 'fan'
 CONF_CLIMATE = 'climate'
 CONF_CLIMATE = 'climate'
 CONF_DISPLAY_LIGHT = 'display_light'
 CONF_DISPLAY_LIGHT = 'display_light'
 CONF_CHILD_LOCK = 'child_lock'
 CONF_CHILD_LOCK = 'child_lock'
+CONF_TANK_FULL = 'tank_full'
 
 
 PLATFORM_SCHEMA = vol.Schema({
 PLATFORM_SCHEMA = vol.Schema({
     vol.Required(CONF_NAME): cv.string,
     vol.Required(CONF_NAME): cv.string,
@@ -43,6 +44,7 @@ PLATFORM_SCHEMA = vol.Schema({
     vol.Optional(CONF_CLIMATE, default=True): cv.boolean,
     vol.Optional(CONF_CLIMATE, default=True): cv.boolean,
     vol.Optional(CONF_DISPLAY_LIGHT, default=False): cv.boolean,
     vol.Optional(CONF_DISPLAY_LIGHT, default=False): cv.boolean,
     vol.Optional(CONF_CHILD_LOCK, default=False): cv.boolean,
     vol.Optional(CONF_CHILD_LOCK, default=False): cv.boolean,
+    vol.Optional(CONF_TANK_FULL, default=False): cv.boolean,
 })
 })
 
 
 CONFIG_SCHEMA = vol.Schema({
 CONFIG_SCHEMA = vol.Schema({
@@ -70,6 +72,8 @@ def setup(hass, config):
             load_platform(hass, 'light', DOMAIN, discovery_info, config)
             load_platform(hass, 'light', DOMAIN, discovery_info, config)
         if device_config.get(CONF_CHILD_LOCK) == True:
         if device_config.get(CONF_CHILD_LOCK) == True:
             load_platform(hass, 'lock', DOMAIN, discovery_info, config)
             load_platform(hass, 'lock', DOMAIN, discovery_info, config)
+        if device_config.get(CONF_TANK_FULL) == True:
+            load_platform(hass, 'binary_sensor', DOMAIN, discovery_info, config)
 
 
     return True
     return True
 
 

+ 18 - 0
custom_components/goldair_climate/binary_sensor.py

@@ -0,0 +1,18 @@
+"""
+Setup for different kinds of Goldair climate devices
+"""
+from homeassistant.const import CONF_HOST
+from custom_components.goldair_climate import (
+    DOMAIN, CONF_TYPE, CONF_TYPE_HEATER, CONF_TYPE_DEHUMIDIFIER, CONF_TYPE_FAN
+)
+from custom_components.goldair_climate.dehumidifier.binary_sensor import GoldairDehumidifierTankFullBinarySensor
+
+def setup_platform(hass, config, add_devices, discovery_info=None):
+    """Set up the Goldair climate device according to its type."""
+    device = hass.data[DOMAIN][discovery_info[CONF_HOST]]
+    if discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
+        add_devices([GoldairDehumidifierTankFullBinarySensor(device)])
+    if discovery_info[CONF_TYPE] == CONF_TYPE_HEATER:
+        raise ValueError('Goldair heaters do not support tank full sensors.')
+    if discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
+        raise ValueError('Goldair fans do not support tank full sensors.')

+ 63 - 0
custom_components/goldair_climate/dehumidifier/binary_sensor.py

@@ -0,0 +1,63 @@
+"""
+Platform to sense whether the dehumidifier tank is full.
+"""
+
+from homeassistant.components.binary_sensor import (BinarySensorDevice, DEVICE_CLASS_PROBLEM)
+from custom_components.goldair_climate import GoldairTuyaDevice
+from custom_components.goldair_climate.dehumidifier.climate import (
+    ATTR_FAULT, FAULT_CODE_TO_DPS_CODE, PROPERTY_TO_DPS_ID
+)
+
+ATTR_FAULT_CODE = 'fault_code'
+FAULT_TANK = 8
+FAULT_NONE = 0
+
+class GoldairDehumidifierTankFullBinarySensor(BinarySensorDevice):
+    """Representation of a Goldair WiFi-connected dehumidifier Tank sensor."""
+
+    def __init__(self, device):
+        """Initialize the binary sensor.
+        Args:
+            device (GoldairTuyaDevice): The device API instance."""
+        self._device = device
+        self._fault = None
+
+    @property
+    def should_poll(self):
+        """Return the polling state"""
+        return True
+
+    @property
+    def name(self):
+        """Return the name of the binary sensor."""
+        return self._device.name
+
+    @property
+    def is_on(self):
+        """Return true if the tank is full."""
+        if (self._fault is None):
+            return None
+        else:
+            return self._fault == FAULT_TANK
+
+    @property
+    def device_class(self):
+        """Return the class of device."""
+        return DEVICE_CLASS_PROBLEM
+
+    @property
+    def device_state_attributes(self):
+        """Return the state attributes"""
+        attrs = {ATTR_FAULT_CODE: self._fault}
+        # attrs.update(super().device_state_attributes)
+        return attrs
+
+    @property
+    def available(self):
+        """Return true if the device is available and value has not expired"""
+        return self._fault is not None
+
+    def update(self):
+        self._device.refresh()
+        self._fault = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_FAULT])
+