Use WATER device class in streamlabswater (#83654)

pull/83666/head
epenet 2022-12-09 16:20:35 +01:00 committed by GitHub
parent 55b996f5db
commit a1758a71d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 15 deletions

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from datetime import timedelta
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.const import VOLUME_GALLONS
from homeassistant.const import UnitOfVolume
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -80,7 +80,8 @@ class StreamlabsUsageData:
class StreamLabsDailyUsage(SensorEntity):
"""Monitors the daily water usage."""
_attr_device_class = SensorDeviceClass.VOLUME
_attr_device_class = SensorDeviceClass.WATER
_attr_native_unit_of_measurement = UnitOfVolume.GALLONS
def __init__(self, location_name, streamlabs_usage_data):
"""Initialize the daily water usage device."""
@ -89,25 +90,15 @@ class StreamLabsDailyUsage(SensorEntity):
self._state = None
@property
def name(self):
def name(self) -> str:
"""Return the name for daily usage."""
return f"{self._location_name} {NAME_DAILY_USAGE}"
@property
def icon(self):
"""Return the daily usage icon."""
return WATER_ICON
@property
def native_value(self):
"""Return the current daily usage."""
return self._streamlabs_usage_data.get_daily_usage()
@property
def native_unit_of_measurement(self):
"""Return gallons as the unit measurement for water."""
return VOLUME_GALLONS
def update(self) -> None:
"""Retrieve the latest daily usage."""
self._streamlabs_usage_data.update()
@ -117,7 +108,7 @@ class StreamLabsMonthlyUsage(StreamLabsDailyUsage):
"""Monitors the monthly water usage."""
@property
def name(self):
def name(self) -> str:
"""Return the name for monthly usage."""
return f"{self._location_name} {NAME_MONTHLY_USAGE}"
@ -131,7 +122,7 @@ class StreamLabsYearlyUsage(StreamLabsDailyUsage):
"""Monitors the yearly water usage."""
@property
def name(self):
def name(self) -> str:
"""Return the name for yearly usage."""
return f"{self._location_name} {NAME_YEARLY_USAGE}"