Skip to content

Comments

add detection of tado generation#143

Open
karlbeecken wants to merge 5 commits intoerwindouna:mainfrom
karlbeecken:tadox
Open

add detection of tado generation#143
karlbeecken wants to merge 5 commits intoerwindouna:mainfrom
karlbeecken:tadox

Conversation

@karlbeecken
Copy link

Proposed Changes

implements basic detection if the home is a V3 or X home, including tests and a new get_home function

Related Issues

part of #136

@erwindouna erwindouna added the enhancement Enhancement of the code, not introducing new features label Feb 18, 2026
@karlbeecken
Copy link
Author

My main question would be how we want to handle the slight differences between the V3 and X API going forward. Here I did something like this:

 async def get_home(self) -> Home:
        """Get the home."""
        response = await self._request(f"homes/{self._home_id}")
        obj = orjson.loads(response)

        # For Tado X, enrich the home payload from hops.tado.com.
        # The X payload provides roomCount, which maps to zonesCount in our model.
        if obj.get("generation") == TadoLine.LINE_X.value:
            try:
                x_response = await self._request(
                    f"homes/{self._home_id}",
                    endpoint=TADO_X_URL,
                )
                x_obj = orjson.loads(x_response)

                if "roomCount" in x_obj:
                    obj["zonesCount"] = x_obj["roomCount"]
                if "isHeatPumpInstalled" in x_obj:
                    obj["isHeatPumpInstalled"] = x_obj["isHeatPumpInstalled"]
                if "supportsFlowTemperatureOptimization" in x_obj:
                    obj["supportsFlowTemperatureOptimization"] = x_obj[
                        "supportsFlowTemperatureOptimization"
                    ]
            except TadoError as err:
                _LOGGER.debug(
                    "Failed to enrich Tado X home data from hops endpoint: %s",
                    err,
                )

        return Home.from_dict(obj)

But I am not sure if that is the optimal way, as I feel it could add a lot of boilerplate. Any thoughts on this?

@wmalgadey
Copy link
Collaborator

@karlbeecken maybe integrate the latest changes from main into your branch, so the workflows should work again

@karlbeecken
Copy link
Author

@wmalgadey done, I think someone with write access needs to approve the CI run

Comment on lines +398 to +418
if obj.get("generation") == TadoLine.LINE_X.value:
try:
x_response = await self._request(
f"homes/{self._home_id}",
endpoint=TADO_X_URL,
)
x_obj = orjson.loads(x_response)

if "roomCount" in x_obj:
obj["zonesCount"] = x_obj["roomCount"]
if "isHeatPumpInstalled" in x_obj:
obj["isHeatPumpInstalled"] = x_obj["isHeatPumpInstalled"]
if "supportsFlowTemperatureOptimization" in x_obj:
obj["supportsFlowTemperatureOptimization"] = x_obj[
"supportsFlowTemperatureOptimization"
]
except TadoError as err:
_LOGGER.debug(
"Failed to enrich Tado X home data from hops endpoint: %s",
err,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on one hand it will create a lot of extra code for every method and for every change in the api. I am naturally more a fan of abstraction here, but adding the complete overhead we added in PyTado seems also not the right way to solve it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we put this "enricher" code into its own class and then call only an "EnricherFactory" within it, which would then call the actual enricher class based on the "generation" and simply modify the current object?

Then the code is separated, we can call the enricher wherever we need it, and we don't clutter up our methods so much!

Could be a main enricher we create on first contact, because this "generation" won't change for the complete api of this home!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement of the code, not introducing new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants