diff --git a/eufy_robovac/demo.py b/eufy_robovac/demo.py index 0caec0a..9514841 100644 --- a/eufy_robovac/demo.py +++ b/eufy_robovac/demo.py @@ -30,20 +30,16 @@ async def cleaning_started_callback(message, device): print("Cleaning started.") -async def go_home_callback(message, device): - print("Device on its way home.") - - async def async_main(device_id, local_key, ip, *args, **kwargs): r = Robovac(device_id, local_key, ip, *args, **kwargs) await r.async_connect(connected_callback) - await asyncio.sleep(5) + await asyncio.sleep(1) print("Starting cleaning...") await r.async_start_cleaning(cleaning_started_callback) - await asyncio.sleep(30) - print("Sending home...") - await r.async_go_home(go_home_callback) - await asyncio.sleep(10) + await asyncio.sleep(5) + print("Pausing...") + r.play_pause = False + await asyncio.sleep(1) print("Disconnecting...") await r.async_disconnect() diff --git a/eufy_robovac/property.py b/eufy_robovac/property.py new file mode 100644 index 0000000..26aff04 --- /dev/null +++ b/eufy_robovac/property.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019 Richard Mitchell +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import enum + + +class StringEnum(enum.Enum): + + def __str__(self): + return self.value + + +class DeviceProperty: + + def __init__(self, key, type_cast=None, read_only=False): + self.key = key + self.type_cast = type_cast + self.read_only = read_only + + def __get__(self, instance): + value = instance.state.get(self.key) + if value is not None and type_cast is not None: + value = self.type_cast(value) + return value + + def __set__(self, instance, value): + if self.read_only: + raise AttributeError("can't set attribute") + + if not isinstance(value, (bool, int, float, str, type(None))): + value = str(value) + instance.set({self.key: value})