Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Add switch for motion detection #47

Merged
merged 6 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion custom_components/fullykiosk/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provides the The Fully Kiosk Browser DataUpdateCoordinator."""
import asyncio
import logging
from datetime import timedelta

Expand Down Expand Up @@ -35,6 +36,12 @@ async def _async_update_data(self):
"""Update data via library."""
try:
with timeout(15):
return await self.fully.getDeviceInfo()
"""Get device info and settings in parallel"""
result = await asyncio.gather(
self.fully.getDeviceInfo(), self.fully.getSettings()
)
"""Store settings under settings key in data"""
result[0]["settings"] = result[1]
return result[0]
except (FullyKioskError, ClientConnectorError) as error:
raise UpdateFailed(error) from error
26 changes: 26 additions & 0 deletions custom_components/fullykiosk/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities([FullyScreenSaverSwitch(hass, coordinator)], False)
async_add_entities([FullyMaintenanceModeSwitch(hass, coordinator)], False)
async_add_entities([FullyKioskLockSwitch(hass, coordinator)], False)
async_add_entities([FullyKioskMotionDetectionSwitch(hass, coordinator)], False)


class FullySwitch(CoordinatorEntity, SwitchEntity):
Expand Down Expand Up @@ -138,3 +139,28 @@ async def async_turn_off(self, **kwargs):
"""Turn off kiosk lock."""
await self.coordinator.fully.unlockKiosk()
await self.coordinator.async_refresh()


class FullyKioskMotionDetectionSwitch(FullySwitch):
"""Representation of a Fully Kiosk Browser kiosk lock switch."""

def __init__(self, hass, coordinator):
"""Intialize the kiosk lock switch."""
super().__init__(hass, coordinator)
self._name = f"{coordinator.data['deviceName']} Motion Detection"
self._unique_id = f"{coordinator.data['deviceID']}-motion-detection"

@property
def is_on(self):
"""Return if motion detection is on."""
return self.coordinator.data["settings"]["motionDetection"]

async def async_turn_on(self, **kwargs):
"""Turn on kiosk lock."""
await self.coordinator.fully.enableMotionDetection()
await self.coordinator.async_refresh()

async def async_turn_off(self, **kwargs):
"""Turn off kiosk lock."""
await self.coordinator.fully.disableMotionDetection()
await self.coordinator.async_refresh()