Skip to content

Commit

Permalink
Add services for setups where messages are missed (debugging and to r…
Browse files Browse the repository at this point in the history
…e-fetch state from the actual RF devices)

Add "opening" and "closing" state as I discovered how to do that.
  • Loading branch information
gluap committed Jan 1, 2023
1 parent 93ea926 commit 66fa6f2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
10 changes: 10 additions & 0 deletions custom_components/duofern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ def clean_config(call):
hass.services.register(DOMAIN, 'sync_devices', sync_devices)
hass.services.register(DOMAIN, 'clean_config', clean_config)

def dump_device_state(call):
_LOGGER.warning(hass.data[DOMAIN]['stick'].duofern_parser.modules)
hass.services.register(DOMAIN, 'dump_device_state', dump_device_state)

def update_device_state(call):
for module_id in hass.data[DOMAIN]['stick'].duofern_parser.modules['by_code'].keys():
hass.data[DOMAIN]['stick'].command(module_id, 'getStatus')
hass.services.register(DOMAIN, 'update_device_state', update_device_state)


def refresh(call):
_LOGGER.warning(call)
for _component in DUOFERN_COMPONENTS:
Expand Down
14 changes: 14 additions & 0 deletions custom_components/duofern/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, id, desc, stick, hass):
self._name = desc
self._state = None
self._stick = stick
self._openclose = 'stop'
hass.data[DOMAIN]['devices'][id] = self

@property
Expand Down Expand Up @@ -75,6 +76,10 @@ def supported_features(self):

@property
def icon(self):
if self.is_opening:
return 'mdi:arrow-up-bold'
if self.is_closing:
return 'mdi:arrow-down-bold'
if self.is_closed:
return "mdi:window-shutter"
else:
Expand All @@ -92,6 +97,14 @@ def stop_cover(self):
"""stop cover"""
self._stick.command(self._id, "stop")

@property
def is_opening(self):
return self._openclose == 'up'

@property
def is_closing(self):
return self._openclose == 'down'

def set_cover_position(self, **kwargs):
"""set position (100-position to make the default intuitive: 0%=closed, 100%=open"""
position = kwargs.get(ATTR_POSITION)
Expand All @@ -108,6 +121,7 @@ def update(self):
_LOGGER.info("updating state")
try:
self._state = 100 - self._stick.duofern_parser.modules['by_code'][self._id]['position']
self._openclose = self._stick.duofern_parser.modules['by_code'][self._id]['moving']
except KeyError:
self._state = None
_LOGGER.info(f"{self._id} state is now {self._state}")
2 changes: 1 addition & 1 deletion custom_components/duofern/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"issue_tracker": "https://github.com/gluap/pyduofern-hacs/issues" ,
"codeowners": ["@gluap"],
"requirements": ["pyduofern==0.34.3"],
"version": "0.3.4"
"version": "0.4.0"
}
10 changes: 9 additions & 1 deletion custom_components/duofern/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ start_pairing:
example: 60

sync_devices:
description: re-sync devices (trigger after pairing)
description: re-sync devices (trigger after pairing)

dump_device_state:
description: dump state of all known devices as a warning. State reflects state considering all
messages received from devices (independent from homeassistant device state).
Purpose is to debug whether there's a discrepancy with state reflected in Homeassistant.

ask_for_update:
description: ask all devices for an update (in case of missed radio transmissions)
9 changes: 8 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ To use ``pyduofern`` within [Homeassistant](https://home-assistant.io/), add the

### Usage

There are two services you can call via the service interface:
There are some services you can call via the service interface:

``duofern.start_pairing`` starts the pairing mode for a given number of seconds.

Expand All @@ -53,3 +53,10 @@ There are two services you can call via the service interface:

Please use the renaming feature in the homeassistant GUI to arrive at human readable
names for your deices.

``duofern.update_device_state``

Ask all duofern devices to re-send their state in case. Can be used in setups where RF is finnicky.

``duofern.dump_device_state``
Dump the current last received state for all duofern modules as a warning level message to the log. This reflects the current state of all RF messages received from devices - What's not here wasn't received by the stick or came in garbled.

0 comments on commit 66fa6f2

Please sign in to comment.