Skip to content

Commit

Permalink
feat: fire events independent on state change
Browse files Browse the repository at this point in the history
There was no second event if we got two events of same type one after other.
But it could be, for example, two alarms events with different labels (value2).
So we should fire HA event for every event from MQTT.
  • Loading branch information
IATkachenko committed Jan 11, 2022
1 parent 6e70ac1 commit 95d371f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -75,6 +75,8 @@ More details in [Wiki](https://github.com/IATkachenko/HA-SleepAsAndroid/wiki/app
### on device event
1. select `Device` in automatization trigger and use `SleepAsAndroid` device;
1. select trigger from a list.

![added_in_version_badge](https://img.shields.io/badge/Since-v1.7.0-red) events will be fired up for every MQTT message

### on sensor state change
`<name>` is an integration name in lower case without spaces from the `Settings` dialog.
Expand All @@ -90,6 +92,7 @@ If application publishes a new event, then integration fires `<name>` event with
"event": "<event_name_from_application>"
}
```
![added_in_version_badge](https://img.shields.io/badge/Since-v1.7.0-red) events will be fired up for every MQTT message
## Attributes
![added_in_version_badge](https://img.shields.io/badge/Since-v1.7.0-red)

Expand Down
5 changes: 2 additions & 3 deletions custom_components/sleep_as_android/sensor.py
Expand Up @@ -120,6 +120,8 @@ def process_message(self, msg):

self._set_attributes(payload)
self.state = new_state
self._fire_event(self.state)
self._fire_trigger(self.state)

except json.decoder.JSONDecodeError:
_LOGGER.warning("expected JSON payload. got '%s' instead", msg.payload)
Expand Down Expand Up @@ -150,9 +152,6 @@ def state(self, new_state: str):
if self._state != new_state:
self._state = new_state
self.async_write_ha_state()
if new_state != STATE_UNKNOWN:
self._fire_event(self.state)
self._fire_trigger(self.state)
else:
_LOGGER.debug(f"Will not update state because old state == new_state")

Expand Down

0 comments on commit 95d371f

Please sign in to comment.