-
Notifications
You must be signed in to change notification settings - Fork 21
/
example.py
112 lines (95 loc) · 3.37 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""Example for hahomematic."""
# !/usr/bin/python3
from __future__ import annotations
import asyncio
import logging
import sys
from aiohttp import ClientSession, TCPConnector
from hahomematic import config, const
from hahomematic.central import CentralConfig
from hahomematic.client import InterfaceConfig
from hahomematic.model.custom import validate_custom_data_point_definition
logging.basicConfig(level=logging.DEBUG)
_LOGGER = logging.getLogger(__name__)
CCU_HOST = "192.168.1.173"
CCU_USERNAME = "Admin"
CCU_PASSWORD = ""
class Example:
"""Example for hahomematic."""
# Create a server that listens on 127.0.0.1:* and identifies itself as myserver.
got_devices = False
def __init__(self):
"""Init example."""
self.SLEEPCOUNTER = 0
self.central = None
def _systemcallback(self, name, *args, **kwargs):
self.got_devices = True
if (
name == const.BackendSystemEvent.NEW_DEVICES
and kwargs
and kwargs.get("device_descriptions")
and len(kwargs["device_descriptions"]) > 0
):
self.got_devices = True
return
if (
name == const.BackendSystemEvent.DEVICES_CREATED
and kwargs
and kwargs.get("new_data_points")
and len(kwargs["new_data_points"]) > 0
):
if len(kwargs["new_data_points"]) > 1:
self.got_devices = True
return
async def example_run(self):
"""Process the example."""
central_name = "ccu-dev"
interface_configs = {
InterfaceConfig(
central_name=central_name,
interface=const.Interface.HMIP_RF,
port=2010,
),
InterfaceConfig(
central_name=central_name,
interface=const.Interface.BIDCOS_RF,
port=2001,
),
InterfaceConfig(
central_name=central_name,
interface=const.Interface.VIRTUAL_DEVICES,
port=9292,
remote_path="/groups",
),
}
self.central = CentralConfig(
name=central_name,
host=CCU_HOST,
username=CCU_USERNAME,
password=CCU_PASSWORD,
central_id="1234",
storage_folder="homematicip_local",
interface_configs=interface_configs,
default_callback_port=54321,
client_session=ClientSession(connector=TCPConnector(limit=3)),
).create_central()
# For testing we set a short INIT_TIMEOUT
config.INIT_TIMEOUT = 10
# Add callbacks to handle the events and see what happens on the system.
self.central.register_backend_system_callback(self._systemcallback)
await self.central.start()
while not self.got_devices and self.SLEEPCOUNTER < 20:
_LOGGER.info("Waiting for devices")
self.SLEEPCOUNTER += 1
await asyncio.sleep(1)
await asyncio.sleep(5)
for i in range(16):
_LOGGER.info("Sleeping (%i)", i)
await asyncio.sleep(2)
# Stop the central_1 thread so Python can exit properly.
await self.central.stop()
# validate the device description
if validate_custom_data_point_definition():
example = Example()
asyncio.run(example.example_run())
sys.exit(0)