-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
110 lines (88 loc) · 3.86 KB
/
test.py
File metadata and controls
110 lines (88 loc) · 3.86 KB
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
import asyncio
from motionblinds import MotionGateway
from .. import fhem, generic
class test(generic.FhemModule):
def __init__(self, logger):
super().__init__(logger)
self.key = None
self.IP = None
# FHEM FUNCTION
async def Define(self, hash, args, argsh):
await super().Define(hash, args, argsh)
# define the attributes
self._attr_list = {
"key": {"default": "127.0.0.1"},
"IP": {"default": None},
}
await self.set_attr_config(self._attr_list)
# check the defined attributes in the define command
if len(args) < 5:
return "Usage: define NAME fhempy test IP"
self.address = args[3]
hash["IP"]= args[3]
self.logger.info(f"Define test address {self.address}")
self.key = args[4]
self.logger.info(f"Define test key {self.address}")
set_config = {
"mode": {
"args": ["mode"],
"argsh": ["mode"],
"params": {"mode": {"default": "eco", "optional": False}},
"options": "eco,comfort",
},
"desiredTemp": {"args": ["temperature"], "options": "slider,10,1,30"},
"holidayMode": {
"args": ["endday", "endtime", "temperature"],
"params": {
"endday": {"default": "31.12.2030"},
"endtime": {"default": "23:59"},
"temperature": {"default": 21, "format": "int"},
},
},
"on": {
"args": ["seconds"],
"params": {
"seconds": {"default": 0, "optional": True, "format": "int"}
},
"help": "Specify seconds as parameter to change to off after X seconds.",
},
"off": {},
"up": {},
"down": {},
}
await self.set_set_config(set_config)
if len(args) > 3:
return "Usage: define hello_fhempy fhempy helloworld"
await fhem.readingsBeginUpdate(hash)
await fhem.readingsBulkUpdateIfChanged(hash, "state", "on")
await fhem.readingsEndUpdate(hash, 1)
# Attribute function format: set_attr_NAMEOFATTRIBUTE(self, hash)
# self._attr_NAMEOFATTRIBUTE contains the new state
async def set_attr_IP(self, hash):
# attribute was set to self._attr_IP
# you can use self._attr_interval already with the new variable
pass
# Set functions in format: set_NAMEOFSETFUNCTION(self, hash, params)
async def set_on(self, hash, params):
# params contains the keyword which was defined in set_list_conf for "on"
# if not provided by the user it will be "" as defined in set_list_conf (default = "" and optional = True)
seconds = params["seconds"]
if seconds != 0:
await fhem.readingsSingleUpdate(hash, "state", "on " + str(seconds), 1)
else:
await fhem.readingsSingleUpdate(hash, "state", "on", 1)
async def set_off(self, hash, params):
# no params argument here, as set_off doesn't have arguments defined in set_list_conf
await fhem.readingsSingleUpdate(hash, "state", "off", 1)
self.create_async_task(self.long_running_task())
return ""
async def set_up(self, hash, params):
# no params argument here, as set_off doesn't have arguments defined in set_list_conf
await fhem.readingsSingleUpdate(hash, "state", "off", 1)
self.create_async_task(self.long_running_task())
return ""
async def set_down(self, hash, params):
# no params argument here, as set_off doesn't have arguments defined in set_list_conf
await fhem.readingsSingleUpdate(hash, "state", "off", 1)
self.create_async_task(self.long_running_task())
return ""