-
Notifications
You must be signed in to change notification settings - Fork 1
/
io_data.py
160 lines (139 loc) · 5.14 KB
/
io_data.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C)2018-24 Maurizio Montel (dr-prodigy) <[email protected]>
# This file is part of hompi <https://github.com/dr-prodigy/hompi>.
#
# hompi is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# hompi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with hompi. If not, see <http://www.gnu.org/licenses/>.
import json
import datetime
import config
hide_message_time = None
class Input:
def __init__(self):
self.last_update = datetime.datetime.now().isoformat()
self.data = ''
class Status:
def __init__(self):
global hide_message_time
# general
self.id = config.HOMPI_ID
self.last_update = datetime.datetime.now().isoformat()
self.last_change = datetime.datetime.now().isoformat()
self.hompi_slaves = {}
self.hompi_ext_sensors = {}
# heating
if config.MODULE_TEMP:
self.int_temp_c = 0.0
# TRV
if config.MODULE_TRV:
self.areas = {}
self.req_area_temps = ''
self.mode_id = ''
self.mode_desc = ''
self.short_mode_desc = ''
self.timetable_desc = ''
self.day_type_desc = ''
self.req_temp_c = 0.0
self.req_temp_desc = ''
self.req_start_time = 0
self.req_end_time = 0
self.heating_status = 'off'
# switches
self.sw_sig = [False]*len(config.BUTTONS)
self.sw_status = [False]*len(config.BUTTONS)
# gui
self.current_image = ''
self.message = ''
hide_message_time = datetime.datetime.now()
# ambient
if config.MODULE_AMBIENT:
self.ambient_color = '000000'
self.ambient_effect = None
self.ambient_on = False
# meteo
if config.MODULE_METEO:
self.ext_temp_c = 0.0
self.place = ''
self.weather = ''
self.humidity = 0
self.pressure = 0
self.wind = 0.0
# aphorism
if config.MODULE_APHORISM:
self.aphorism_text = ''
self.aphorism_author = ''
def get_output(self):
return json.dumps(self.__dict__, indent=0)
def get_status_text(self):
if self.message != '':
status = '{}'.format(self.message)
else:
state = self.mode_desc.lower().replace('-', ' ')
heating = self.heating_status.lower().replace('-', ' ')
status = 'temperature {:.1f} degrees, {} mode'.\
format(self.int_temp_c, state) + \
(', target {:.1f} degrees, heating {}'.format(
self.req_temp_c, heating)
if state in ['automatic', 'manual'] else
'')
return status
def set_ambient(self, ambient):
self.ambient_color = ambient.status_color
self.ambient_on = ambient.status_power_on
self.ambient_effect = ambient.status_effect
def update(self, current_time):
if self.message != '' and hide_message_time <= current_time:
self.message = ''
self.last_change == current_time.isoformat()
def send_message(self, message):
global hide_message_time
self.message = message.encode('utf-8')
self.last_change = datetime.datetime.now().isoformat()
hide_message_time = datetime.datetime.now() + datetime.timedelta(seconds=40)
def reset_message(self):
global hide_message_time
self.message = ''
self.last_change = datetime.datetime.now().isoformat()
hide_message_time = datetime.datetime.now()
def send_switch_command(self, switch):
self.sw_sig[switch] = True
def get_area_manual_set(self):
is_manual_set = False
if config.MODULE_TRV:
for area in self.areas.values():
if 'manual_set' in area:
is_manual_set |= area['manual_set']
return is_manual_set
class SystemInfo:
def __init__(self):
self.modules = []
self.buttons = []
self.temperatures = []
if config.MODULE_AMBIENT:
self.modules.append('ambient')
self.ambient_commands = ['AMBIENT_XMAS']
if config.MODULE_APHORISM:
self.modules.append('aphorism')
if config.MODULE_DB_LOG:
self.modules.append('db_log')
if config.MODULE_LCD:
self.modules.append('lcd')
if config.MODULE_METEO:
self.modules.append('meteo')
if config.MODULE_TEMP:
self.modules.append('temp')
for button in config.BUTTONS:
self.buttons.append(button[1])
def get_output(self):
return json.dumps(self.__dict__, indent=0)