bosch-thermostat / bosch-thermostat-client-python

Python3 asyncio package to talk to Bosch thermostat devices.
Apache License 2.0
23 stars 20 forks source link

new feature: specifiy --path multiple times #32

Closed OlliL closed 1 year ago

OlliL commented 1 year ago

Add the possibility to specify --path multiple times.

I am interested in 11 different parameters of my CT200. Right now I have to execute 3 rawscans to retrieve all possible data (basically everything but not recordings which takes awfully long to retrieve) - but all I need are those 11 parameters - all the other read out parameters are discarded.

It would be much better if there would be a way only requesting the parameters I need.

With that change it can now be achived by specifying all the path of interest.

Thats why I enhanced the parameters to allow multiple specification of the path parameter. For example:

olli@patna bosch-thermostat-client-python> python3.11 bosch_thermostat_client/bosch_cli.py query --host <retracted> --token <retracted> --password <retracted> --protocol HTTP --device IVT --path /system/sensors/temperatures/supply_t1 --path /heatingCircuits/hc1/roomtemperature --path /system/sensors/temperatures/outdoor_t1
2023-04-16 00:02:36 INFO (MainThread) [__main__] Connecting to <retracted> with 'HTTP'
2023-04-16 00:02:36 INFO (MainThread) [bosch_thermostat_client.gateway.base] Scanning /system/sensors/temperatures/supply_t1
2023-04-16 00:02:36 INFO (MainThread) [bosch_thermostat_client.gateway.base] Scanning /heatingCircuits/hc1/roomtemperature
2023-04-16 00:02:36 INFO (MainThread) [bosch_thermostat_client.gateway.base] Scanning /system/sensors/temperatures/outdoor_t1
[
    {
        "id": "/system/sensors/temperatures/supply_t1",
        "recordable": 0,
        "state": [
            {
                "open": -3276.8
            },
            {
                "short": 3276.7
            }
        ],
        "type": "floatValue",
        "unitOfMeasure": "C",
        "value": 24.4,
        "writeable": 0
    },
    {
        "id": "/heatingCircuits/hc1/roomtemperature",
        "recordable": 1,
        "state": [
            {
                "open": -3276.8
            },
            {
                "short": 3276.7
            }
        ],
        "type": "floatValue",
        "unitOfMeasure": "C",
        "value": 21.2,
        "writeable": 0
    },
    {
        "id": "/system/sensors/temperatures/outdoor_t1",
        "recordable": 1,
        "state": [
            {
                "open": -3276.8
            },
            {
                "short": 3276.7
            }
        ],
        "type": "floatValue",
        "unitOfMeasure": "C",
        "value": 6.4,
        "writeable": 0
    }
]
olli@patna bosch-thermostat-client-python>
pszafer commented 1 year ago

Did you check if it is still working with Home Assistant with those changes?

OlliL commented 1 year ago

Unfortunally I have no working homeassistant setup, so I did not check it ~~- but I wonder why it shouldn't work as all it does is adding the possibility to specify --path multiple times - you can still specify it only one time if you like. So it is 100% backward compatible i'd say. But yes - the log messages changed a bit of course - does HA work with those log messages? If thats the case I can make it have the same log output as before with one path argument, and the changed log output only when --path was specified multiple times.~~

OlliL commented 1 year ago

I must correct my previous message - the return value as well as the argument to raw_query changed.

To make it compatible, custom_components/bosch/__init__.py has to be adjusted:

old:

    async def custom_get(self, path) -> str:
        """Fetch value from gateway."""
        async with self._update_lock:
            return await self.gateway.raw_query(path=path)

new:

    async def custom_get(self, path) -> str:
        """Fetch value from gateway."""
        async with self._update_lock:
            result = await self.gateway.raw_query(path=[path])
            return result[0] if result else None

I could also create a new raw_query_multiple method, use that in bosch_cli and turn back raw_query to what it was before. Another option could be to not touch the library at all and just call raw_query multiple times from inside bosch_cli.

Please tell me your opinion :smile:

OlliL commented 1 year ago

I've just submitted #35 which implements the version of calling raw_query multiple times from inside bosch_cli instead of breaking the API. This might be the best solution imho :smile:

OlliL commented 1 year ago

lets close this as #35 got merged with the same functionallity but w/o any API break