Skip to content

Commit a2157f8

Browse files
authored
Add raw attributes to address sensor (#15)
1 parent 6313a42 commit a2157f8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Creates sensors that have details (time zone, address, etc.) about another entit
44

55
Type | Description
66
-|-
7-
address | The address where the entity is located
7+
address | The address where the entity is located. See also [Address Sensor](#address-sensor).
88
country | The country the entity is in. Includes a `country_code` attribute.
99
different country | Is `on` when the country where entity is located is different than Home Assistant's country configuration
1010
different time | Is `on` when the local time where entity is located is different than Home Assistant's local time
@@ -15,6 +15,14 @@ All entities are disabled by default,
1515
exept for the "local time" sensor, which is enabled by default for static time zones and zone entities,
1616
and the "time zone" sensor, which is enabled by default for all other entities.
1717

18+
### Address Sensor
19+
The address sensor's state will typically be a "combined" address string, containing house number, road, etc.
20+
It will also have attributes for each of the address "details".
21+
The list of possible attributes is documented [here](https://nominatim.org/release-docs/develop/api/Output/#addressdetails).
22+
The exact set of attributes can change over time.
23+
Do not count on any particular attribute always being present.
24+
E.g., in templates, always check for the attribute's presence, or provide a `|default()` filter.
25+
1826
## Installation
1927
### With HACS
2028
[![hacs_badge](https://img.shields.io/badge/HACS-Custom-41BDF5.svg)](https://hacs.xyz/)

custom_components/entity_tz/sensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ def __init__(self, entry: ConfigEntry) -> None:
4141

4242
async def async_update(self) -> None:
4343
"""Update sensor."""
44+
self._attr_extra_state_attributes = {}
4445
if not self._sources_valid:
4546
return
4647

4748
self._attr_native_value = self._entity_loc.address
49+
for attr, value in self._entity_loc.raw["address"].items():
50+
self._attr_extra_state_attributes[attr] = value
4851

4952

5053
class EntityCountrySensor(ETZEntity, SensorEntity):

0 commit comments

Comments
 (0)