diff --git a/custom_components/flichub/__init__.py b/custom_components/flichub/__init__.py index ba47dbf..f27b2df 100644 --- a/custom_components/flichub/__init__.py +++ b/custom_components/flichub/__init__.py @@ -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}") diff --git a/custom_components/flichub/manifest.json b/custom_components/flichub/manifest.json index db5abd0..3f8b923 100644 --- a/custom_components/flichub/manifest.json +++ b/custom_components/flichub/manifest.json @@ -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" } diff --git a/custom_components/flichub/sensor.py b/custom_components/flichub/sensor.py index e15d6a9..a63ec81 100644 --- a/custom_components/flichub/sensor.py +++ b/custom_components/flichub/sensor.py @@ -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 @@ -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 @@ -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):