Skip to content

Commit

Permalink
Use attr_xxx fields instead of properties (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
tetienne authored Aug 24, 2021
1 parent 3400b1e commit 915355a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
18 changes: 3 additions & 15 deletions custom_components/veolia/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ def __init__(self, coordinator, config_entry):
"""Initialize the entity."""
super().__init__(coordinator)
self.config_entry = config_entry

@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{self.config_entry.entry_id}_{self.name}"
self._attr_unique_id = f"{self.config_entry.entry_id}_{self.name}"
self._attr_unit_of_measurement = VOLUME_LITERS
self._attr_icon = "mdi:water"

@property
def device_info(self):
Expand All @@ -33,13 +31,3 @@ def device_state_attributes(self):
return {
"last_report": self.coordinator.data[LAST_REPORT_TIMESTAMP],
}

@property
def icon(self) -> str:
"""Return the usage icon."""
return "mdi:water"

@property
def unit_of_measurement(self) -> str:
"""Return liter as the unit measurement for water."""
return VOLUME_LITERS
15 changes: 3 additions & 12 deletions custom_components/veolia/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ async def async_setup_entry(hass, entry, async_add_devices):
class VeoliaHourlyUsageSensor(VeoliaEntity):
"""Monitors the hourly water usage."""

@property
def name(self):
"""Return the name of the sensor."""
return "veolia_hourly_consumption"
_attr_name = "veolia_hourly_consumption"

@property
def state(self):
Expand All @@ -37,10 +34,7 @@ def state(self):
class VeoliaDailyUsageSensor(VeoliaEntity):
"""Monitors the daily water usage."""

@property
def name(self):
"""Return the name of the sensor."""
return "veolia_daily_consumption"
_attr_name = "veolia_daily_consumption"

@property
def state(self):
Expand All @@ -56,10 +50,7 @@ def state(self):
class VeoliaMonthlyUsageSensor(VeoliaEntity):
"""Monitors the monthly water usage."""

@property
def name(self):
"""Return the name of the sensor."""
return "veolia_monthly_consumption"
_attr_name = "veolia_monthly_consumption"

@property
def state(self):
Expand Down

0 comments on commit 915355a

Please sign in to comment.