Skip to content

Commit

Permalink
[#27] In a Github workflow, run unit tests against a HA container
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Senart committed Jan 12, 2025
1 parent 01ac6ca commit 9b693d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion gazpar2haws/gazpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ async def _find_last_date_days_value(
if exists_statistic_id:
# Get the last statistic from Home Assistant
try:
last_statistic = await self._homeassistant.get_last_statistic(entity_id, self._as_of_date, self._last_days)
last_statistic = await self._homeassistant.get_last_statistic(
entity_id, self._as_of_date, self._last_days
)
except HomeAssistantWSException:
Logger.warning(
f"Error while fetching last statistics from Home Assistant: {traceback.format_exc()}"
Expand Down
4 changes: 3 additions & 1 deletion gazpar2haws/haws.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ async def statistics_during_period(
return response

# ----------------------------------
async def get_last_statistic(self, entity_id: str, as_of_date: datetime, depth_days: int) -> dict:
async def get_last_statistic(
self, entity_id: str, as_of_date: datetime, depth_days: int
) -> dict:

Logger.debug(f"Getting last statistic for {entity_id}...")

Expand Down
8 changes: 6 additions & 2 deletions tests/test_haws.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ async def test_get_last_statistic(self):

await self._haws.connect()

statistics = await self._haws.get_last_statistic("sensor.gazpar2haws_volume", datetime.now(), 30)
statistics = await self._haws.get_last_statistic(
"sensor.gazpar2haws_volume", datetime.now(), 30
)

assert statistics is not None

Expand Down Expand Up @@ -109,6 +111,8 @@ async def test_clear_statistics(self):

await self._haws.connect()

await self._haws.clear_statistics(["sensor.gazpar2haws_energy", "sensor.gazpar2haws_volume"])
await self._haws.clear_statistics(
["sensor.gazpar2haws_energy", "sensor.gazpar2haws_volume"]
)

await self._haws.disconnect()

0 comments on commit 9b693d0

Please # to comment.