Skip to content

Commit

Permalink
add code for the uuid normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeyev committed Jun 8, 2024
1 parent 8b9f9eb commit c99d330
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions custom_components/eyeonwater/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ def __init__(
translation_key=description.translation_key,
)
self.meter = meter
chars = [c if c.isalnum() or c == "_" else "_" for c in meter.meter_uuid]
self._uuid = "".join(chars)
self._state = False
self._available = False
self._attr_unique_id = f"{description.key}_{self.meter.meter_uuid}"
self._attr_unique_id = f"{description.key}_{self._uuid}"
self._attr_is_on = self._state
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.meter.meter_uuid)},
identifiers={(DOMAIN, self._uuid)},
name=f"{WATER_METER_NAME} {self.meter.meter_id}",
model=self.meter.meter_info.reading.model,
manufacturer=self.meter.meter_info.reading.customer_name,
Expand Down
15 changes: 9 additions & 6 deletions custom_components/eyeonwater/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def __init__(

self._attr_name = f"{WATER_METER_NAME} {self.meter.meter_id} Statistic"
self._attr_device_class = SensorDeviceClass.WATER
self._attr_unique_id = f"{self.meter.meter_uuid}_statistic"
self._attr_unique_id = f"{self._uuid}_statistic"
self._attr_native_unit_of_measurement = get_ha_native_unit_of_measurement(
meter.native_unit_of_measurement,
)
self._attr_suggested_display_precision = 0
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.meter.meter_uuid)},
identifiers={(DOMAIN, self._uuid)},
name=f"{WATER_METER_NAME} {self.meter.meter_id}",
model=self.meter.meter_info.reading.model,
manufacturer=self.meter.meter_info.reading.customer_name,
Expand Down Expand Up @@ -172,9 +172,12 @@ def __init__(
"""Initialize the sensor."""
super().__init__(coordinator)
self.meter = meter
self._attr_unique_id = f"{self.meter.meter_uuid}_temperature"
chars = [c if c.isalnum() or c == "_" else "_" for c in meter.meter_uuid]
self._uuid = "".join(chars)

self._attr_unique_id = f"{self._uuid}_temperature"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.meter.meter_uuid)},
identifiers={(DOMAIN, self._uuid)},
name=f"{WATER_METER_NAME} {self.meter.meter_id}",
model=self.meter.meter_info.reading.model,
manufacturer=self.meter.meter_info.reading.customer_name,
Expand Down Expand Up @@ -207,13 +210,13 @@ def __init__(
self._state: pyonwater.DataPoint | None = None
self._available = False

self._attr_unique_id = meter.meter_uuid
self._attr_unique_id = self._uuid
self._attr_native_unit_of_measurement = get_ha_native_unit_of_measurement(
meter.native_unit_of_measurement,
)
self._attr_suggested_display_precision = 0
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.meter.meter_uuid)},
identifiers={(DOMAIN, self._uuid)},
name=f"{WATER_METER_NAME} {self.meter.meter_id}",
model=self.meter.meter_info.reading.model,
manufacturer=self.meter.meter_info.reading.customer_name,
Expand Down

0 comments on commit c99d330

Please sign in to comment.