FHEM & reconnecting client fixes

This commit is contained in:
Martin Bauer
2019-07-07 17:30:45 +02:00
parent 06f96cb2dc
commit e6f5504181
8 changed files with 34 additions and 13 deletions

View File

@@ -53,24 +53,33 @@ class FhemSwitch(SwitchDevice):
async def async_turn_on(self, **kwargs):
"""Turn the device on."""
self._on = True
self.connection.fhem_set(self._ids[0], 'on')
async def async_turn_off(self, **kwargs):
"""Turn the device off."""
self._on = False
self.connection.fhem_set(self._ids[0], 'off')
def refresh(self):
self.connection.fhem_set(self._ids[0], 'statusRequest')
async def line_received(self, line):
line = line.strip()
if line.startswith('level:'):
self._available = True
_, new_state = line.split(':')
new_state = new_state.strip().lower()
if new_state in ('on', '100'):
self._on = True
if new_state in ('off', '0'):
elif new_state in ('off', '0'):
self._on = False
await self.async_update_ha_state()
elif line in ('on', 'off'):
self._available = True
prev = self._on
self._on = (line == 'on')
await self.async_update_ha_state()
elif line.startswith('ResndFail') or line.startswith('MISSING ACK'):
self._available = False
await self.async_update_ha_state()