async def async_init(self):
        """Init async items in entry."""
        import bosch_thermostat_client as bosch

        _LOGGER.debug("Initializing Bosch integration.")
        self._update_lock = asyncio.Lock()
        BoschGateway = bosch.gateway_chooser(device_type=self._device_type)
        self.gateway = BoschGateway(
            session=async_get_clientsession(self.hass, verify_ssl=False)
            if self._protocol == HTTP else None,
            session_type=self._protocol,
            host=self._host,
            access_key=self._access_key,
            access_token=self._access_token,
        )

        async def close_connection(event):
            """Close connection with server."""
            _LOGGER.debug("Closing connection to Bosch")
            await self.gateway.close()

        if await self.async_init_bosch():
            self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP,
                                            close_connection)
            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.config_entry, component))
            device_registry = (
                await self.hass.helpers.device_registry.async_get_registry())
            device_registry.async_get_or_create(
                config_entry_id=self.config_entry.entry_id,
                identifiers={(DOMAIN, self.uuid)},
                manufacturer=self.gateway.device_model,
                model=self.gateway.device_type,
                name=self.gateway.device_name,
                sw_version=self.gateway.firmware,
            )
            if GATEWAY in self.hass.data[DOMAIN][self.uuid]:
                _LOGGER.debug("Registering services.")
                self.register_service(True, False)
            _LOGGER.debug(
                "Bosch component registered with platforms %s.",
                self.supported_platforms,
            )
            return True
        return False
Exemplo n.º 2
0
    async def async_init(self):
        """Init async items in entry."""
        import bosch_thermostat_client as bosch

        self._update_lock = asyncio.Lock()
        BoschGateway = bosch.gateway_chooser(device_type=self._device_type)
        self.gateway = BoschGateway(
            session=self._session,
            session_type=self._protocol,
            host=self._host,
            access_key=self._access_key,
            access_token=self._access_token)
        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.config_entry, component
                    )
                )
            device_registry = (
                await self.hass.helpers.device_registry.async_get_registry()
            )
            device_registry.async_get_or_create(
                config_entry_id=self.config_entry.entry_id,
                identifiers={(DOMAIN, self.uuid)},
                manufacturer=self.gateway.device_model,
                model=self.gateway.device_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 configure_gateway(self,
                             device_type,
                             session_type,
                             host,
                             access_token,
                             password=None,
                             session=None):
     try:
         BoschGateway = gateway_chooser(device_type)
         device = BoschGateway(
             session_type=session_type,
             host=host,
             access_token=access_token,
             password=password,
             session=session,
         )
         try:
             uuid = await device.check_connection()
         except (FirmwareException, UnknownDevice) as err:
             create_notification_firmware(hass=self.hass, msg=err)
             uuid = device.uuid
         if uuid:
             await self.async_set_unique_id(uuid)
             self._abort_if_unique_id_configured()
     except (DeviceException, EncryptionException) as err:
         _LOGGER.error("Wrong IP or credentials at %s - %s", host, err)
         return self.async_abort(reason="faulty_credentials")
     except Exception as err:  # pylint: disable=broad-except
         _LOGGER.error("Error connecting Bosch at %s - %s", host, err)
     else:
         _LOGGER.debug("Adding Bosch entry.")
         return self.async_create_entry(
             title=device.device_name or "Unknown model",
             data={
                 CONF_ADDRESS: device.host,
                 UUID: uuid,
                 ACCESS_KEY: device.access_key,
                 ACCESS_TOKEN: device.access_token,
                 CONF_DEVICE_TYPE: self._choose_type,
                 CONF_PROTOCOL: session_type,
             },
         )
async def cli(ctx, host: str, token: str, password: str, protocol: str, device: 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)
    logging.getLogger('aioxmpp').setLevel(logging.WARN)
    logging.getLogger('aioopenssl').setLevel(logging.WARN)
    logging.getLogger('aiosasl').setLevel(logging.WARN)
    logging.getLogger('asyncio').setLevel(logging.WARN)
    if device.upper() == NEFIT or device.upper() == IVT:
        BoschGateway = bosch.gateway_chooser(device_type=device)
    else:
        _LOGGER.error("Wrong device type.")
        return
    if protocol.upper() == XMPP:
        gateway = BoschGateway(session=asyncio.get_event_loop(),
                               session_type=XMPP,
                               host=host,
                               access_token=token,
                               password=password)
        if await gateway.check_connection():
            await scan(gateway, smallscan, output, stdout)
    elif protocol.upper() == HTTP and device.upper() == IVT:
        async with aiohttp.ClientSession() as session:
            _LOGGER.debug("Connecting to %s with token '%s' and password '%s'", host, token, password)
            gateway = BoschGateway(session=session,
                                   session_type=HTTP,
                                   host=host,
                                   access_token=token,
                                   password=password)
            _LOGGER.debug("Trying to connect to gateway.")
            if await gateway.check_connection():
                await scan(gateway, smallscan, output, stdout)
            else:
                _LOGGER.error("Couldn't connect to gateway!")
            await session.close()
Exemplo n.º 5
0
 async def configure_gateway(self,
                             device_type,
                             session,
                             session_type,
                             host,
                             access_token,
                             password=None):
     try:
         BoschGateway = gateway_chooser(device_type)
         device = BoschGateway(session=session,
                               session_type=session_type,
                               host=host,
                               access_token=access_token,
                               password=password)
         uuid = await device.check_connection()
         if uuid:
             return await self._entry_from_gateway(device, uuid)
     except DeviceException as err:
         _LOGGER.error("Wrong IP or credentials at %s - %s", host, err)
         return self.async_abort(reason="faulty_credentials")
     except Exception as err:  # pylint: disable=broad-except
         _LOGGER.error("Error connecting Bosch at %s - %s", host, err)
Exemplo n.º 6
0
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_file = open("data_file.txt", "r")
        data = data_file.read().splitlines()
        BoschGateway = bosch.gateway_chooser(device_type=IVT)
        gateway = BoschGateway(session=session,
                               session_type=HTTP,
                               host=data[0],
                               access_token=data[1],
                               password=data[2])
        print(await gateway.check_connection())
        await gateway.initialize_circuits(HC)
        # await gateway.test_connection()
        # small = await gateway.smallscan(DHW_CIRCUITS)
        #        myjson = json.loads(small)
        # print(small)
        # return
        # sensors = gateway.initialize_sensors()
        # for sensor in sensors:
        #     await sensor.update()

        hcs = gateway.heating_circuits
        for hc in hcs:
            time.sleep(1)
            await hc.update()
            print("hvac mode", hc.ha_mode)
            print("target temp ->", hc.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()
async def main():
    """
    Provide data_file.txt with ip, access_key, password and check
    if you can retrieve data from your thermostat.
    """
    data_file = open("data_file_nefit2.txt", "r")
    data = data_file.read().splitlines()
    loop = asyncio.get_event_loop()
    BoschGateway = bosch.gateway_chooser(device_type=NEFIT)
    gateway = BoschGateway(session=loop,
                           session_type=XMPP,
                           host=data[0],
                           access_token=data[1],
                           password=data[2],
                           nefit_connector=NefitConnector2)
    # gateway = BoschGateway(session=loop,
    #                        session_type="xmpp",
    #                        host=data[0],
    #                        access_key=data[1],
    #                        password=data[2])
    print(await gateway.custom_test())
    # await gateway.initialize()
    # return
    # print(f"UUID {await gateway.check_connection()}")

    # small = await gateway.smallscan(DHW_CIRCUITS)
    #        myjson = json.loads(small)
    # print(small)
    # return
    sensors = gateway.initialize_sensors()
    for sensor in sensors:
        await sensor.update()
    for sensor in sensors:
        print(f"{sensor.name} : {sensor.state}")
    await gateway.get_capabilities()
    for hc in gateway.heating_circuits:
        await hc.update()
        print("hvac mode", hc.ha_mode)
        print("target temp ->", hc.target_temperature)
    return

    #        await hc.set_ha_mode("auto") #MEANS AUTO
    #       await hc.update()
    # time.sleep(4)
    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 loop.close()