hif2k1 / battery_sim

Home assistant home battery simulator - allows you to model how much energy you would save with a home battery
106 stars 13 forks source link

Updated the config flow to set Second Import and Export #86

Closed Daandamhuis closed 10 months ago

Daandamhuis commented 10 months ago

Related to: https://github.com/hif2k1/battery_sim/issues/83

Outline

So I saw there were some issues with using the second export and import. I've altered the configuration flow, and the mainly the __init__.py. All the other edits where mainly some checks with Flake8 and unused objects.

To-do

This is the configuration flow file.

if self._data[METER_TYPE] == TWO_IMPORT_TWO_EXPORT_METER:
    self._data[CONF_SECOND_IMPORT_SENSOR] = user_input[CONF_SECOND_IMPORT_SENSOR]
    self._data[CONF_SECOND_EXPORT_SENSOR] = user_input[CONF_SECOND_EXPORT_SENSOR]
{
   "size_kwh":9.3,
   "max_discharge_rate_kw":5.0,
   "max_charge_rate_kw":3.3,
   "efficiency":0.95,
   "setup_type":"config_flow",
   "name":"battery_sim: LG Chem",
   "type_of_energy_meter":"two_import_two_export",
   "tariff_type":"No tariff information",
   "import_sensor":"sensor.energy_consumption_tarif_1",
   "export_sensor":"sensor.energy_production_tarif_1",
   "second_import_sensor":"sensor.energy_consumption_tarif_2",
   "second_export_sensor":"sensor.energy_production_tarif_2"
}
2023-08-11 23:07:02.358 DEBUG (MainThread) [custom_components.battery_sim] <battery_sim: LG Chem> monitoring sensor.energy_consumption_tarif_1
2023-08-11 23:07:02.358 DEBUG (MainThread) [custom_components.battery_sim] <battery_sim: LG Chem> monitoring sensor.energy_consumption_tarif_2
2023-08-11 23:07:02.358 DEBUG (MainThread) [custom_components.battery_sim] <battery_sim: LG Chem> monitoring sensor.energy_production_tarif_1
2023-08-11 23:07:02.358 DEBUG (MainThread) [custom_components.battery_sim] <battery_sim: LG Chem> monitoring sensor.energy_production_tarif_2
hif2k1 commented 10 months ago

Thanks so much for your work on this. It looks good. Because you've put so many changes/commits in one request it's going to take me a bit of time to work through it, but hopefully can merge it shortly.

hif2k1 commented 10 months ago

Can we not rename the battery_mode_now sensor. I can see why you did it for consistency, but it would be a breaking change. For anyone who has this setup already and might be using it to trigger something else it won't work any more. Thanks

Daandamhuis commented 10 months ago

Can we not rename the battery_mode_now sensor. I can see why you did it for consistency, but it would be a breaking change. For anyone who has this setup already and might be using it to trigger something else it won't work any more. Thanks

I've changed it back :)

Daandamhuis commented 10 months ago

Thanks so much for your work on this. It looks good. Because you've put so many changes/commits in one request it's going to take me a bit of time to work through it, but hopefully can merge it shortly.

I'm still looking through the code if I can make some optimizations, but for now it seems to be ok. I'm a bit hesitant to check for the kWh or Wh unit on each update. Can Image that it won't change after initializing the battery.

Also I want to check creating 1 collection list instead of 4 different variables.

hif2k1 commented 10 months ago

Thanks again for your work on this. I'm pretty new to python and never knew about list comprehension so I'm learning. Just a couple of areas highlighted above that need resolving. Hope that's ok. Thanks.

Daandamhuis commented 10 months ago

Hi !

I've altered it based on your suggestions. I'm still getting used to the Home Assistant way of doing this, so that will come.

Good luck.