Skip to content

Commit

Permalink
Feature/run pre commit (#86)
Browse files Browse the repository at this point in the history
* bump pyonwater

* bump pyonwater

* gosh

* Fix import service issues

* bump pyonwater

* run pre-commit
  • Loading branch information
kdeyev authored Jan 27, 2024
1 parent 12328af commit 1fdb9db
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions custom_components/eyeonwater/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING, Any

import pyonwater
from homeassistant import exceptions
from homeassistant.components.recorder.statistics import async_import_statistics
from homeassistant.components.sensor import (
SensorDeviceClass,
Expand Down Expand Up @@ -56,12 +57,15 @@ async def async_setup_entry(
last_imported_time=last_imported_time,
),
)
#sensors.append(EyeOnWaterSensor(meter, coordinator))
sensors.append(EyeOnWaterTempSensor(meter, coordinator))

async_add_entities(sensors, update_before_add=False)


class NoDataFound(exceptions.HomeAssistantError):
"""Error to indicate there is no data."""


class EyeOnWaterStatistic(CoordinatorEntity, SensorEntity):
"""Representation of an EyeOnWater sensor."""

Expand Down Expand Up @@ -117,17 +121,19 @@ def _state_update(self):
self._state = self.meter.reading

if not self.meter.last_historical_data:
raise Exception("Meter doesn't have recent readings")

msg = "Meter doesn't have recent readings"
raise NoDataFound(msg)

self._last_historical_data = filter_newer_data(
self.meter.last_historical_data,
self._last_imported_time,
)
if self._last_historical_data:
self.import_historical_data()
if not self.meter._last_historical_data:
raise Exception("No historical data loaded")

msg = "No historical data loaded"
raise NoDataFound(msg)

self._last_imported_time = self._last_historical_data[-1].dt

self.async_write_ha_state()
Expand Down Expand Up @@ -190,6 +196,7 @@ def native_value(self) -> float | None:

class EyeOnWaterSensor(CoordinatorEntity, SensorEntity):
"""Representation of an EyeOnWater sensor."""

# Leaving this class in-place for now in case we need it in the future

_attr_has_entity_name = True
Expand Down

0 comments on commit 1fdb9db

Please sign in to comment.