Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change in HA2024.10.x #382

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions custom_components/foxess_em/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"""

import asyncio
import copy
from datetime import time
import logging


from homeassistant.config_entries import ConfigEntry, ConfigEntryAuthFailed
from homeassistant.const import (
MAJOR_VERSION as HA_MAJOR_VERSION,
Expand Down Expand Up @@ -77,36 +79,45 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

# Check FoxESS API Key before settings up the other platforms to prevent those being setup if it
# fails, which will prevent setup working when the FoxESS API key is fixed.
if len(entry.options) > 0:
entry_options = copy.deepcopy(dict(entry.options))
entry_data = copy.deepcopy(dict(entry.data))
_LOGGER.debug(f"Options {entry.options}")
_LOGGER.debug(f"Data {entry.data}")
FozzieUK marked this conversation as resolved.
Show resolved Hide resolved

if entry_options != entry_data:
FozzieUK marked this conversation as resolved.
Show resolved Hide resolved
# overwrite data with options
entry.data = entry.options
entry_data = copy.deepcopy(dict(entry.options))
_LOGGER.info("Config has been updated")
_LOGGER.debug(f"_Data {entry_data}")


connection_type = entry.data.get(CONNECTION_TYPE, FOX_MODBUS_TCP)
fox_api_key = entry.data.get(FOX_API_KEY)
connection_type = entry_data.get(CONNECTION_TYPE, FOX_MODBUS_TCP)
fox_api_key = entry_data.get(FOX_API_KEY)
if connection_type == FOX_CLOUD:
if not fox_api_key:
raise ConfigEntryAuthFailed(
"FoxESSCloud must now be accessed vi API Keys. Please reconfigure."
)

solcast_api_key = entry.data.get(SOLCAST_API_KEY)

eco_start_time = time.fromisoformat(entry.data.get(ECO_START_TIME))
eco_end_time = time.fromisoformat(entry.data.get(ECO_END_TIME))
house_power = entry.data.get(HOUSE_POWER)
battery_soc = entry.data.get(BATTERY_SOC)
aux_power = entry.data.get(AUX_POWER)
user_min_soc = entry.data.get(MIN_SOC)
capacity = entry.data.get(BATTERY_CAPACITY)
dawn_buffer = entry.data.get(DAWN_BUFFER)
day_buffer = entry.data.get(DAY_BUFFER)

solcast_api_key = entry_data.get(SOLCAST_API_KEY)

eco_start_time = time.fromisoformat(entry_data.get(ECO_START_TIME))
eco_end_time = time.fromisoformat(entry_data.get(ECO_END_TIME))
house_power = entry_data.get(HOUSE_POWER)
battery_soc = entry_data.get(BATTERY_SOC)
aux_power = entry_data.get(AUX_POWER)
user_min_soc = entry_data.get(MIN_SOC)
capacity = entry_data.get(BATTERY_CAPACITY)
dawn_buffer = entry_data.get(DAWN_BUFFER)
day_buffer = entry_data.get(DAY_BUFFER)
# Added for 1.6.1
charge_amps = entry.data.get(CHARGE_AMPS, 18)
battery_volts = entry.data.get(BATTERY_VOLTS, 208)
charge_amps = entry_data.get(CHARGE_AMPS, 18)
battery_volts = entry_data.get(BATTERY_VOLTS, 208)
# Added for 1.7.0
fox_modbus_host = entry.data.get(FOX_MODBUS_HOST, "")
fox_modbus_port = entry.data.get(FOX_MODBUS_PORT, 502)
fox_modbus_slave = entry.data.get(FOX_MODBUS_SLAVE, 247)
fox_modbus_host = entry_data.get(FOX_MODBUS_HOST, "")
fox_modbus_port = entry_data.get(FOX_MODBUS_PORT, 502)
fox_modbus_slave = entry_data.get(FOX_MODBUS_SLAVE, 247)

session = async_get_clientsession(hass)
solcast_client = SolcastApiClient(solcast_api_key, SOLCAST_URL, session)
Expand Down Expand Up @@ -207,7 +218,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
)

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True


Expand Down
Loading