Skip to content

Commit

Permalink
Bump solarlog_cli to 0.2.2 (#124948)
Browse files Browse the repository at this point in the history
* Add inverter-devices

* Minor code adjustments

* Update manifest.json

Seperate dependency upgrade to seperate PR

* Update requirements_all.txt

Seperate dependency upgrade to seperate PR

* Update requirements_test_all.txt

Seperate dependency upgrade to seperate PR

* Update homeassistant/components/solarlog/sensor.py

Co-authored-by: Joost Lekkerkerker <[email protected]>

* Split up base class, document SolarLogSensorEntityDescription

* Split up sensor types

* Update snapshot

* Bump solarlog_cli to 0.2.1

* Add strict typing

* Bump fyta_cli to 0.6.3 (#124574)

* Ensure write access to hassrelease data folder (#124573)

Co-authored-by: Robert Resch <[email protected]>

* Update a roborock blocking call to be fully async (#124266)

Remove a blocking call in roborock

* Add inverter-devices

* Split up sensor types

* Update snapshot

* Bump solarlog_cli to 0.2.1

* Backport/rebase

* Tidy up

* Simplyfication coordinator.py

* Minor adjustments

* Ruff

* Bump solarlog_cli to 0.2.2

* Update homeassistant/components/solarlog/sensor.py

Co-authored-by: Joost Lekkerkerker <[email protected]>

* Update homeassistant/components/solarlog/config_flow.py

Co-authored-by: Joost Lekkerkerker <[email protected]>

* Update homeassistant/components/solarlog/sensor.py

Co-authored-by: Joost Lekkerkerker <[email protected]>

* Update persentage-values in fixture

---------

Co-authored-by: Joost Lekkerkerker <[email protected]>
Co-authored-by: Paulus Schoutsen <[email protected]>
Co-authored-by: Robert Resch <[email protected]>
Co-authored-by: Allen Porter <[email protected]>
  • Loading branch information
5 people authored Sep 1, 2024
1 parent 68162e1 commit 1661304
Show file tree
Hide file tree
Showing 13 changed files with 350 additions and 125 deletions.
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ homeassistant.components.slack.*
homeassistant.components.sleepiq.*
homeassistant.components.smhi.*
homeassistant.components.snooz.*
homeassistant.components.solarlog.*
homeassistant.components.sonarr.*
homeassistant.components.speedtestdotnet.*
homeassistant.components.sql.*
Expand Down
23 changes: 9 additions & 14 deletions homeassistant/components/solarlog/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@callback
def solarlog_entries(hass: HomeAssistant):
def solarlog_entries(hass: HomeAssistant) -> set[str]:
"""Return the hosts already configured."""
return {
entry.data[CONF_HOST] for entry in hass.config_entries.async_entries(DOMAIN)
Expand All @@ -36,7 +36,7 @@ def __init__(self) -> None:
"""Initialize the config flow."""
self._errors: dict = {}

def _host_in_configuration_exists(self, host) -> bool:
def _host_in_configuration_exists(self, host: str) -> bool:
"""Return True if host exists in configuration."""
if host in solarlog_entries(self.hass):
return True
Expand All @@ -50,7 +50,7 @@ def _parse_url(self, host: str) -> str:
url = ParseResult("http", netloc, path, *url[3:])
return url.geturl()

async def _test_connection(self, host):
async def _test_connection(self, host: str) -> bool:
"""Check if we can connect to the Solar-Log device."""
solarlog = SolarLogConnector(host)
try:
Expand All @@ -66,11 +66,12 @@ async def _test_connection(self, host):

return True

async def async_step_user(self, user_input=None) -> ConfigFlowResult:
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Step when user initializes a integration."""
self._errors = {}
if user_input is not None:
# set some defaults in case we need to return to the form
user_input[CONF_NAME] = slugify(user_input[CONF_NAME])
user_input[CONF_HOST] = self._parse_url(user_input[CONF_HOST])

Expand All @@ -81,20 +82,14 @@ async def async_step_user(self, user_input=None) -> ConfigFlowResult:
title=user_input[CONF_NAME], data=user_input
)
else:
user_input = {}
user_input[CONF_NAME] = DEFAULT_NAME
user_input[CONF_HOST] = DEFAULT_HOST
user_input = {CONF_NAME: DEFAULT_NAME, CONF_HOST: DEFAULT_HOST}

return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(
CONF_NAME, default=user_input.get(CONF_NAME, DEFAULT_NAME)
): str,
vol.Required(
CONF_HOST, default=user_input.get(CONF_HOST, DEFAULT_HOST)
): str,
vol.Required(CONF_NAME, default=user_input[CONF_NAME]): str,
vol.Required(CONF_HOST, default=user_input[CONF_HOST]): str,
vol.Required("extended_data", default=False): bool,
}
),
Expand Down
19 changes: 10 additions & 9 deletions homeassistant/components/solarlog/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
SolarLogConnectionError,
SolarLogUpdateError,
)
from solarlog_cli.solarlog_models import SolarlogData

from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import update_coordinator
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

_LOGGER = logging.getLogger(__name__)

if TYPE_CHECKING:
from . import SolarlogConfigEntry


class SolarLogCoordinator(update_coordinator.DataUpdateCoordinator):
class SolarLogCoordinator(DataUpdateCoordinator[SolarlogData]):
"""Get and update the latest data."""

def __init__(self, hass: HomeAssistant, entry: SolarlogConfigEntry) -> None:
Expand All @@ -43,29 +44,29 @@ def __init__(self, hass: HomeAssistant, entry: SolarlogConfigEntry) -> None:
self.name = entry.title
self.host = url.geturl()

extended_data = entry.data["extended_data"]

self.solarlog = SolarLogConnector(
self.host, extended_data, hass.config.time_zone
self.host, entry.data["extended_data"], hass.config.time_zone
)

async def _async_setup(self) -> None:
"""Do initialization logic."""
if self.solarlog.extended_data:
device_list = await self.solarlog.client.get_device_list()
device_list = await self.solarlog.update_device_list()
self.solarlog.set_enabled_devices({key: True for key in device_list})

async def _async_update_data(self):
async def _async_update_data(self) -> SolarlogData:
"""Update the data from the SolarLog device."""
_LOGGER.debug("Start data update")

try:
data = await self.solarlog.update_data()
await self.solarlog.update_device_list()
if self.solarlog.extended_data:
await self.solarlog.update_device_list()
data.inverter_data = await self.solarlog.update_inverter_data()
except SolarLogConnectionError as err:
raise ConfigEntryNotReady(err) from err
except SolarLogUpdateError as err:
raise update_coordinator.UpdateFailed(err) from err
raise UpdateFailed(err) from err

_LOGGER.debug("Data successfully updated")

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/solarlog/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/solarlog",
"iot_class": "local_polling",
"loggers": ["solarlog_cli"],
"requirements": ["solarlog_cli==0.1.6"]
"requirements": ["solarlog_cli==0.2.2"]
}
Loading

0 comments on commit 1661304

Please sign in to comment.