def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the Radio Thermostat. """ try: import radiotherm except ImportError: _LOGGER.exception( "Unable to import radiotherm. " "Did you maybe not install the 'radiotherm' package?") return False hosts = [] if CONF_HOST in config: hosts = config[CONF_HOST] else: hosts.append(radiotherm.discover.discover_address()) if hosts is None: _LOGGER.error("No radiotherm thermostats detected.") return False hold_temp = config.get(HOLD_TEMP, False) tstats = [] for host in hosts: try: tstat = radiotherm.get_thermostat(host) tstats.append(RadioThermostat(tstat, hold_temp)) except (URLError, OSError): _LOGGER.exception("Unable to connect to Radio Thermostat: %s", host) add_devices(tstats)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Radio Thermostat.""" import radiotherm hosts = [] if CONF_HOST in config: hosts = config[CONF_HOST] else: hosts.append(radiotherm.discover.discover_address()) if hosts is None: _LOGGER.error("No Radiotherm Thermostats detected") return False hold_temp = config.get(CONF_HOLD_TEMP) away_temps = [ config.get(CONF_AWAY_TEMPERATURE_HEAT), config.get(CONF_AWAY_TEMPERATURE_COOL) ] tstats = [] for host in hosts: try: tstat = radiotherm.get_thermostat(host) tstats.append(RadioThermostat(tstat, hold_temp, away_temps)) except OSError: _LOGGER.exception("Unable to connect to Radio Thermostat: %s", host) add_entities(tstats, True)
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Radio Thermostat.""" import radiotherm hosts = [] if CONF_HOST in config: hosts = config[CONF_HOST] else: hosts.append(radiotherm.discover.discover_address()) if hosts is None: _LOGGER.error("No Radiotherm Thermostats detected") return False hold_temp = config.get(CONF_HOLD_TEMP) tstats = [] for host in hosts: try: tstat = radiotherm.get_thermostat(host) tstats.append(RadioThermostat(tstat, hold_temp)) except (URLError, OSError): _LOGGER.exception("Unable to connect to Radio Thermostat: %s", host) add_devices(tstats)
def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Radio Thermostat.""" hosts = [] if CONF_HOST in config: hosts = config[CONF_HOST] else: hosts.append(radiotherm.discover.discover_address()) if hosts is None: _LOGGER.error("No Radiotherm Thermostats detected") return False hold_temp = config.get(CONF_HOLD_TEMP) tstats = [] for host in hosts: try: tstat = radiotherm.get_thermostat(host) tstats.append(RadioThermostat(tstat, hold_temp)) except OSError: _LOGGER.exception("Unable to connect to Radio Thermostat: %s", host) add_entities(tstats, True)
def test_model_found(self, mock_get_class): mock_model = MagicMock() mock_model.get = lambda x: MODEL with patch('radiotherm.thermostat.CommonThermostat.model', mock_model): ret = radiotherm.get_thermostat(IP) mock_get_class.assert_called_once_with(MODEL)
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Radio Thermostat.""" import radiotherm hosts = [] if CONF_HOST in config: hosts = config[CONF_HOST] else: hosts.append(radiotherm.discover.discover_address()) if hosts is None: _LOGGER.error("No radiotherm thermostats detected.") return False hold_temp = config.get(HOLD_TEMP, False) tstats = [] for host in hosts: try: tstat = radiotherm.get_thermostat(host) tstats.append(RadioThermostat(tstat, hold_temp)) except (URLError, OSError): _LOGGER.exception("Unable to connect to Radio Thermostat: %s", host) add_devices(tstats)
def _get_init_data(host: str) -> RadioThermInitData: tstat = radiotherm.get_thermostat(host) tstat.timeout = TIMEOUT name: str = tstat.name["raw"] sys: dict[str, Any] = tstat.sys["raw"] mac: str = dr.format_mac(sys["uuid"]) model: str = tstat.model.get("raw") return RadioThermInitData(tstat, host, name, mac, model, sys.get("fw_version"), sys.get("api_version"))
def getinfo(ip): tstat = radiotherm.get_thermostat(ip) #tstat.temp & dicts use dicts as output. temp = tstat.temp['raw'] #this grabs the raw value of temp from the therm and puts into a float FanState = tstat.fstate['raw'] #this grabs the raw value of fan on or off ThermState = tstat.tstate['raw'] #this grabs raw value of thermostat state -if it is commanding cool, heat,or off tname = tstat.name['raw'] #name of thermostat given by the radio thermostat company ThermMode = tstat.tmode['raw'] #current mode: cool, heat or off. if (ThermMode == 2): comm = tstat.t_cool['raw'] #commanded temp, not sure the difference b/w t_cool and it_cool else: comm = tstat.t_heat['raw'] #commanded temp for heat return {'temp': temp, 'FanState': FanState, 'ThermState': ThermState, 'ThermName': tname, 'comm': comm}
def connect(): """Connect to the thermostat. Returns a radiotherm object""" try: tstat = radiotherm.get_thermostat() except IOError as e: if len(e.args) == 0: logger.critical("Unable to find the thermostat: Generic IOError." " Sorry, python wouldn't tell me any more.") else: logger.critical("Unable to find the thermostat: %s (%d)", e.strerror, e.errno) raise except Exception: logger.critical("Unable to connect to the thermostat:") logger.critical(format_exc()) raise return tstat
def get_tstat_recs(self): w = {'owm_' + k: v for k, v in self.get_weather().items()} recs = [] for name, ip in self.TSTATS.items(): th = radiotherm.get_thermostat(ip) d = { 'name': name, 'ip': ip, 'ts': self.local_tz.localize(datetime.datetime.now()) } d.update({k: v for k, v in th.tstat['raw'].items() if k != 'time'}) dl = th.datalog['raw'] for day in dl: for rt in dl[day]: d["{}_{}".format( day, rt)] = dl[day][rt]['hour'] * 60 + dl[day][rt]['minute'] d.update(w) recs.append(d) return recs
def setup_platform(hass, config, add_devices, discovery_info=None): import radiotherm hosts = [] if CONF_HOST in config: hosts = config[CONF_HOST] else: hosts.append(radiotherm.discover.discover_address()) if hosts is None: _LOGGER.error("No Radiotherm Thermostats detected") tstats = [] for host in hosts: try: _LOGGER.info("Connecting to radiotherm at %s", host) tstat = radiotherm.get_thermostat(host) for s_type in CLIMATE_BINARY_TYPES: tstats.append(RadioThermostatBinarySensor(tstat, s_type)) except OSError: _LOGGER.exception("Unable to connect to Radio Thermostat: %s", host) add_devices(tstats, True)
import radiotherm tstat = radiotherm.get_thermostat() print(tstat.temp)
#!usr/bin/env python import radiotherm tstat = radiotherm.get_thermostat('192.168.0.9') print tstat.temp print tstat.tstate print tstat.tmode print tstat.fstate print tstat.fmode print tstat.version print tstat.time print tstat.t_cool print tstat.it_cool print tstat.t_heat print tstat.it_heat print tstat.sys
def test_model_not_found(self): ret = radiotherm.get_thermostat(IP) self.assertIsNone(ret)
def test_without_address(self, mock_model, mock_discover_address): radiotherm.get_thermostat() mock_discover_address.assert_called_once_with()
def test_creates_common_tstat(self, mock_model): with patch('radiotherm.thermostat.CommonThermostat.__init__', MagicMock(return_value=None)) as mock_init: radiotherm.get_thermostat(IP) mock_init.assert_called_once_with(IP)
import time import radiotherm from influxdb import client as influxdb def record_state(db, tsdata): data = [{'points':[[tsdata['temp'], tsdata['tstate'], tsdata['t_cool'], tsdata['hold']]], 'name':'thermostat_data', 'columns':['temp','state','t_cool','hold']}] print(data) db.write_points(data) if __name__ == '__main__': db = influxdb.InfluxDBClient(host='raspberrypi', database='hvac') #ts = radiotherm.get_thermostat('thermostat-89-BD-39.local') ts = radiotherm.get_thermostat('192.168.1.217') last_state = ts.tstat['raw'] del last_state['time'] last_time = time.time() record_state(db, last_state) while True: time.sleep(5) state = ts.tstat['raw'] del state['time'] if state['tstate'] == -1: continue if state != last_state: record_state(db, state) last_time = time.time()
self.hold.value = value def get_config(): try: with open('/etc/radio_thermostat/config.yaml', 'r') as f: # use safe_load instead load configMap = yaml.safe_load(f) except FileNotFoundError: with open('config.yaml', 'r') as f: configMap = yaml.safe_load(f) return(configMap) configMap = get_config() rtherm = radiotherm.get_thermostat() name = rtherm.name['raw'] thermostat = Device_Radio_Thermostat(device_id=name.lower().replace(" ", ""), name=name, mqtt_settings=configMap['mqtt'], tstat_device=rtherm) def main(): last_report_time = 0 while True: if (time.time() - last_report_time) > configMap['update']['interval'] * 60: thermostat.update() last_report_time = time.time() time.sleep(1) if __name__ == '__main__': try: