Skip to content

Commit

Permalink
Refactor alarm_info, add as function in client for easy access.
Browse files Browse the repository at this point in the history
  • Loading branch information
RenierM26 committed Apr 30, 2022
1 parent bba75c9 commit 01775f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyhyypapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""init hyyp api exceptions."""
from .client import HyypClient
from .alarm_info import HyypAlarmInfos
from .client import HyypClient
from .constants import GCF_SENDER_ID, HyypPkg
from .exceptions import HTTPError, HyypApiError, InvalidURL
from .push_receiver import run_example
Expand Down
16 changes: 12 additions & 4 deletions pyhyypapi/alarm_info.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
"""Alarm info for hass integration"""
from __future__ import annotations

import datetime
from typing import TYPE_CHECKING, Any

from .client import HyypClient
if TYPE_CHECKING:
from .client import HyypClient


class HyypAlarmInfos:
"""Initialize Hyyp alarm objects."""

def __init__(self, client: HyypClient) -> None:
self._client = client
self._sync_info: dict = {}
self._state_info: dict = {}

def _fetch_data(self) -> None:
"""Fetch data via client api."""
self._sync_info = self._client.get_sync_info()
self._state_info = self._client.get_state_info()

def format_data(self) -> dict[Any, Any]:
def _format_data(self) -> dict[Any, Any]:
"""Format data for Hass."""

# The API returns data from site level, need to invert.
Expand Down Expand Up @@ -83,4 +88,7 @@ def format_data(self) -> dict[Any, Any]:
def status(self) -> dict[Any, Any]:
"""Returns the status of Hyyp connected alarms."""

return {}
self._fetch_data()
formatted_data: dict[Any, Any] = self._format_data()

return formatted_data
6 changes: 6 additions & 0 deletions pyhyypapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .constants import DEFAULT_TIMEOUT, REQUEST_HEADER, STD_PARAMS, HyypPkg
from .exceptions import HTTPError, HyypApiError, InvalidURL
from .alarm_info import HyypAlarmInfos

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -130,6 +131,11 @@ def check_app_version(self) -> dict[Any, Any]:

return _json_result

def load_alarm_infos(self) -> dict[Any, Any]:
"""Get alarm infos formatted for hass infos."""

return HyypAlarmInfos(self).status()

def site_notifications(
self, site_id: int = None, timestamp: int = None, json_key: str = None
) -> dict[Any, Any]:
Expand Down

0 comments on commit 01775f2

Please sign in to comment.