rianadon / the-energy-detective-py

Unofficial library for reading from The Energy Detective power meters
0 stars 3 forks source link

Initial brute force attempt to get something on paper #10

Closed realumhelp closed 2 years ago

realumhelp commented 2 years ago

Fixes #9 - Simple attempt (ugly) at pulling the extra data for advanced system types /w generative capabilities. Hard to know the system's behavior without having all the necessary pieces in place for testing.

realumhelp commented 2 years ago

If you wanted to be a bit smarter you could probably pull the queries like this, however you'd have to make sure you don't call total_gen or total_load methods if you system type is NET. Seems like a good chunk of work when you could just call the queries and get empty values back.

    async def update(self) -> None:
        """Fetch settings and power data from the endpoints."""
        await asyncio.gather(
            self._update_endpoint("endpoint_settings_results", ENDPOINT_URL_SETTINGS),
        )

        self._parse_mtus()
        self._parse_spyders()

        adv_system_type_queries = []
        if self.system_type != TED6000.SystemType.NET:
            """Only do these extra queries if advanced system type."""
            adv_system_type_queries.extend(
                [
                    self._update_endpoint(
                        "endpoint_solardash_results", ENDPOINT_URL_DASHBOARD, 1
                    ),
                    self._update_endpoint(
                        "endpoint_solardash_results", ENDPOINT_URL_DASHBOARD, 2
                    ),
                ]
            )
        """Fetch MTU/Spyder data results"""
        await asyncio.gather(
            self._update_endpoint("endpoint_mtu_results", ENDPOINT_URL_MTU),
            self._update_endpoint("endpoint_spyder_results", ENDPOINT_URL_SPYDER),
            self._update_endpoint(
                "endpoint_dashboard_results", ENDPOINT_URL_DASHBOARD, 0
            ),
            *adv_system_type_queries,
            *map(
                lambda mtu: self._update_endpoint(
                    "endpoint_dashboard_results",
                    ENDPOINT_URL_MTUDASHBOARD,
                    mtu.position,
                ),
                self.mtus,
            )
        )