Skip to content

Commit

Permalink
Update buttons once an inactive button connects (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohNan authored Oct 6, 2023
1 parent 617d65e commit afc6c1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
13 changes: 8 additions & 5 deletions custom_components/flichub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.data.setdefault(DOMAIN, {})

def on_event(button: FlicButton, event: Event):
hass.bus.fire(EVENT_CLICK, {
EVENT_DATA_SERIAL_NUMBER: button.serial_number,
EVENT_DATA_NAME: button.name,
EVENT_DATA_CLICK_TYPE: event.action
})
if event.event == "button":
hass.bus.fire(EVENT_CLICK, {
EVENT_DATA_SERIAL_NUMBER: button.serial_number,
EVENT_DATA_NAME: button.name,
EVENT_DATA_CLICK_TYPE: event.action
})
if event.event == "buttonReady":
coordinator.async_refresh()

def on_commend(command: Command):
_LOGGER.debug(f"Command: {command.data}")
Expand Down
2 changes: 1 addition & 1 deletion custom_components/flichub/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/JohNan/home-assistant-flichub/issues",
"loggers": ["pyflichub"],
"requirements": ["pyflichub-tcpclient==0.1.6"],
"requirements": ["pyflichub-tcpclient==0.1.7"],
"version": "v0.0.0"
}
5 changes: 4 additions & 1 deletion custom_components/flichub/sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Binary sensor platform for Flic Hub."""
import logging
from homeassistant.util.dt import get_time_zone, as_utc

from homeassistant.helpers.device_registry import format_mac

from homeassistant.helpers.update_coordinator import CoordinatorEntity
Expand Down Expand Up @@ -50,6 +52,7 @@ def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{self.serial_number}-battery"


class FlicHubButtonBatteryTimestampSensor(FlicHubButtonEntity, SensorEntity):
"""flichub binary_sensor class."""
_attr_device_class = SensorDeviceClass.TIMESTAMP
Expand All @@ -61,7 +64,7 @@ def __init__(self, coordinator, config_entry, button: FlicButton, flic_hub: Flic
@property
def native_value(self):
"""Return the state of the sensor."""
return self.button.battery_timestamp
return as_utc(self.button.battery_timestamp) if self.button.battery_timestamp else None

@property
def unique_id(self):
Expand Down

0 comments on commit afc6c1d

Please sign in to comment.