diff --git a/custom_components/ev_smart_charging/const.py b/custom_components/ev_smart_charging/const.py index 9371107..56dec2a 100644 --- a/custom_components/ev_smart_charging/const.py +++ b/custom_components/ev_smart_charging/const.py @@ -30,6 +30,7 @@ PLATFORM_NORDPOOL = "nordpool" PLATFORM_ENERGIDATASERVICE = "energidataservice" PLATFORM_ENTSOE = "entsoe" +PLATFORM_TGE = "tge" PLATFORM_VW = "volkswagen_we_connect_id" PLATFORM_OCPP = "ocpp" PLATFORM_GENERIC = "generic" diff --git a/custom_components/ev_smart_charging/helpers/config_flow.py b/custom_components/ev_smart_charging/helpers/config_flow.py index 56c4ac0..d13926c 100644 --- a/custom_components/ev_smart_charging/helpers/config_flow.py +++ b/custom_components/ev_smart_charging/helpers/config_flow.py @@ -26,6 +26,7 @@ PLATFORM_ENTSOE, PLATFORM_GENERIC, PLATFORM_NORDPOOL, + PLATFORM_TGE, PLATFORM_OCPP, PLATFORM_VW, SWITCH, @@ -131,6 +132,8 @@ def find_price_sensor(hass: HomeAssistant) -> str: sensor = FindEntity.find_energidataservice_sensor(hass) if len(sensor) == 0: sensor = FindEntity.find_entsoe_sensor(hass) + if len(sensor) == 0: + sensor = FindEntity.find_tge_sensor(hass) return sensor @staticmethod @@ -185,6 +188,21 @@ def find_generic_sensor(hass: HomeAssistant) -> str: return entity_id return "" + @staticmethod + def find_tge_sensor(hass: HomeAssistant) -> str: + """Search for TGE sensor""" + entity_registry: EntityRegistry = async_entity_registry_get(hass) + registry_entries: UserDict[str, RegistryEntry] = ( + entity_registry.entities.items() + ) + for entry in registry_entries: + if entry[1].platform == PLATFORM_TGE: + entity_id = entry[1].entity_id + attributes = hass.states.get(entity_id).attributes + if all(attr in attributes for attr in ["prices", "prices_today", "prices_tomorrow"]): + return entity_id + return "" + @staticmethod def find_vw_soc_sensor(hass: HomeAssistant) -> str: """Search for Volkswagen SOC sensor""" diff --git a/custom_components/ev_smart_charging/helpers/coordinator.py b/custom_components/ev_smart_charging/helpers/coordinator.py index 89d2cd4..9384fb9 100644 --- a/custom_components/ev_smart_charging/helpers/coordinator.py +++ b/custom_components/ev_smart_charging/helpers/coordinator.py @@ -10,6 +10,7 @@ from custom_components.ev_smart_charging.const import ( PLATFORM_ENERGIDATASERVICE, PLATFORM_ENTSOE, + PLATFORM_TGE, PLATFORM_GENERIC, PLATFORM_NORDPOOL, READY_HOUR_NONE, @@ -59,7 +60,7 @@ def convert_raw_item( # "price": float, # } # {'time': '2023-03-06 00:00:00+01:00', 'price': 0.1306} time is not datetime - if platform == PLATFORM_ENTSOE: + if platform in (PLATFORM_ENTSOE, PLATFORM_TGE): if item["price"] is not None and isinstance(item["time"], str): item_new = {} item_new["value"] = item["price"] diff --git a/custom_components/ev_smart_charging/helpers/price_adaptor.py b/custom_components/ev_smart_charging/helpers/price_adaptor.py index 43c5100..3686557 100644 --- a/custom_components/ev_smart_charging/helpers/price_adaptor.py +++ b/custom_components/ev_smart_charging/helpers/price_adaptor.py @@ -11,6 +11,7 @@ CONF_PRICE_SENSOR, PLATFORM_ENERGIDATASERVICE, PLATFORM_ENTSOE, + PLATFORM_TGE, PLATFORM_GENERIC, PLATFORM_NORDPOOL, ) @@ -65,7 +66,7 @@ def get_raw_today_local(self, state) -> Raw: if self._price_platform in (PLATFORM_NORDPOOL, PLATFORM_ENERGIDATASERVICE): return Raw(state.attributes["raw_today"], self._price_platform) - if self._price_platform in (PLATFORM_ENTSOE, PLATFORM_GENERIC): + if self._price_platform in (PLATFORM_ENTSOE, PLATFORM_TGE, PLATFORM_GENERIC): return Raw(state.attributes["prices_today"], self._price_platform) return Raw([]) @@ -76,7 +77,7 @@ def get_raw_tomorrow_local(self, state) -> Raw: if self._price_platform in (PLATFORM_NORDPOOL, PLATFORM_ENERGIDATASERVICE): return Raw(state.attributes["raw_tomorrow"], self._price_platform) - if self._price_platform in (PLATFORM_ENTSOE, PLATFORM_GENERIC): + if self._price_platform in (PLATFORM_ENTSOE, PLATFORM_TGE, PLATFORM_GENERIC): return Raw(state.attributes["prices_tomorrow"], self._price_platform) return Raw([]) @@ -87,7 +88,7 @@ def get_current_price(self, state) -> float: if self._price_platform in (PLATFORM_NORDPOOL, PLATFORM_ENERGIDATASERVICE): return state.attributes["current_price"] - if self._price_platform in (PLATFORM_ENTSOE, PLATFORM_GENERIC): + if self._price_platform in (PLATFORM_ENTSOE, PLATFORM_TGE, PLATFORM_GENERIC): time_now = dt.now() return self.get_raw_today_local(state).get_value(time_now) @@ -117,7 +118,7 @@ def validate_price_entity( _LOGGER.debug("No attribute raw_tomorrow in price sensor") return ("base", "sensor_is_not_price") - if price_platform in (PLATFORM_ENTSOE, PLATFORM_GENERIC): + if price_platform in (PLATFORM_ENTSOE, PLATFORM_TGE, PLATFORM_GENERIC): if not "prices_today" in price_state.attributes.keys(): _LOGGER.debug("No attribute prices today in price sensor") return ("base", "sensor_is_not_price")