async def async_init(self): """Init async items in entry.""" import bosch_thermostat_http as bosch self._update_lock = asyncio.Lock() self.gateway = bosch.Gateway(self.websession, self.address, self.access_key) if await self.async_init_bosch(): self.hass.helpers.dispatcher.async_dispatcher_connect( SIGNAL_BOSCH, self.get_signals) for component in self.supported_platforms: if component == SOLAR: continue self.hass.async_create_task( self.hass.config_entries.async_forward_entry_setup( self.entry, component)) device_registry = ( await self.hass.helpers.device_registry.async_get_registry()) device_registry.async_get_or_create( config_entry_id=self.entry.entry_id, identifiers={(DOMAIN, self.uuid)}, manufacturer=self.gateway.get_info(SYSTEM_BRAND), model=self.gateway.get_info(SYSTEM_TYPE), name=self.gateway.device_name, sw_version=self.gateway.firmware, ) if GATEWAY in self.hass.data[DOMAIN][self.uuid]: self.register_service(True, False) _LOGGER.debug( "Bosch component registered with platforms %s.", self.supported_platforms, ) return True return False
async def main(): """ Provide data_file.txt with ip, access_key, password and check if you can retrieve data from your thermostat. """ async with aiohttp.ClientSession() as session: data_file = open("data_file.txt", "r") data = data_file.read().splitlines() gateway = bosch.Gateway(session, host=data[0], access_key=data[1], password=data[2]) print(await gateway.check_connection()) #await gateway.initialize_circuits(DHW) #await gateway.initialize_circuits(HC) #dhws = gateway.dhw_circuits #dhw = dhws[0] #print("getting property") #print(dhw.get_property(DHW_OFFTEMP_LEVEL)) #await dhw.update() #print(dhw.get_property(DHW_OFFTEMP_LEVEL)) # await hc.set_operation_mode("manual") await gateway.set_value("/heatingCircuits/hc1/suWiSwitchMode", "forced") #time.sleep(5) print(await gateway.get("/heatingCircuits/hc1/currentSuWiMode")) print(await gateway.get("/heatingCircuits/hc1/suWiSwitchMode")) #print(await gateway.get("/heatingCircuits/hc1/currentRoomSetpoint")) #await gateway.set_value("/heatingCircuits/hc1/manualRoomSetpoint", 22.0) #time.sleep(3) #print(await gateway.get("/heatingCircuits/hc1/currentRoomSetpoint")) #print(await gateway.get("/heatingCircuits/hc1/operationMode")) await session.close()
async def main(): """ Provide data_file.txt with ip, access_key, password and check if you can retrieve data from your thermostat. """ async with aiohttp.ClientSession() as session: data_file = open("data_file_ka.txt", "r") data = data_file.read().splitlines() gateway = bosch.Gateway(session, host=data[0], access_key=data[1]) await gateway.check_connection() print(gateway.firmware) print(gateway.device_name) await gateway.initialize_circuits(HC) hcs = gateway.heating_circuits hc = hcs[1] time.sleep(1) await hc.update() # print(hc.hvac_modes) # print(hc.hvac_mode) # print(hc.target_temperature) await hc.set_hvac_mode("auto") # await hc.update() # print(hc.hvac_mode) # await hc.set_temperature(21) # await hc.update() print(hc.target_temperature) # print(hc.schedule.get_temp_for_date(gateway.get_info(DATE))) smallscan = await gateway.smallscan() to_file = "kamika_raw_small.json" with open(to_file, 'w') as logfile: json.dump(smallscan, logfile, indent=4) return aa = 0 while aa < 10: time.sleep(1) await hc.update() print(hc.target_temperature) aa = aa + 1 await hc.set_operation_mode("auto") aa = 0 while aa < 10: time.sleep(1) await hc.update() print(hc.target_temperature) aa = aa + 1 # print(gateway.get_property(TYPE_INFO, UUID)) await session.close()
async def main(): """ Provide data_file.txt with ip, access_key, password and check if you can retrieve data from your thermostat. """ async with aiohttp.ClientSession() as session: data_file = open("data_file.txt", "r") data = data_file.read().splitlines() gateway = bosch.Gateway(session=session, host=data[0], access_key=data[1], password=data[2]) print(await gateway.check_connection()) sensors = bosch_sensors(gateway.get_info(FIRMWARE_VERSION)) print(sensors) await gateway.initialize_sensors(sensors) print(gateway.sensors) # # await gateway.rawscan() await session.close()
async def dhw(ctx, ip: str, token: str, password: str, debug: int, target_temp: int, op_mode: int, op_modes: int, setpoints: int): if debug: logging.basicConfig(level=logging.DEBUG) _LOGGER.info("Debug mode active") _LOGGER.debug(f"Lib version is {bosch.version.__version__}") else: logging.basicConfig(level=logging.INFO) async with aiohttp.ClientSession() as session: gateway = bosch.Gateway(session=session, host=ip, access_key=token, password=password) _LOGGER.debug("Trying to connect to gateway.") if await gateway.check_connection(): _LOGGER.info("Successfully connected to gateway. Found UUID: %s", gateway.uuid) await circuit_fetch(gateway, DHW, target_temp, op_mode, op_modes, setpoints) else: _LOGGER.error("Couldn't connect to gateway!") await session.close()
async def cli(ctx, ip: str, token: str, password: str, output: str, stdout: int, debug: int, smallscan: str): """A tool to create rawscan of Bosch thermostat.""" if debug: logging.basicConfig(level=logging.DEBUG) _LOGGER.info("Debug mode active") _LOGGER.debug(f"Lib version is {bosch.version.__version__}") else: logging.basicConfig(level=logging.INFO) async with aiohttp.ClientSession() as session: _LOGGER.debug("Connecting to %s with token '%s' and password '%s'", ip, token, password) gateway = bosch.Gateway(session=session, host=ip, access_key=token, password=password) _LOGGER.debug("Trying to connect to gateway.") if await gateway.check_connection(): _LOGGER.info("Successfully connected to gateway. Found UUID: %s", gateway.uuid) if smallscan: result = await gateway.smallscan(smallscan) out_file = output if output else f"smallscan_{gateway.uuid}.json" else: result = await gateway.rawscan() out_file = output if output else f"rawscan_{gateway.uuid}.json" if stdout: print(json.dumps(result, indent=4)) else: with open(out_file, "w") as logfile: json.dump(result, logfile, indent=4) _LOGGER.info("Successfully saved result to file: %s", out_file) _LOGGER.debug("Job done.") else: _LOGGER.error("Couldn't connect to gateway!") await session.close()
async def sensors(ctx, ip: str, token: str, password: str, debug: int, sensor): if debug: logging.basicConfig(level=logging.DEBUG) _LOGGER.info("Debug mode active") _LOGGER.debug(f"Lib version is {bosch.version.__version__}") else: logging.basicConfig(level=logging.INFO) async with aiohttp.ClientSession() as session: gateway = bosch.Gateway(session=session, host=ip, access_key=token, password=password) _LOGGER.debug("Trying to connect to gateway.") if await gateway.check_connection(): _LOGGER.info("Successfully connected to gateway. Found UUID: %s", gateway.uuid) sensors = gateway.initialize_sensors(list(sensor)) for sensor_obj in sensors: await sensor_obj.update() print(sensor_obj.name, ":", sensor_obj.get_property(sensor_obj.attr_id)) else: _LOGGER.error("Couldn't connect to gateway!") await session.close()
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry): """Create entry for Bosch thermostat device.""" import bosch_thermostat_http as bosch _LOGGER.debug("Setting up Bosch component.") SUPPORTED_PLATFORMS = [] websession = async_get_clientsession(hass, verify_ssl=False) uuid = entry.title if entry.data[CONF_ADDRESS] and entry.data[ACCESS_KEY]: gateway = bosch.Gateway(websession, entry.data[CONF_ADDRESS], entry.data[ACCESS_KEY]) store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY) prefs = await store.async_load() _LOGGER.debug("Checking connection to Bosch gateway.") if not await gateway.check_connection(): _LOGGER.error( "Cannot connect to Bosch gateway, host %s with UUID: %s", entry.data[CONF_ADDRESS], uuid) return False current_firmware = gateway.get_info(FIRMWARE_VERSION) if prefs is None: prefs = {uuid: {"uuid": uuid, FIRMWARE_VERSION: current_firmware}} hcs, need_saving1 = (await initialize_component(HC, uuid, prefs[uuid], gateway)) if hcs: SUPPORTED_PLATFORMS.append(CLIMATE) prefs[uuid] = hcs water_heaters, need_saving2 = (await initialize_component( DHW, uuid, prefs[uuid], gateway)) if water_heaters: SUPPORTED_PLATFORMS.append(WATER_HEATER) # This is HCS and water heater object. prefs[uuid] = water_heaters sensors, need_saving3 = (await initialize_component( "sensors", uuid, bosch_sensors(current_firmware), gateway)) if sensors: SUPPORTED_PLATFORMS.append(SENSOR) hass.data[DOMAIN][uuid] = {GATEWAY: gateway} if need_saving1 or need_saving2: await store.async_save(prefs) for component in SUPPORTED_PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup( entry, component)) device_registry = (await hass.helpers.device_registry.async_get_registry()) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, uuid)}, manufacturer=gateway.get_info(SYSTEM_BRAND), model=gateway.get_info(SYSTEM_TYPE), name="Gateway iCom_Low_NSC_v1", sw_version=current_firmware) _LOGGER.debug("Bosch component registered.") async def thermostat_refresh(event_time): """Call Bosch to refresh information.""" _LOGGER.debug("Updating Bosch thermostat entitites.") data = hass.data[DOMAIN][uuid] updated = False if CLIMATE in SUPPORTED_PLATFORMS: await circuit_update(data['hcs'], HCS_UPDATE_KEYS) dispatcher_send(hass, SIGNAL_CLIMATE_UPDATE_BOSCH) updated = True if WATER_HEATER in SUPPORTED_PLATFORMS: await circuit_update(data['dhws'], DHW_UPDATE_KEYS) dispatcher_send(hass, SIGNAL_DHW_UPDATE_BOSCH) updated = True if SENSOR in SUPPORTED_PLATFORMS: await sensors_update(data['sensors']) dispatcher_send(hass, SIGNAL_SENSOR_UPDATE_BOSCH) updated = True if updated: _LOGGER.debug("Bosch thermostat entitites updated.") async def async_handle_debug_service(service_call): filename = hass.config.path("www/bosch_scan.json") def _write_to_filr(to_file, rawscan): """Executor helper to write image.""" with open(to_file, 'w') as logfile: json.dump(rawscan, logfile, indent=4) url = "{}{}".format(hass.config.api.base_url, "/local/bosch_scan.json") _LOGGER.info("Rawscan success. Your URL: {}?v{}".format( url, random.randint(0, 5000))) try: _LOGGER.info("Starting rawscan of Bosch component") rawscan = await gateway.rawscan() await hass.async_add_executor_job(_write_to_filr, filename, rawscan) except OSError as err: _LOGGER.error("Can't write image to file: %s", err) # hass.services.register(DOMAIN, 'update', thermostat_refresh) hass.services.async_register(DOMAIN, SERVICE_DEBUG, async_handle_debug_service, SERVICE_DEBUG_SCHEMA) # Repeat running every 30 seconds. async_track_time_interval(hass, thermostat_refresh, SCAN_INTERVAL) return True
async def main(): """ Provide data_file.txt with ip, access_key, password and check if you can retrieve data from your thermostat. """ async with aiohttp.ClientSession() as session: data_file = open("data_file.txt", "r") data = data_file.read().splitlines() gateway = bosch.Gateway(session, host=data[0], access_key=data[1], password=data[2]) print(await gateway.check_connection()) # return await gateway.initialize_circuits(DHW) # small = await gateway.smallscan(DHW_CIRCUITS) # myjson = json.loads(small) # print(small) # return # sensors = gateway.initialize_sensors() # for sensor in sensors: # await sensor.update() dhws = gateway.dhw_circuits dhw = dhws[0] time.sleep(1) await dhw.update() # await hc.set_ha_mode("auto") #MEANS AUTO # await hc.update() # time.sleep(4) print("hvac mode", dhw.ha_mode) print("target temp ->", dhw.target_temperature) await dhw.set_temperature(53.0) # return # return # await dhw.set_ha_mode("performance") #MEANS MANUAL return # print("target in manual", hc.target_temperature) # print("ha mode in manual", hc.ha_mode) # await hc.update() # print("target after update", hc.target_temperature) # print("ha mode", hc.ha_mode) # await hc.set_ha_mode("auto") #MEANS AUTO # print("target after auto without update", hc.target_temperature) # print("ha mode", hc.ha_mode) # return # print(await hc.set_temperature(10.0)) # print("ustawiona!") dhws = gateway.dhw_circuits dhw = dhws[0] await dhw.update() print("START1") print(dhw.target_temperature) print("START2") print(dhw.current_mode) print(dhw.target_temperature) return print("START3") print(dhw.target_temperature) return # print(hc.schedule) print(gateway.get_info(DATE)) # print(await gateway.rawscan()) #print(hc.schedule.get_temp_for_date(gateway.get_info(DATE))) return aa = 0 while aa < 10: time.sleep(1) await hc.update() print(hc.target_temperature) aa = aa + 1 await hc.set_operation_mode("auto") aa = 0 while aa < 10: time.sleep(1) await hc.update() print(hc.target_temperature) aa = aa + 1 # print(gateway.get_property(TYPE_INFO, UUID)) await session.close()