Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use utc #26

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/sensus_analytics/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "sensus_analytics",
"name": "Sensus Analytics Integration",
"version": "1.4.2",
"version": "1.4.3",
"documentation": "https://github.com/zestysoft/sensus_analytics_integration",
"dependencies": [],
"codeowners": ["@zestysoft"],
Expand Down
72 changes: 15 additions & 57 deletions custom_components/sensus_analytics/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,70 +107,46 @@ def native_value(self):
return self._convert_usage(daily_usage)


class SensusAnalyticsUsageUnitSensor(CoordinatorEntity, SensorEntity):
class SensusAnalyticsUsageUnitSensor(StaticUnitSensorBase):
"""Representation of the usage unit sensor."""

def __init__(self, coordinator, entry):
"""Initialize the usage unit sensor."""
super().__init__(coordinator)
self.coordinator = coordinator
self.entry = entry
self._unique_id = f"{DOMAIN}_{entry.entry_id}_usage_unit"
super().__init__(coordinator, entry, unit=None)
self._attr_name = f"{DEFAULT_NAME} Native Usage Unit"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, entry.entry_id)},
name=DEFAULT_NAME,
manufacturer="Unknown",
model="Water Meter",
)
self._attr_unique_id = f"{self._unique_id}_usage_unit"

@property
def native_value(self):
"""Return the state of the sensor."""
return self.coordinator.data.get("usageUnit")


class SensusAnalyticsMeterAddressSensor(CoordinatorEntity, SensorEntity):
class SensusAnalyticsMeterAddressSensor(StaticUnitSensorBase):
"""Representation of the meter address sensor."""

def __init__(self, coordinator, entry):
"""Initialize the meter address sensor."""
super().__init__(coordinator)
self.coordinator = coordinator
self.entry = entry
self._unique_id = f"{DOMAIN}_{entry.entry_id}_meter_address"
super().__init__(coordinator, entry, unit=None)
self._attr_name = f"{DEFAULT_NAME} Meter Address"
self._attr_unique_id = f"{self._unique_id}_meter_address"
self._attr_icon = "mdi:map-marker"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, entry.entry_id)},
name=DEFAULT_NAME,
manufacturer="Unknown",
model="Water Meter",
)

@property
def native_value(self):
"""Return the state of the sensor."""
return self.coordinator.data.get("meterAddress1")


class SensusAnalyticsLastReadSensor(CoordinatorEntity, SensorEntity):
class SensusAnalyticsLastReadSensor(StaticUnitSensorBase):
"""Representation of the last read timestamp sensor."""

def __init__(self, coordinator, entry):
"""Initialize the last read sensor."""
super().__init__(coordinator)
self.coordinator = coordinator
self.entry = entry
self._unique_id = f"{DOMAIN}_{entry.entry_id}_last_read"
super().__init__(coordinator, entry, unit="UTC")
self._attr_name = f"{DEFAULT_NAME} Last Read"
self._attr_unique_id = f"{self._unique_id}_last_read"
self._attr_icon = "mdi:clock-time-nine"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, entry.entry_id)},
name=DEFAULT_NAME,
manufacturer="Unknown",
model="Water Meter",
)

@property
def native_value(self):
Expand Down Expand Up @@ -198,23 +174,15 @@ def native_value(self):
return self.coordinator.data.get("meterLong")


class SensusAnalyticsMeterIdSensor(CoordinatorEntity, SensorEntity):
class SensusAnalyticsMeterIdSensor(StaticUnitSensorBase):
"""Representation of the meter ID sensor."""

def __init__(self, coordinator, entry):
"""Initialize the meter ID sensor."""
super().__init__(coordinator)
self.coordinator = coordinator
self.entry = entry
self._unique_id = f"{DOMAIN}_{entry.entry_id}_meter_id"
super().__init__(coordinator, entry, unit=None)
self._attr_name = f"{DEFAULT_NAME} Meter ID"
self._attr_unique_id = f"{self._unique_id}_meter_id"
self._attr_icon = "mdi:account"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, entry.entry_id)},
name=DEFAULT_NAME,
manufacturer="Unknown",
model="Water Meter",
)

@property
def native_value(self):
Expand Down Expand Up @@ -255,23 +223,15 @@ def native_value(self):
return self._convert_usage(latest_read_usage)


class SensusAnalyticsLatestReadTimeSensor(CoordinatorEntity, SensorEntity):
class SensusAnalyticsLatestReadTimeSensor(StaticUnitSensorBase):
"""Representation of the latest read time sensor."""

def __init__(self, coordinator, entry):
"""Initialize the latest read time sensor."""
super().__init__(coordinator)
self.coordinator = coordinator
self.entry = entry
self._unique_id = f"{DOMAIN}_{entry.entry_id}_latest_read_time"
super().__init__(coordinator, entry, unit="UTC")
self._attr_name = f"{DEFAULT_NAME} Latest Read Time"
self._attr_unique_id = f"{self._unique_id}_latest_read_time"
self._attr_icon = "mdi:clock-time-nine"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, entry.entry_id)},
name=DEFAULT_NAME,
manufacturer="Unknown",
model="Water Meter",
)

@property
def native_value(self):
Expand Down Expand Up @@ -321,7 +281,6 @@ def native_value(self):

def _convert_usage(self, usage):
"""Convert usage based on the configuration and native unit."""
# Use the same conversion logic as in DynamicUnitSensorBase
if usage is None:
return None
usage_unit = self.coordinator.data.get("usageUnit")
Expand Down Expand Up @@ -373,7 +332,6 @@ def native_value(self):

def _convert_usage(self, usage):
"""Convert usage based on the configuration and native unit."""
# Use the same conversion logic as in DynamicUnitSensorBase
if usage is None:
return None
usage_unit = self.coordinator.data.get("usageUnit")
Expand Down
Loading