Skip to content

Commit

Permalink
fix: add ev sensors to config flow (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
woopstar authored Oct 18, 2024
1 parent 1455afa commit e7e1e9e
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 86 deletions.
85 changes: 85 additions & 0 deletions custom_components/hsem/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
DEFAULT_HSEM_SOLAR_PRODUCTION_POWER,
DEFAULT_HSEM_SOLCAST_PV_FORECAST_FORECAST_TODAY,
DEFAULT_HSEM_SOLCAST_PV_FORECAST_FORECAST_TOMORROW,
DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER,
DEFAULT_HSEM_EV_CHARGER_POWER,
DEFAULT_HSEM_BATTERY_CONVERSION_LOSS,
DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_MAXIMUM_CHARGING_POWER,
DOMAIN,
NAME,
)
Expand Down Expand Up @@ -120,8 +124,14 @@ async def async_step_huawei_solar(self, user_input=None):
self._errors["hsem_huawei_solar_inverter_active_power_control"] = (
"required"
)
elif not user_input.get("hsem_huawei_solar_batteries_maximum_charging_power"):
self._errors["hsem_huawei_solar_batteries_maximum_charging_power"] = (
"required"
)
elif not user_input.get("hsem_battery_max_capacity"):
self._errors["hsem_battery_max_capacity"] = "required"
elif not user_input.get("hsem_battery_conversion_loss"):
self._errors["hsem_battery_conversion_loss"] = "required"
else:
# Combine user inputs and create the entry
final_data = {**self._user_input, **user_input}
Expand Down Expand Up @@ -165,6 +175,10 @@ async def async_step_huawei_solar(self, user_input=None):
"hsem_huawei_solar_inverter_active_power_control",
default=DEFAULT_HSEM_HUAWEI_SOLAR_INVERTER_ACTIVE_POWER_CONTROL,
): selector({"entity": {"domain": "sensor"}}),
vol.Required(
"hsem_huawei_solar_batteries_maximum_charging_power",
default=DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_MAXIMUM_CHARGING_POWER,
): selector({"entity": {"domain": "number"}}),
vol.Required(
"hsem_battery_max_capacity",
default=DEFAULT_HSEM_BATTERY_MAX_CAPACITY,
Expand All @@ -179,6 +193,20 @@ async def async_step_huawei_solar(self, user_input=None):
}
}
),
vol.Required(
"hsem_battery_conversion_loss",
default=DEFAULT_HSEM_BATTERY_CONVERSION_LOSS,
): selector(
{
"number": {
"min": 0,
"max": 50,
"step": 1,
"unit_of_measurement": "%",
"mode": "slider",
}
}
),
}
)

Expand Down Expand Up @@ -298,6 +326,15 @@ async def async_step_misc(self, user_input=None):
"hsem_ev_charger_status",
default=DEFAULT_HSEM_EV_CHARGER_STATUS,
): selector({"entity": {"domain": "sensor"}}),
vol.Optional(
"hsem_ev_charger_power",
default=DEFAULT_HSEM_EV_CHARGER_POWER,
): selector({"entity": {"domain": "sensor"}}),
vol.Optional(
"hsem_house_power_includes_ev_charger_power",
default=DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER,
): selector({"boolean": {}}),

}
)

Expand Down Expand Up @@ -420,8 +457,18 @@ async def async_step_huawei_solar(self, user_input=None):
self._errors["hsem_huawei_solar_inverter_active_power_control"] = (
"required"
)
elif not user_input.get("hsem_huawei_solar_inverter_active_power_control"):
self._errors["hsem_huawei_solar_inverter_active_power_control"] = (
"required"
)
elif not user_input.get("hsem_huawei_solar_batteries_maximum_charging_power"):
self._errors["hsem_huawei_solar_batteries_maximum_charging_power"] = (
"required"
)
elif not user_input.get("hsem_battery_max_capacity"):
self._errors["hsem_battery_max_capacity"] = "required"
elif not user_input.get("hsem_battery_conversion_loss"):
self._errors["hsem_battery_conversion_loss"] = "required"
else:
# Combine user inputs and create the entry
final_data = {**self._user_input, **user_input}
Expand Down Expand Up @@ -473,6 +520,13 @@ async def async_step_huawei_solar(self, user_input=None):
DEFAULT_HSEM_HUAWEI_SOLAR_INVERTER_ACTIVE_POWER_CONTROL,
),
): selector({"entity": {"domain": "sensor"}}),
vol.Required(
"hsem_huawei_solar_batteries_maximum_charging_power",
default=self.config_entry.options.get(
"hsem_huawei_solar_batteries_maximum_charging_power",
DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_MAXIMUM_CHARGING_POWER,
),
): selector({"entity": {"domain": "number"}}),
vol.Required(
"hsem_battery_max_capacity",
default=self.config_entry.options.get(
Expand All @@ -490,6 +544,23 @@ async def async_step_huawei_solar(self, user_input=None):
}
}
),
vol.Required(
"hsem_battery_conversion_loss",
default=self.config_entry.options.get(
"hsem_battery_conversion_loss",
DEFAULT_HSEM_BATTERY_CONVERSION_LOSS,
),
): selector(
{
"number": {
"min": 0,
"max": 50,
"step": 1,
"unit_of_measurement": "%",
"mode": "slider",
}
}
),
}
)

Expand Down Expand Up @@ -618,6 +689,20 @@ async def async_step_misc(self, user_input=None):
DEFAULT_HSEM_EV_CHARGER_STATUS,
),
): selector({"entity": {"domain": "sensor"}}),
vol.Optional(
"hsem_ev_charger_power",
default=self.config_entry.options.get(
"hsem_ev_charger_power",
DEFAULT_HSEM_EV_CHARGER_POWER,
),
): selector({"entity": {"domain": "sensor"}}),
vol.Optional(
"hsem_house_power_includes_ev_charger_power",
default=self.config_entry.options.get(
"hsem_house_power_includes_ev_charger_power",
DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER,
),
): selector({"boolean": {}}),
}
)

Expand Down
12 changes: 12 additions & 0 deletions custom_components/hsem/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@
HOUSE_CONSUMPTION_ENERGY_WEIGHT_3D = 0.6 # 60% weight for the 3-day average
HOUSE_CONSUMPTION_ENERGY_WEIGHT_7D = 0.3 # 30% weight for the 7-day average
HOUSE_CONSUMPTION_ENERGY_WEIGHT_14D = 0.1 # 10% weight for the 14-day average

# Default for house power includes EV charger power
DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER = True

# Default sensor entity ID for EV charger power
DEFAULT_HSEM_EV_CHARGER_POWER = 'sensor.go_echarger_222819_nrg_12'

# Default conversion loss for battery charging
DEFAULT_HSEM_BATTERY_CONVERSION_LOSS = 10

# Default sensor entity ID for battery charging power
DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_MAXIMUM_CHARGING_POWER = 'number.battery_maximum_charging_power'
Loading

0 comments on commit e7e1e9e

Please sign in to comment.