@@ -593,6 +593,7 @@ async def update_method(self):
593593 shedding_event ["refresh_date" ] = datetime .strptime (
594594 shedding_event ["refresh_date" ], "%Y-%m-%dT%H:%M:%S%z"
595595 )
596+ data ["address" ] = { "street" : street , "insee_code" : city_code }
596597 return data
597598 except Exception as err :
598599 raise UpdateFailed (f"Error communicating with API: { err } " )
@@ -728,3 +729,43 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
728729 hass .config_entries .async_update_entry (config_entry , data = new )
729730 _LOGGER .info (f"Migration to version { config_entry .version } successful" )
730731 return True
732+
733+ class DetectedAddress (CoordinatorEntity , RestorableCoordinatedSensor ):
734+ """Exposes the address detected from GPS coordinate and sent to Enedis"""
735+
736+ def __init__ (
737+ self , coordinator : EnedisAPICoordinator , hass : HomeAssistant
738+ ):
739+ super ().__init__ (coordinator )
740+ self ._restored = False
741+ self .hass = hass
742+ self ._attr_extra_state_attributes : Dict [str , Any ] = {}
743+ self ._attr_name = "Detected address"
744+ self ._state = None
745+ self ._attr_entity_category = EntityCategory .DIAGNOSTIC
746+
747+ @callback
748+ def _handle_coordinator_update (self ) -> None :
749+ if not self .coordinator .last_update_success :
750+ _LOGGER .debug ("Last coordinator failed, assuming state has not changed" )
751+ return
752+ data = self .coordinator .data ['address' ]
753+ self ._state = f"{ data ['street' ]} { data ['insee_code' ]} "
754+ self .async_write_ha_state ()
755+
756+ @property
757+ def state (self ) -> Optional [str ]:
758+ return self ._state
759+
760+ @property
761+ def native_value (self ):
762+ return self ._state
763+
764+ @property
765+ def device_info (self ):
766+ # technically the sensor should belong to a French Governement entity
767+ return {"identifiers" : {(DOMAIN , "enedis" )}, "name" : "Enedis" }
768+
769+ @property
770+ def unique_id (self ) -> str :
771+ return f"enedis-sent-address"
0 commit comments