87 lines
3.8 KiB
Python
87 lines
3.8 KiB
Python
|
|
||
|
import logging
|
||
|
|
||
|
from xmlrpc.server import SimpleXMLRPCServer
|
||
|
import config
|
||
|
import control
|
||
|
|
||
|
class Remotecontrol():
|
||
|
def __init__(self, configfile):
|
||
|
self.__log = logging.getLogger()
|
||
|
self.__config = config.Config(configfile)
|
||
|
|
||
|
host = (self.__config.hostinfo())
|
||
|
self.__server = SimpleXMLRPCServer(host, allow_none=True)
|
||
|
self.__control = control.Control(configfile)
|
||
|
|
||
|
self.__server.register_function(self.set_water_autostate, 'set_water_autostate')
|
||
|
self.__server.register_function(self.clear_water_autostate, 'clear_water_autostate')
|
||
|
self.__server.register_function(self.set_water_times, 'set_water_times')
|
||
|
|
||
|
self.__server.register_function(self.set_heat_autostate, 'set_heat_autostate')
|
||
|
self.__server.register_function(self.clear_heat_autostate, 'clear_heat_autostate')
|
||
|
self.__server.register_function(self.increase_on_temperature, 'increase_on_temperature')
|
||
|
self.__server.register_function(self.decrease_on_temperature, 'decrease_on_temperature')
|
||
|
self.__server.register_function(self.increase_off_temperature, 'increase_off_temperature')
|
||
|
self.__server.register_function(self.decrease_off_temperature, 'decrease_off_temperature')
|
||
|
|
||
|
self.__server.register_function(self.__config.get_heat_autostate, 'get_heat_autostate')
|
||
|
self.__server.register_function(self.__config.get_on_temperature, 'get_on_temperature')
|
||
|
self.__server.register_function(self.__config.get_off_temperature, 'get_off_temperature')
|
||
|
self.__server.register_function(self.__config.get_water_autostate, 'get_water_autostate')
|
||
|
self.__server.register_function(self.__config.get_water_times, 'get_water_times')
|
||
|
|
||
|
self.__server.register_function(self.__control.get_current_temperature, 'get_current_temperature')
|
||
|
self.__server.register_function(self.__control.get_current_heat_state, 'get_current_heat_state')
|
||
|
self.__server.register_function(self.__control.get_current_water_state, 'get_current_water_state')
|
||
|
|
||
|
self.__server.register_function(self.__control.set_heat_state, 'set_heat_state')
|
||
|
self.__server.register_function(self.__control.clear_heat_state, 'clear_heat_state')
|
||
|
self.__server.register_function(self.__control.set_water_state, 'set_water_state')
|
||
|
self.__server.register_function(self.__control.clear_water_state, 'clear_water_state')
|
||
|
|
||
|
def set_water_times(self, ident: str, times):
|
||
|
self.__config.set_water_times(ident, times)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def set_water_autostate(self, ident: str):
|
||
|
self.__config.set_water_autostate(ident)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def clear_water_autostate(self, ident: str):
|
||
|
self.__config.clear_water_autostate(ident)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def set_heat_autostate(self, ident: str):
|
||
|
self.__config.set_heat_autostate(ident)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def clear_heat_autostate(self, ident: str):
|
||
|
self.__config.clear_heat_autostate(ident)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def increase_on_temperature(self, ident: str):
|
||
|
self.__config.increase_on_temperature(ident)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def decrease_on_temperature(self, ident: str):
|
||
|
self.__config.decrease_on_temperature(ident)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def increase_off_temperature(self, ident: str):
|
||
|
self.__config.increase_off_temperature(ident)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def decrease_off_temperature(self, ident: str):
|
||
|
self.__config.decrease_off_temperature(ident)
|
||
|
self.__control.reload_config()
|
||
|
|
||
|
def start(self):
|
||
|
self.__log.info('Control-c to quit')
|
||
|
self.__control.start()
|
||
|
self.__server.serve_forever()
|
||
|
|
||
|
self.__log.info("Shutting down...")
|
||
|
self.__control.stop()
|
||
|
self.__log.info("...done. Exiting...")
|