Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanU committed May 23, 2024
1 parent d00395f commit 7117521
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions custom_components/talent_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import asyncio
import json
import logging

from custom_components.talent_monitor.coordinator import (
Expand Down Expand Up @@ -38,6 +39,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

await coordinator.async_config_entry_first_refresh()

_LOGGER.debug("received data %s", json.dumps(coordinator.data))

hass.data[DOMAIN][entry.entry_id] = coordinator

for platform in PLATFORMS:
Expand Down
14 changes: 9 additions & 5 deletions custom_components/talent_monitor/pyTalentMonitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ async def login(self):
response_data = await response.json()
if "token" in response_data:
self.token = response_data["token"]
logging.debug("Login successful - received token: %s", self.token)
_LOGGER.debug("Login successful - received token: %s", self.token)
else:
logging.error("Login failed. Got status code %s", response.status)
_LOGGER.error("Login failed. Got status code %s", response.status)
raise AuthenticationError("Authentication failed")

async def refresh_token(self):
"""Refresh the token."""
logging.debug("Token expired. Refreshing token...")
_LOGGER.debug("Token expired. Refreshing token...")
self.login()

async def get_data(self, endpoint):
Expand All @@ -76,7 +76,7 @@ async def get_data(self, endpoint):
if response.status == 200:
return await response.json()
else:
logging.error("Failed to fetch data. Status Code: %s", response.status)
_LOGGER.error("Failed to fetch data. Status Code: %s", response.status)
return None

async def fetch_solar_data(self):
Expand All @@ -90,11 +90,13 @@ async def fetch_solar_data(self):
status = first_station["status"]
stationName = first_station["stationName"]
powerStationGuid = first_station["powerStationGuid"]
logging.debug("GUID: %s", powerStationGuid)
_LOGGER.debug("GUID: %s", powerStationGuid)

data = await self.get_data(
endpoint=f"system/station/getPowerStationByGuid?powerStationGuid={powerStationGuid}&timezone={TIMEZONE}"
)
_LOGGER.debug("Data for powerstation GUID %s: %s", powerStationGuid, json.dumps(data))

if data:
power_data = data["data"]
totalActivePower = power_data["totalActivePower"]
Expand All @@ -109,6 +111,8 @@ async def fetch_solar_data(self):
data = await self.get_data(
endpoint=f"tools/device/selectDeviceInverterInfo?deviceGuid={deviceGuid}"
)

_LOGGER.debug("Data for inverter GUID %s: %s", deviceGuid, json.dumps(data))
if data:
pv = data["data"]["pv"]
pv1Voltage = pv[0]["voltage"]
Expand Down

0 comments on commit 7117521

Please sign in to comment.