Skip to content

Commit

Permalink
Add button entities for bridge reboot and FW update
Browse files Browse the repository at this point in the history
  • Loading branch information
kvj committed Dec 26, 2021
1 parent 8b852d5 commit f647777
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
43 changes: 43 additions & 0 deletions custom_components/nuki_ng/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from homeassistant.components.button import ButtonEntity

import logging

from . import NukiBridge
from .constants import DOMAIN

_LOGGER = logging.getLogger(__name__)

async def async_setup_entry(hass, entry, async_add_entities):
entities = []
data = entry.as_dict()
coordinator = hass.data[DOMAIN][entry.entry_id]

if coordinator.api.can_bridge():
entities.append(RebootBridge(coordinator))
entities.append(FWUpdateBridge(coordinator))
async_add_entities(entities)
return True

class RebootBridge(NukiBridge, ButtonEntity):

def __init__(self, coordinator):
super().__init__(coordinator)
self.set_id("reboot")
self.set_name("Reboot")
self._attr_device_class = "restart"
self._attr_entity_category = "config"

async def async_press(self) -> None:
await self.coordinator.do_reboot()

class FWUpdateBridge(NukiBridge, ButtonEntity):

def __init__(self, coordinator):
super().__init__(coordinator)
self.set_id("fw_update")
self.set_name("Firmware Update")
self._attr_device_class = "update"
self._attr_entity_category = "config"

async def async_press(self) -> None:
await self.coordinator.do_fwupdate()
2 changes: 1 addition & 1 deletion custom_components/nuki_ng/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DOMAIN = "nuki_ng"
PLATFORMS = ["binary_sensor", "sensor", "lock", "switch"]
PLATFORMS = ["binary_sensor", "sensor", "lock", "switch", "button"]
2 changes: 1 addition & 1 deletion custom_components/nuki_ng/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"requirements": [],
"iot_class": "local_polling",
"config_flow": true,
"version": "0.1.0"
"version": "0.2.0"
}
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Nuki Lock",
"domains": ["lock", "sensor"],
"homeassistant": "2021.11.1",
"homeassistant": "2021.12.1",
"render_readme": true
}

0 comments on commit f647777

Please sign in to comment.