Skip to content

Commit

Permalink
Added sensor unique_id
Browse files Browse the repository at this point in the history
Sensor became unavailable when Min Renovasjon changed the name of the fraction.
  • Loading branch information
eyesoft committed Sep 30, 2022
1 parent 0d56664 commit 5b75a5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/min_renovasjon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"ssdp": [],
"zeroconf": [],
"homekit": {},
"version": "0.0.5",
"version": "2.1.0",
"iot_class": "cloud_polling"
}
9 changes: 5 additions & 4 deletions custom_components/min_renovasjon/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, min_renovasjon, fraction_id, calendar_list):
self._fraction_id = int(fraction_id)
self._available = True
self._attributes = {}
self._attr_unique_id = self.get_name()

@property
def should_poll(self):
Expand Down Expand Up @@ -79,15 +78,17 @@ def extra_state_attributes(self):
@property
def name(self):
"""Return the name."""
return self.get_name()

def get_name(self):
if self._calendar_list is not None:
for fraction in self._calendar_list:
if int(fraction[0]) == self._fraction_id:
return fraction[1]
return None

@property
def unique_id(self) -> str:
"""Return unique ID."""
return "{0}_{1}".format(DOMAIN, self._fraction_id)

@property
def state(self):
"""Return the state/date of the fraction."""
Expand Down

0 comments on commit 5b75a5d

Please sign in to comment.