Skip to content

Commit

Permalink
Add runstate and wifi/sensor RSSI attributes
Browse files Browse the repository at this point in the history
Require 3 consecutive failures to contact indoor unit before marking as unavailable
  • Loading branch information
dlarrick committed Dec 22, 2020
1 parent 6b811ea commit adb6450
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
62 changes: 58 additions & 4 deletions custom_components/kumo/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@

ATTR_FILTER_DIRTY = "filter_dirty"
ATTR_DEFROST = "defrost"
ATTR_RSSI = "rssi"
ATTR_SENSOR_RSSI = "sensor_rssi"
ATTR_RUNSTATE = "runstate"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
Expand Down Expand Up @@ -96,7 +99,7 @@
KUMO_STATE_OFF: CURRENT_HVAC_OFF,
}
MAX_SETUP_TRIES = 10

MAX_AVAILABILITY_TRIES = 3

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Kumo thermostats."""
Expand Down Expand Up @@ -201,6 +204,9 @@ class KumoThermostat(ClimateEntity):
"battery_percent",
"filter_dirty",
"defrost",
"rssi",
"sensor_rssi",
"runstate",
]

def __init__(self, kumo_api, unit):
Expand All @@ -220,6 +226,9 @@ def __init__(self, kumo_api, unit):
self._battery_percent = None
self._filter_dirty = None
self._defrost = None
self._rssi = None
self._sensor_rssi = None
self._runstate = None
self._pykumo = kumo_api
self._fan_modes = self._pykumo.get_fan_speeds()
self._swing_modes = self._pykumo.get_vane_directions()
Expand All @@ -246,16 +255,26 @@ def __init__(self, kumo_api, unit):
prop,
str(err),
)
self._unavailable_count = 0
self._available = False

def update(self):
"""Call from HA to trigger a refresh of cached state."""
for prop in KumoThermostat._update_properties:
self._update_property(prop)
if not self.available:
if self._unavailable_count > 1:
# Get out early if it's failing
break

def _update_availability(self, success):
if success:
self._available = True
self._unavailable_count = 0
else:
self._unavailable_count += 1
if self._unavailable_count >= MAX_AVAILABILITY_TRIES:
self._available = False

def _update_property(self, prop):
"""Call to refresh the value of a property -- may block on I/O."""
try:
Expand All @@ -266,10 +285,9 @@ def _update_property(self, prop):
)
return
success = self._pykumo.update_status()
self._update_availability(success)
if not success:
self._available = False
return
self._available = True
do_update()

@property
Expand Down Expand Up @@ -442,6 +460,36 @@ def _update_filter_dirty(self):
dirty = self._pykumo.get_filter_dirty()
self._filter_dirty = dirty

@property
def rssi(self):
"""Return WiFi RSSI, if any."""
return self._rssi

def _update_rssi(self):
"""Refresh the cached rssi attribute."""
rssi = self._pykumo.get_wifi_rssi()
self._rssi = rssi

@property
def sensor_rssi(self):
"""Return sensor RSSI, if any."""
return self._sensor_rssi

def _update_sensor_rssi(self):
"""Refresh the cached sensor_rssi attribute."""
rssi = self._pykumo.get_sensor_rssi()
self._sensor_rssi = rssi

@property
def runstate(self):
"""Return unit's current runstate."""
return self._runstate

def _update_runstate(self):
"""Refresh the cached runstate attribute."""
runstate = self._pykumo.get_runstate()
self._runstate = runstate

@property
def defrost(self):
"""Return whether in defrost mode."""
Expand All @@ -462,6 +510,12 @@ def device_state_attributes(self):
attr[ATTR_FILTER_DIRTY] = self._filter_dirty
if self._defrost is not None:
attr[ATTR_DEFROST] = self._defrost
if self._rssi is not None:
attr[ATTR_RSSI] = self._rssi
if self._sensor_rssi is not None:
attr[ATTR_SENSOR_RSSI] = self._sensor_rssi
if self._runstate is not None:
attr[ATTR_RUNSTATE] = self._runstate

return attr

Expand Down
2 changes: 1 addition & 1 deletion custom_components/kumo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"documentation": "https://github.com/dlarrick/hass-kumo",
"dependencies": [],
"codeowners": [ "@dlarrick" ],
"requirements": ["pykumo==0.1.10"],
"requirements": ["pykumo==0.1.11"],
"homeassistant": "0.96.0"
}

0 comments on commit adb6450

Please sign in to comment.