Skip to content

Commit

Permalink
Add battery timestamp and various other fixes (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohNan authored Oct 6, 2023
1 parent 70ea53f commit 617d65e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
5 changes: 5 additions & 0 deletions custom_components/flichub/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{self.serial_number}-connected"

@property
def available(self) -> bool:
"""Return True if entity is available."""
return True


class FlicHubButtonPassiveBinarySensor(FlicHubButtonEntity, BinarySensorEntity):
"""flichub sensor class."""
Expand Down
24 changes: 24 additions & 0 deletions custom_components/flichub/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async def async_setup_entry(hass, entry, async_add_devices):
devices = []
for serial_number, button in buttons.items():
devices.append(FlicHubButtonBatterySensor(data_entry.coordinator, entry, button, flic_hub))
devices.append(FlicHubButtonBatteryTimestampSensor(data_entry.coordinator, entry, button, flic_hub))
async_add_devices(devices)


Expand All @@ -48,3 +49,26 @@ def native_value(self):
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
_attr_entity_category = EntityCategory.DIAGNOSTIC

def __init__(self, coordinator, config_entry, button: FlicButton, flic_hub: FlicHubInfo):
super().__init__(coordinator, config_entry, button.serial_number, flic_hub)

@property
def native_value(self):
"""Return the state of the sensor."""
return self.button.battery_timestamp

@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{self.serial_number}-battery-timestamp"

@property
def available(self) -> bool:
"""Return True if entity is available."""
return True
10 changes: 5 additions & 5 deletions custom_components/flichub/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"step": {
"user": {
"title": "Flic Hub",
"description": "If you need help with the configuration have a look here: https://github.com/JohNan/flichub",
"description": "If you need help with the configuration have a look here: https://github.com/JohNan/home-assistant-flichub",
"data": {
"name": "Name",
"name": "Name your device",
"ip_address": "IP Address",
"port": "Port"
"port": "Port (default: 8124)"
}
},
"devices": {
"title": "Flic Hub",
"description": "If you need help with the configuration have a look here: https://github.com/JohNan/flichub",
"description": "If you need help with the configuration have a look here: https://github.com/JohNan/home-assistant-flichub",
"data": {
"ip_address": "Discovered devices",
"port": "Port"
"port": "Port (default: 8124)"
}
}
},
Expand Down

0 comments on commit 617d65e

Please sign in to comment.