forked from Heckie75/voltcraft-sem-6000
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.py
481 lines (307 loc) · 16.4 KB
/
message.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
from . import util
import datetime
class AbstractCommand:
def __str__(self):
name = self.__class__.__name__
return name + "()"
class AbstractSwitchCommand():
def __init__(self, on):
self.on = on
def __str__(self):
name = self.__class__.__name__
return name + "(on=" + str(self.on) + ")"
class AbstractCommandConfirmationNotification:
def __init__(self, was_successful):
self.was_successful = was_successful
def __str__(self):
name = self.__class__.__name__
return name + "(was_successful=" + str(self.was_successful) + ")"
class AuthorizeCommand():
def __init__(self, pin):
self.pin = pin
def __str__(self):
name = self.__class__.__name__
return name + "(pin=" + str(self.pin) + ")"
class ChangePinCommand():
def __init__(self, pin, new_pin):
self.pin = pin
self.new_pin = new_pin
def __str__(self):
name = self.__class__.__name__
return name + "(pin=" + str(self.pin) + ", new_pin=" + str(self.new_pin) + ")"
class ResetPinCommand(AbstractCommand):
pass
class PowerSwitchCommand(AbstractSwitchCommand):
pass
class ChangeNightmodeCommand(AbstractSwitchCommand):
pass
class SynchronizeDateAndTimeCommand():
def __init__(self, isodatetime):
d = datetime.datetime.fromisoformat(isodatetime)
self.isodatetime = d.isoformat(timespec='seconds')
def __str__(self):
name = self.__class__.__name__
return name + "(isodatetime=" + str(self.isodatetime) + ")"
class RequestSettingsCommand(AbstractCommand):
pass
class ChangePowerLimitCommand():
def __init__(self, power_limit_in_watt):
self.power_limit_in_watt = power_limit_in_watt
def __str__(self):
name = self.__class__.__name__
return name + "(power_limit_in_watt=" + str(self.power_limit_in_watt) + ")"
class ChangePricesCommand():
def __init__(self, normal_price_in_cent, reduced_period_price_in_cent):
self.normal_price_in_cent = normal_price_in_cent
self.reduced_period_price_in_cent = reduced_period_price_in_cent
def __str__(self):
name = self.__class__.__name__
return name + "(normal_price_in_cent=" + str(self.normal_price_in_cent) + ", reduced_period_price_in_cent=" + str(self.reduced_period_price_in_cent) + ")"
class ChangeReducedPeriodCommand():
def __init__(self, is_active, start_isotime, end_isotime):
self.is_active = is_active
self.start_isotime = start_isotime
self.end_isotime = end_isotime
def __str__(self):
name = self.__class__.__name__
return name + "(is_active=" + str(self.is_active) + ", start_isotime=" + str(self.start_isotime) + ", end_isotime=" + str(self.end_isotime) + ")"
class RequestTimerStatusCommand(AbstractCommand):
pass
class SetTimerCommand:
def __init__(self, is_reset_timer, is_action_turn_on, target_isodatetime=None):
if not is_reset_timer and target_isodatetime is None:
raise Exception("target_isodatetime parameter is None")
if is_reset_timer and not target_isodatetime is None:
raise Exception("target_isodatetime parameter is expected to be None if timer is being reset")
self.is_reset_timer = is_reset_timer
self.is_action_turn_on = is_action_turn_on
self.target_isodatetime = None
if not is_reset_timer:
d = datetime.datetime.fromisoformat(target_isodatetime)
self.target_isodatetime = d.isoformat(timespec='seconds')
def __str__(self):
name = self.__class__.__name__
return name + "(is_reset_timer=" + str(self.is_reset_timer) + ", is_action_turn_on=" + str(self.is_action_turn_on) + ", target_isodatetime=" + str(self.target_isodatetime) + ")"
class RequestSchedulerCommand:
def __init__(self, page_number):
self.page_number = page_number
def __str__(self):
name = self.__class__.__name__
return name + "(page_number=" + str(self.page_number) + ")"
class AddSchedulerCommand:
def __init__(self, scheduler):
assert isinstance(scheduler, Scheduler)
self.scheduler = scheduler
def __str__(self):
name = self.__class__.__name__
return name + "(scheduler=" + str(self.scheduler) + ")"
class EditSchedulerCommand:
def __init__(self, slot_id, scheduler):
assert isinstance(scheduler, Scheduler)
self.slot_id = slot_id
self.scheduler = scheduler
def __str__(self):
name = self.__class__.__name__
return name + "(slot_id=" + str(self.slot_id) + ", scheduler=" + str(self.scheduler) + ")"
class RemoveSchedulerCommand:
def __init__(self, slot_id):
self.slot_id = slot_id
def __str__(self):
name = self.__class__.__name__
return name + "(slot_id=" + str(self.slot_id) + ")"
class RequestRandomModeStatusCommand(AbstractCommand):
pass
class ChangeRandomModeCommand:
def __init__(self, is_active, active_on_weekdays, start_isotime, end_isotime):
active_on_weekdays = util._list_values_to_enum(util.Weekday, active_on_weekdays)
self.is_active = is_active
self.active_on_weekdays = active_on_weekdays
start_time = datetime.time.fromisoformat(start_isotime)
end_time = datetime.time.fromisoformat(end_isotime)
self.start_isotime = start_time.isoformat(timespec='minutes')
self.end_isotime = end_time.isoformat(timespec='minutes')
def __str__(self):
weekday_formatter = lambda w: w.name
active_on_weekdays = util._format_list_of_objects(weekday_formatter, self.active_on_weekdays)
name = self.__class__.__name__
return name + "(is_active=" + str(self.is_active) + ", active_on_weekdays=" + active_on_weekdays + ", start_isotime=" + str(self.start_isotime) + ", end_isotime=" + str(self.end_isotime) + ")"
class RequestMeasurementCommand(AbstractCommand):
pass
class RequestConsumptionOfLast12MonthsCommand(AbstractCommand):
pass
class RequestConsumptionOfLast30DaysCommand(AbstractCommand):
pass
class RequestConsumptionOfLast23HoursCommand(AbstractCommand):
pass
class ResetConsumptionCommand(AbstractCommand):
pass
class FactoryResetCommand(AbstractCommand):
pass
class ChangeDeviceNameCommand:
def __init__(self, new_name):
self.new_name = new_name
def __str__(self):
command = self.__class__.__name__
return command + "(new_name=" + str(self.new_name) + ")"
class RequestDeviceSerialCommand(AbstractCommand):
pass
class AuthorizedNotification(AbstractCommandConfirmationNotification):
pass
class PinChangedNotification(AbstractCommandConfirmationNotification):
pass
class PinResetNotification(AbstractCommandConfirmationNotification):
pass
class PowerSwitchedNotification(AbstractCommandConfirmationNotification):
pass
class NightmodeChangedNotification(AbstractCommandConfirmationNotification):
pass
class DateAndTimeChangedNotification(AbstractCommandConfirmationNotification):
pass
class SettingsRequestedNotification:
def __init__(self, is_reduced_period, normal_price_in_cent, reduced_period_price_in_cent, reduced_period_start_isotime, reduced_period_end_isotime, is_nightmode_active, power_limit_in_watt):
self.is_reduced_period = is_reduced_period
self.normal_price_in_cent = normal_price_in_cent
self.reduced_period_price_in_cent = reduced_period_price_in_cent
start_time = datetime.time.fromisoformat(reduced_period_start_isotime)
end_time = datetime.time.fromisoformat(reduced_period_end_isotime)
self.reduced_period_start_isotime = start_time.isoformat(timespec='minutes')
self.reduced_period_end_isotime = end_time.isoformat(timespec='minutes')
self.is_nightmode_active = is_nightmode_active
self.power_limit_in_watt = power_limit_in_watt
def __str__(self):
name = self.__class__.__name__
return name + "(is_reduced_period=" + str(self.is_reduced_period) + ", normal_price_in_cent=" + str(self.normal_price_in_cent) + ", reduced_periiod_price_in_cent=" + str(self.reduced_period_price_in_cent) + ", reduced_period_start_isotime=" + str(self.reduced_period_start_isotime) + ", reduced_period_end_isotime=" + str(self.reduced_period_end_isotime) + ", is_nightmode_active=" + str(self.is_nightmode_active) + ", power_limit_in_watt=" + str(self.power_limit_in_watt) + ")"
class PowerLimitChangedNotification(AbstractCommandConfirmationNotification):
pass
class PricesChangedNotification(AbstractCommandConfirmationNotification):
pass
class ReducedPeriodChangedNotification(AbstractCommandConfirmationNotification):
pass
class TimerStatusRequestedNotification:
def __init__(self, is_active, is_action_turn_on, target_isodatetime, original_timer_length_in_seconds):
d = datetime.datetime.fromisoformat(target_isodatetime)
self.is_active = is_active
self.is_action_turn_on = is_action_turn_on
self.target_isodatetime = d.isoformat(timespec='seconds')
self.original_timer_length_in_seconds = original_timer_length_in_seconds
def __str__(self):
name = self.__class__.__name__
return name + "(is_active=" + str(self.is_active) + ", is_action_turn_on=" + str(self.is_action_turn_on) + ", target_isodatetime=" + str(self.target_isodatetime) + ", original_timer_length_in_seconds=" + str(self.original_timer_length_in_seconds) + ")"
class TimerSetNotification(AbstractCommandConfirmationNotification):
pass
class Scheduler:
def __init__(self, is_active, is_action_turn_on, repeat_on_weekdays, isodatetime):
repeat_on_weekdays = util._list_values_to_enum(util.Weekday, repeat_on_weekdays)
self.is_active = is_active
self.is_action_turn_on = is_action_turn_on
self.repeat_on_weekdays = repeat_on_weekdays
d = datetime.datetime.fromisoformat(isodatetime)
self.isodatetime = d.isoformat(timespec='minutes')
class OneTimeScheduler(Scheduler):
def __init__(self, is_active, is_action_turn_on, isodatetime):
Scheduler.__init__(self,
is_active=is_active,
is_action_turn_on=is_action_turn_on,
repeat_on_weekdays=[],
isodatetime=isodatetime)
def __str__(self):
name = self.__class__.__name__
weekday_formatter = lambda w: w.name
repeat_on_weekdays = util._format_list_of_objects(weekday_formatter, self.repeat_on_weekdays)
return name + "(is_active=" + str(self.is_active) + ", is_action_turn_on=" + str(self.is_action_turn_on) + ", isodatetime=" + str(self.isodatetime) + ")"
class RepeatedScheduler(Scheduler):
def __init__(self, is_active, is_action_turn_on, repeat_on_weekdays, isotime):
Scheduler.__init__(self,
is_active=is_active,
is_action_turn_on=is_action_turn_on,
repeat_on_weekdays=repeat_on_weekdays,
isodatetime=datetime.date.today().isoformat() + 'T' + isotime)
def __str__(self):
name = self.__class__.__name__
weekday_formatter = lambda w: w.name
repeat_on_weekdays = util._format_list_of_objects(weekday_formatter, self.repeat_on_weekdays)
isotime = datetime.datetime.fromisoformat(self.isodatetime).time().isoformat(timespec='minutes')
return name + "(is_active=" + str(self.is_active) + ", is_action_turn_on=" + str(self.is_action_turn_on) + ", repeat_on_weekdays=" + repeat_on_weekdays + ", isotime=" + isotime + ")"
class SchedulerEntry:
def __init__(self, slot_id, scheduler):
assert isinstance(scheduler, Scheduler)
self.slot_id = slot_id
self.scheduler = scheduler
def __str__(self):
name = self.__class__.__name__
return name + "(slot_id=" + str(self.slot_id) + ", scheduler=" + str(self.scheduler) + ")"
class SchedulerRequestedNotification:
def __init__(self, number_of_schedulers, scheduler_entries):
for scheduler_entry in scheduler_entries:
assert isinstance(scheduler_entry, SchedulerEntry)
self.number_of_schedulers = number_of_schedulers
self.scheduler_entries = scheduler_entries
def __str__(self):
name = self.__class__.__name__
scheduler_entries = util._format_list_of_objects(str, self.scheduler_entries)
return name + "(number_of_schedulers=" + str(self.number_of_schedulers) + ", scheduler_entries=" + scheduler_entries + ")"
class SchedulerChangedNotification(AbstractCommandConfirmationNotification):
pass
class RandomModeStatusRequestedNotification:
def __init__(self, is_active, active_on_weekdays, start_isotime, end_isotime):
active_on_weekdays = util._list_values_to_enum(util.Weekday, active_on_weekdays)
self.is_active = is_active
self.active_on_weekdays = active_on_weekdays
start_time = datetime.time.fromisoformat(start_isotime)
end_time = datetime.time.fromisoformat(end_isotime)
self.start_isotime = start_time.isoformat(timespec='minutes')
self.end_isotime = end_time.isoformat(timespec='minutes')
def __str__(self):
weekday_formatter = lambda w: w.name
active_on_weekdays = util._format_list_of_objects(weekday_formatter, self.active_on_weekdays)
name = self.__class__.__name__
return name + "(is_active=" + str(self.is_active) + ", active_on_weekdays=" + active_on_weekdays + ", start_isotime=" + str(self.start_isotime) + ", end_isotime=" + str(self.end_isotime) + ")"
class RandomModeChangedNotification(AbstractCommandConfirmationNotification):
pass
class MeasurementRequestedNotification:
def __init__(self, is_power_active, power_in_milliwatt, voltage_in_volt, current_in_milliampere, frequency_in_hertz, total_consumption_in_kilowatt_hour):
self.is_power_active = is_power_active
self.power_in_milliwatt = power_in_milliwatt
self.voltage_in_volt = voltage_in_volt
self.current_in_milliampere = current_in_milliampere
self.frequency_in_hertz = frequency_in_hertz
self.total_consumption_in_kilowatt_hour = total_consumption_in_kilowatt_hour
def __str__(self):
name = self.__class__.__name__
return name + "(is_power_active=" + str(self.is_power_active) + ", power_in_milliwatt=" + str(self.power_in_milliwatt) + ", voltage_in_volt=" + str(self.voltage_in_volt) + ", current_in_milliampere=" + str(self.current_in_milliampere) + ", frequency_in_hertz=" + str(self.frequency_in_hertz) + ", total_consumption_in_kilowatt_hour=" + str(self.total_consumption_in_kilowatt_hour) + ")"
class ConsumptionOfLast12MonthsRequestedNotification:
def __init__(self, consumption_n_months_ago_in_watt_hour):
self.consumption_n_months_ago_in_watt_hour = consumption_n_months_ago_in_watt_hour
def __str__(self):
name = self.__class__.__name__
return name + "(consumption_n_months_ago_in_watt_hour=" + util._format_list_of_objects(str, self.consumption_n_months_ago_in_watt_hour) + ")"
class ConsumptionOfLast30DaysRequestedNotification:
def __init__(self, consumption_n_days_ago_in_watt_hour):
self.consumption_n_days_ago_in_watt_hour = consumption_n_days_ago_in_watt_hour
def __str__(self):
name = self.__class__.__name__
return name + "(consumption_n_days_ago_in_watt_hour=" + util._format_list_of_objects(str, self.consumption_n_days_ago_in_watt_hour) + ")"
class ConsumptionOfLast23HoursRequestedNotification:
def __init__(self, consumption_n_hours_ago_in_watt_hour):
self.consumption_n_hours_ago_in_watt_hour = consumption_n_hours_ago_in_watt_hour
def __str__(self):
name = self.__class__.__name__
return name + "(consumption_n_hours_ago_in_watt_hour=" + util._format_list_of_objects(str, self.consumption_n_hours_ago_in_watt_hour) + ")"
class ConsumptionResetNotification(AbstractCommandConfirmationNotification):
pass
class FactoryResetNotification(AbstractCommandConfirmationNotification):
pass
class DeviceNameChangedNotification(AbstractCommandConfirmationNotification):
pass
class DeviceNameRequestedNotification:
def __init__(self, device_name):
self.device_name = device_name
def __str__(self):
name = self.__class__.name
return name + "(device_name=" + self.device_name + ")"
class DeviceSerialRequestedNotification:
def __init__(self, serial):
self.serial = serial
def __str__(self):
name = self.__class__.__name__
return name + "(serial=" + str(self.serial) + ")"