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

Add switch for motion detection #47

merged 6 commits into from
Dec 27, 2021

Conversation

SamMousa
Copy link
Contributor

@SamMousa SamMousa commented Jun 3, 2021

This depends on my PR here: cgarwood/python-fullykiosk#10

I've tested it to be working on my installation without modifying the underlying python library (harder to reach from vs-code plugin). To do that I just adapted the code from this PR to call existing function in python-fullykiosk directly.

So instead of calling enableMotionDetection etc I did this:

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.setConfigurationBool("motionDetection", True)
        await self.coordinator.async_refresh()

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

And instead of calling getSettings in coordinator.py I did this:

async def _async_update_data(self):
        """Update data via library."""
        try:
            with timeout(15):
                """Get device info and settings in parallel"""
                result = await asyncio.gather(self.fully.getDeviceInfo(), self.fully.sendCommand("listSettings"))
                """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

Again I don't speak python so check thoroughly!

This should also provide a simple framework for adding other switches for settings.

@SamMousa
Copy link
Contributor Author

SamMousa commented Jun 7, 2021

Does this look good @cgarwood?

@bcutter
Copy link

bcutter commented Sep 19, 2021

Does this look good @cgarwood?

Just want to ask the same question @cgarwood 2,5 months later :-)

@cgarwood
Copy link
Owner

😬 so far behind on projects.. just merged your other PR and did a new release of the library, 0.0.9. Please update the requirements in manifest.json and give it a quick test then I think we're good to merge.

@cgarwood cgarwood linked an issue Sep 22, 2021 that may be closed by this pull request
@SamMousa
Copy link
Contributor Author

@cgarwood Done!

@chpego
Copy link
Contributor

chpego commented Dec 25, 2021

Hi @SamMousa , did you try to fix the format of your commit ?

@SamMousa
Copy link
Contributor Author

Not sure what you mean? I thought this one was done, but haven't looked at it in a long while!

@chpego
Copy link
Contributor

chpego commented Dec 25, 2021

Not sure what you mean? I thought this one was done, but haven't looked at it in a long while!

the check formatting action failed on some parts of the code you pushed :
https://github.com/cgarwood/homeassistant-fullykiosk/runs/4289157913?check_suite_focus=true#step:4:61

@SamMousa
Copy link
Contributor Author

Yeah will do when I have time!

Copy link
Owner

@cgarwood cgarwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some free time so I committed the code formatting changes 🙂

HACS validation test failure is unrelated to this PR

@cgarwood cgarwood merged commit b438927 into cgarwood:master Dec 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add switch for motion detection.
4 participants