Rework store and restore heating function data from and to database
This commit is contained in:
parent
04f269c750
commit
882ea0230c
4
base.py
4
base.py
@ -76,7 +76,9 @@ class videv_base(mqtt_base):
|
|||||||
# register a callback to listen for data from external device
|
# register a callback to listen for data from external device
|
||||||
ext_device.add_callback(ext_key, None, self.__rx_ext_device_data__, on_change_only)
|
ext_device.add_callback(ext_key, None, self.__rx_ext_device_data__, on_change_only)
|
||||||
# send initial display data to videv interface
|
# send initial display data to videv interface
|
||||||
self.__tx__(my_key, ext_device.get(ext_key))
|
data = ext_device.get(ext_key)
|
||||||
|
if data is not None:
|
||||||
|
self.__tx__(my_key, data)
|
||||||
|
|
||||||
def __rx_ext_device_data__(self, ext_device, ext_key, data):
|
def __rx_ext_device_data__(self, ext_device, ext_key, data):
|
||||||
my_key = self.__display_dict__[(id(ext_device), ext_key)]
|
my_key = self.__display_dict__[(id(ext_device), ext_key)]
|
||||||
|
@ -1,15 +1,31 @@
|
|||||||
|
from function.modules import heating_function
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
db_file = os.path.join(os.path.dirname(__file__), '..', 'database.db')
|
db_file = os.path.join(os.path.dirname(__file__), '..', 'database.db')
|
||||||
|
|
||||||
|
db_mapping_radiator = {
|
||||||
|
0: heating_function.KEY_AWAY_MODE,
|
||||||
|
1: heating_function.KEY_SUMMER_MODE,
|
||||||
|
2: heating_function.KEY_USER_TEMPERATURE_SETPOINT,
|
||||||
|
3: heating_function.KEY_TEMPERATURE_SETPOINT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_radiator_data(topic):
|
def get_radiator_data(topic):
|
||||||
return __storage__().get_radiator_data(topic)
|
db_data = __storage__().get_radiator_data(topic)
|
||||||
|
rv = {}
|
||||||
|
for index in db_mapping_radiator:
|
||||||
|
rv[db_mapping_radiator[index]] = db_data[index]
|
||||||
|
return rv
|
||||||
|
|
||||||
|
|
||||||
def set_radiator_data(topic, away_mode, summer_mode, user_temperatur_setpoint, temperatur_setpoint):
|
def set_radiator_data(device, key, data):
|
||||||
return __storage__().store_radiator_data(topic, away_mode, summer_mode, user_temperatur_setpoint, temperatur_setpoint)
|
if key in db_mapping_radiator.values():
|
||||||
|
db_data = []
|
||||||
|
for index in range(0, len(db_mapping_radiator)):
|
||||||
|
db_data.append(device.get(db_mapping_radiator[index]))
|
||||||
|
return __storage__().store_radiator_data(device.heating_valve.topic, db_data)
|
||||||
|
|
||||||
|
|
||||||
class __storage__(object):
|
class __storage__(object):
|
||||||
@ -25,19 +41,17 @@ class __storage__(object):
|
|||||||
temperatur_setpoint real
|
temperatur_setpoint real
|
||||||
)""")
|
)""")
|
||||||
|
|
||||||
def store_radiator_data(self, topic, away_mode, summer_mode, user_temperatur_setpoint, temperatur_setpoint):
|
def store_radiator_data(self, topic, target_data):
|
||||||
data = [topic, away_mode, summer_mode, user_temperatur_setpoint, temperatur_setpoint]
|
|
||||||
try:
|
try:
|
||||||
with self.conn:
|
with self.conn:
|
||||||
self.c.execute(
|
self.c.execute(
|
||||||
'INSERT INTO radiator VALUES (?, ?, ?, ?, ?)', data)
|
'INSERT INTO radiator VALUES (?, ?, ?, ?, ?)', [topic] + target_data)
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
data = [away_mode, summer_mode, user_temperatur_setpoint, temperatur_setpoint]
|
|
||||||
db_data = self.get_radiator_data(topic)
|
db_data = self.get_radiator_data(topic)
|
||||||
if db_data != data:
|
if db_data != target_data:
|
||||||
with self.conn:
|
with self.conn:
|
||||||
self.c.execute(
|
self.c.execute(
|
||||||
'UPDATE radiator SET away_mode = ?, summer_mode = ?, user_temperatur_setpoint = ?, temperatur_setpoint = ? WHERE topic = ?', data + [topic])
|
'UPDATE radiator SET away_mode = ?, summer_mode = ?, user_temperatur_setpoint = ?, temperatur_setpoint = ? WHERE topic = ?', target_data + [topic])
|
||||||
|
|
||||||
def get_radiator_data(self, topic):
|
def get_radiator_data(self, topic):
|
||||||
""" returns a list [away_mode, summer_mode, user_temperatur_setpoint, temperatur_setpoint] or [None, None, None, None]"""
|
""" returns a list [away_mode, summer_mode, user_temperatur_setpoint, temperatur_setpoint] or [None, None, None, None]"""
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import config
|
import config
|
||||||
import devices
|
import devices
|
||||||
|
from function.db import get_radiator_data, set_radiator_data
|
||||||
from function.helpers import day_event
|
from function.helpers import day_event
|
||||||
from function.modules import brightness_choose_n_action, timer_on_activation, heating_function
|
from function.modules import brightness_choose_n_action, timer_on_activation, heating_function
|
||||||
from function.rooms import room, room_collection
|
from function.rooms import room, room_collection
|
||||||
@ -157,7 +158,12 @@ class first_floor_east_sleep(room):
|
|||||||
self.bed_light_ma_powerplug.toggle_output_0_mcb)
|
self.bed_light_ma_powerplug.toggle_output_0_mcb)
|
||||||
|
|
||||||
# heating function
|
# heating function
|
||||||
self.heating_function = heating_function(self.heating_valve)
|
self.heating_function = heating_function(
|
||||||
|
self.heating_valve,
|
||||||
|
config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
|
||||||
|
**get_radiator_data(self.heating_valve.topic)
|
||||||
|
)
|
||||||
|
self.heating_function.add_callback(None, None, set_radiator_data, True)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Virtual Device Interface
|
# Virtual Device Interface
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import config
|
import config
|
||||||
import devices
|
import devices
|
||||||
|
from function.db import get_radiator_data, set_radiator_data
|
||||||
from function.modules import heating_function
|
from function.modules import heating_function
|
||||||
from function.rooms import room, room_collection
|
from function.rooms import room, room_collection
|
||||||
from function.videv import videv_switch_brightness, videv_switch_brightness_color_temp, videv_heating
|
from function.videv import videv_switch_brightness, videv_switch_brightness_color_temp, videv_heating
|
||||||
@ -58,7 +59,12 @@ class first_floor_west_bath(room):
|
|||||||
# Functionality initialisation
|
# Functionality initialisation
|
||||||
#
|
#
|
||||||
# heating function
|
# heating function
|
||||||
self.heating_function = heating_function(self.heating_valve)
|
self.heating_function = heating_function(
|
||||||
|
self.heating_valve,
|
||||||
|
config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
|
||||||
|
**get_radiator_data(self.heating_valve.topic)
|
||||||
|
)
|
||||||
|
self.heating_function.add_callback(None, None, set_radiator_data, True)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Virtual Device Interface
|
# Virtual Device Interface
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import config
|
import config
|
||||||
import devices
|
import devices
|
||||||
|
from function.db import get_radiator_data, set_radiator_data
|
||||||
from function.modules import brightness_choose_n_action, heating_function, switched_light
|
from function.modules import brightness_choose_n_action, heating_function, switched_light
|
||||||
from function.rooms import room, room_collection
|
from function.rooms import room, room_collection
|
||||||
from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player
|
from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player
|
||||||
@ -69,7 +70,12 @@ class ground_floor_west_marion(room):
|
|||||||
# Functionality initialisation
|
# Functionality initialisation
|
||||||
#
|
#
|
||||||
# heating function
|
# heating function
|
||||||
self.heating_function = heating_function(self.heating_valve)
|
self.heating_function = heating_function(
|
||||||
|
self.heating_valve,
|
||||||
|
config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
|
||||||
|
**get_radiator_data(self.heating_valve.topic)
|
||||||
|
)
|
||||||
|
self.heating_function.add_callback(None, None, set_radiator_data, True)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Virtual Device Interface
|
# Virtual Device Interface
|
||||||
@ -150,7 +156,12 @@ class ground_floor_west_dirk(room):
|
|||||||
self.audio_source = self.AUDIO_SOURCE_PC
|
self.audio_source = self.AUDIO_SOURCE_PC
|
||||||
|
|
||||||
# heating function
|
# heating function
|
||||||
self.heating_function = heating_function(self.heating_valve)
|
self.heating_function = heating_function(
|
||||||
|
self.heating_valve,
|
||||||
|
config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
|
||||||
|
**get_radiator_data(self.heating_valve.topic)
|
||||||
|
)
|
||||||
|
self.heating_function.add_callback(None, None, set_radiator_data, True)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Virtual Device Interface
|
# Virtual Device Interface
|
||||||
|
@ -14,7 +14,6 @@ Targets:
|
|||||||
from base import common_base
|
from base import common_base
|
||||||
import config
|
import config
|
||||||
import devices
|
import devices
|
||||||
from function.db import get_radiator_data, set_radiator_data
|
|
||||||
from function.helpers import day_state
|
from function.helpers import day_state
|
||||||
import logging
|
import logging
|
||||||
import task
|
import task
|
||||||
@ -153,19 +152,19 @@ class heating_function(common_base):
|
|||||||
AWAY_REDUCTION = 5
|
AWAY_REDUCTION = 5
|
||||||
SUMMER_TEMPERATURE = 5
|
SUMMER_TEMPERATURE = 5
|
||||||
|
|
||||||
def __init__(self, heating_valve):
|
def __init__(self, heating_valve, default_temperature, **kwargs):
|
||||||
self.heating_valve = heating_valve
|
self.heating_valve = heating_valve
|
||||||
self.default_temperature = config.DEFAULT_TEMPERATURE[heating_valve.topic]
|
self.default_temperature = default_temperature
|
||||||
db_data = get_radiator_data(heating_valve.topic)
|
#
|
||||||
super().__init__({
|
super().__init__({
|
||||||
self.KEY_USER_TEMPERATURE_SETPOINT: db_data[2] or self.default_temperature,
|
self.KEY_USER_TEMPERATURE_SETPOINT: kwargs.get(self.KEY_USER_TEMPERATURE_SETPOINT, self.default_temperature),
|
||||||
self.KEY_TEMPERATURE_SETPOINT: db_data[3] or self.default_temperature,
|
self.KEY_TEMPERATURE_SETPOINT: kwargs.get(self.KEY_TEMPERATURE_SETPOINT, self.default_temperature),
|
||||||
self.KEY_TEMPERATURE_CURRENT: None,
|
self.KEY_TEMPERATURE_CURRENT: kwargs.get(self.KEY_TEMPERATURE_CURRENT, None),
|
||||||
self.KEY_AWAY_MODE: db_data[0] or False,
|
self.KEY_AWAY_MODE: kwargs.get(self.KEY_AWAY_MODE, False),
|
||||||
self.KEY_SUMMER_MODE: db_data[1] or False,
|
self.KEY_SUMMER_MODE: kwargs.get(self.KEY_SUMMER_MODE, False),
|
||||||
self.KEY_START_BOOST: True,
|
self.KEY_START_BOOST: kwargs.get(self.KEY_START_BOOST, True),
|
||||||
self.KEY_SET_DEFAULT_TEMPERATURE: False,
|
self.KEY_SET_DEFAULT_TEMPERATURE: kwargs.get(self.KEY_SET_DEFAULT_TEMPERATURE, False),
|
||||||
self.KEY_BOOST_TIMER: 0
|
self.KEY_BOOST_TIMER: kwargs.get(self.KEY_BOOST_TIMER, 0)
|
||||||
})
|
})
|
||||||
#
|
#
|
||||||
self.heating_valve.set_heating_setpoint(self[self.KEY_TEMPERATURE_SETPOINT])
|
self.heating_valve.set_heating_setpoint(self[self.KEY_TEMPERATURE_SETPOINT])
|
||||||
@ -200,10 +199,7 @@ class heating_function(common_base):
|
|||||||
self.set(self.KEY_BOOST_TIMER, 0, block_callback=[self.timer_expired])
|
self.set(self.KEY_BOOST_TIMER, 0, block_callback=[self.timer_expired])
|
||||||
|
|
||||||
def send_command(self, key, data, block_callback=[]):
|
def send_command(self, key, data, block_callback=[]):
|
||||||
rv = super().set(key, data, block_callback)
|
return super().set(key, data, block_callback)
|
||||||
set_radiator_data(self.heating_valve.topic, self[self.KEY_AWAY_MODE], self[self.KEY_SUMMER_MODE],
|
|
||||||
self[self.KEY_USER_TEMPERATURE_SETPOINT], self[self.KEY_TEMPERATURE_SETPOINT])
|
|
||||||
return rv
|
|
||||||
|
|
||||||
def away_mode(self, device, key, value):
|
def away_mode(self, device, key, value):
|
||||||
if value is True:
|
if value is True:
|
||||||
|
@ -13,7 +13,7 @@ logger = logging.getLogger(config.APP_NAME)
|
|||||||
|
|
||||||
VERS_MAJOR = 1
|
VERS_MAJOR = 1
|
||||||
VERS_MINOR = 2
|
VERS_MINOR = 2
|
||||||
VERS_PATCH = 5
|
VERS_PATCH = 6
|
||||||
|
|
||||||
INFO_TOPIC = "__info__"
|
INFO_TOPIC = "__info__"
|
||||||
INFO_DATA = {
|
INFO_DATA = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user