Update demo

This commit is contained in:
Richard Mitchell
2019-04-18 12:41:04 +01:00
parent d7f0137bc6
commit aa063a43a3
2 changed files with 50 additions and 9 deletions

View File

@@ -30,20 +30,16 @@ async def cleaning_started_callback(message, device):
print("Cleaning started.") 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): async def async_main(device_id, local_key, ip, *args, **kwargs):
r = Robovac(device_id, local_key, ip, *args, **kwargs) r = Robovac(device_id, local_key, ip, *args, **kwargs)
await r.async_connect(connected_callback) await r.async_connect(connected_callback)
await asyncio.sleep(5) await asyncio.sleep(1)
print("Starting cleaning...") print("Starting cleaning...")
await r.async_start_cleaning(cleaning_started_callback) await r.async_start_cleaning(cleaning_started_callback)
await asyncio.sleep(30) await asyncio.sleep(5)
print("Sending home...") print("Pausing...")
await r.async_go_home(go_home_callback) r.play_pause = False
await asyncio.sleep(10) await asyncio.sleep(1)
print("Disconnecting...") print("Disconnecting...")
await r.async_disconnect() await r.async_disconnect()

45
eufy_robovac/property.py Normal file
View File

@@ -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})