Skip to content

Commit

Permalink
extra setup options + fix config update (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Sep 26, 2023
1 parent ac92faf commit ef95a66
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
15 changes: 15 additions & 0 deletions custom_components/MyEnergy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def create_schema(entry, option=False):
default_day_electricity_consumption = entry.data.get("day_electricity_consumption", 0)
default_night_electricity_consumption = entry.data.get("night_electricity_consumption", 0)
default_excl_night_electricity_consumption = entry.data.get("excl_night_electricity_consumption", 0)
default_solar_panels = entry.data.get("solar_panels", False)
default_inverter_power = entry.data.get("inverter_power", 0)
default_electricity_injection = entry.data.get("electricity_injection", 0)
default_electricity_injection_night = entry.data.get("electricity_injection_night", 0)
default_gas_consumption = entry.data.get("gas_consumption", "")
default_directdebit_invoice = entry.data.get("directdebit_invoice", False)
default_email_invoice = entry.data.get("email_invoice", False)
Expand All @@ -47,7 +50,10 @@ def create_schema(entry, option=False):
default_day_electricity_consumption = 0
default_night_electricity_consumption = 0
default_excl_night_electricity_consumption = 0
default_solar_panels = False
default_inverter_power = 0
default_electricity_injection = 0
default_electricity_injection_night = 0
default_gas_consumption = 0
default_directdebit_invoice = True
default_email_invoice = True
Expand All @@ -71,9 +77,18 @@ def create_schema(entry, option=False):
data_schema[
vol.Optional("excl_night_electricity_consumption", default=default_excl_night_electricity_consumption, description="excl_night_electricity_consumption")
] = int
data_schema[
vol.Required("solar_panels", default=default_solar_panels, description="solar_panels")
] = bool
data_schema[
vol.Optional("electricity_injection", default=default_electricity_injection, description="electricity_injection")
] = int
data_schema[
vol.Optional("electricity_injection_night", default=default_electricity_injection_night, description="electricity_injection_night")
] = int
data_schema[
vol.Optional("inverter_power", default=default_inverter_power, description="inverter_power")
] = int
data_schema[
vol.Required("electric_car", default=default_electric_car, description="electric_car")
] = bool
Expand Down
2 changes: 1 addition & 1 deletion custom_components/MyEnergy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/myTselection/MyEnergy/issues",
"requirements": ["bs4","requests"],
"version": "1.0.1"
"version": "1.1.0"
}
4 changes: 2 additions & 2 deletions custom_components/MyEnergy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def __init__(self, config, hass):

@property
def unique_id(self):
return f"{DOMAIN}-{self._postalcode}-{self._day_electricity_consumption}-{self._night_electricity_consumption}-{self._gas_consumption}"
return f"{DOMAIN}-{self._postalcode}"

# same as update, but without throttle to make sure init is always executed
async def _forced_update(self):
Expand Down Expand Up @@ -247,7 +247,7 @@ def icon(self) -> str:
@property
def unique_id(self) -> str:
"""Return the unique ID of the sensor."""
return f"{self._data.unique_id}-{self._postalcode}-{self._fuel_type.fullnameEN}-{self._contract_type.fullname}"
return f"{self._data.unique_id}-{self._fuel_type.fullnameEN}-{self._contract_type.fullname}"

@property
def name(self) -> str:
Expand Down
15 changes: 12 additions & 3 deletions custom_components/MyEnergy/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
"postalcode": "Belgian postalcode",
"electricity_digital_counter": "Digital electricity counter",
"day_electricity_consumption": "Average electricity consumption per year daytime (kWh)",
"night_electricity_consumption": "Average electricity consumption per year nighttime (kWh)",
"night_electricity_consumption": "Average electricity consumption per year nighttime and weekend (kWh)",
"excl_night_electricity_consumption": "Average electricity consumption per year exclusive nighttime (kWh)",
"solar_panels": "Solar panels",
"electricity_injection": "Electricty injection (kWh)",
"electricity_injection_night": "Electricty injection night and weekend (kWh)",
"inverter_power": "What is the total power of the inverter(s) of your installation?",
"electricity_provider": "Select your current electricty provider",
"electric_car": "Electrical car",
"gas_consumption": "Average gas consumption per year (kWh)",
Expand All @@ -27,9 +30,12 @@
"postalcode": "Belgian postalcode",
"electricity_digital_counter": "Digital electricity counter",
"day_electricity_consumption": "Average electricity consumption per year daytime (kWh)",
"night_electricity_consumption": "Average electricity consumption per year nighttime (kWh)",
"night_electricity_consumption": "Average electricity consumption per year nighttime and weekend (kWh)",
"excl_night_electricity_consumption": "Average electricity consumption per year exclusive nighttime (kWh)",
"solar_panels": "Solar panels",
"electricity_injection": "Electricty injection (kWh)",
"electricity_injection_night": "Electricty injection night and weekend (kWh)",
"inverter_power": "What is the total power of the inverter(s) of your installation?",
"electricity_provider": "Select your current electricty provider",
"electric_car": "Electrical car",
"gas_consumption": "Average gas consumption per year (kWh)",
Expand All @@ -55,9 +61,12 @@
"postalcode": "Belgian postalcode",
"electricity_digital_counter": "Digital electricity counter",
"day_electricity_consumption": "Average electricity consumption per year daytime (kWh)",
"night_electricity_consumption": "Average electricity consumption per year nighttime (kWh)",
"night_electricity_consumption": "Average electricity consumption per year nighttime and weekend (kWh)",
"excl_night_electricity_consumption": "Average electricity consumption per year exclusive nighttime (kWh)",
"solar_panels": "Solar panels",
"electricity_injection": "Electricty injection (kWh)",
"electricity_injection_night": "Electricty injection night and weekend (kWh)",
"inverter_power": "What is the total power of the inverter(s) of your installation?",
"electricity_provider": "Select your current electricty provider",
"electric_car": "Electrical car",
"gas_consumption": "Average gas consumption per year (kWh)",
Expand Down
28 changes: 16 additions & 12 deletions custom_components/MyEnergy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,33 @@ def __init__(self):

def get_data(self, config, contract_type: ContractType):
postalcode = config.get("postalcode")
electricity_digital_counter = config.get("electricity_digital_counter")
electricity_digital_counter = config.get("electricity_digital_counter", False)
electricity_digital_counter_n = 1 if electricity_digital_counter == True else 0
day_electricity_consumption = config.get("day_electricity_consumption",0)
night_electricity_consumption = config.get("night_electricity_consumption", 0)
excl_night_electricity_consumption = config.get("excl_night_electricity_consumption", 0)

solar_panels = config.get("solar_panels", False)
solar_panels_n = 1 if solar_panels == True else 0
electricity_injection = config.get("electricity_injection", 0)
electricity_injection_night = config.get("electricity_injection_night", 0)

combine_elec_and_gas = config.get("combine_elec_and_gas", False)
inverter_power = config.get("inverter_power", 0)
inverter_power = str(inverter_power).replace(',','%2C').replace('.','%2C')

combine_elec_and_gas = config.get("combine_elec_and_gas", False)
combine_elec_and_gas_n = 1 if combine_elec_and_gas == True else 0

gas_consumption = config.get("gas_consumption", 0)

directdebit_invoice = config.get("directdebit_invoice", True)
directdebit_invoice_n = 1 if directdebit_invoice == True else 0
email_invoice = config.get("email_invoice", True)
email_invoice_n = 1 if email_invoice == True else 0
online_support = config.get("online_support", True)
online_support_n = 1 if online_support == True else 0
electric_car = config.get("electric_car", False)
electric_car_n = 1 if electric_car == True else 0

electricity_comp = day_electricity_consumption != 0 or night_electricity_consumption != 0 or excl_night_electricity_consumption != 0
gas_comp = gas_consumption != 0
Expand All @@ -88,16 +101,7 @@ def get_data(self, config, contract_type: ContractType):
if excl_night_electricity_consumption !=0:
elec_level += 1

directdebit_invoice_n = 1 if directdebit_invoice == True else 0
email_invoice_n = 1 if email_invoice == True else 0
online_support_n = 1 if online_support == True else 0
electricity_digital_counter_n = 1 if electricity_digital_counter == True else 0
electric_car_n = 1 if electric_car == True else 0
electricity_injection_n = 1 if electricity_injection == True else 0

combine_elec_and_gas_n = 1 if combine_elec_and_gas == True else 0

myenergy_url = f"https://www.mijnenergie.be/energie-vergelijken-3-resultaten-?Form=fe&e={comp}&d={electricity_digital_counter_n}&c=particulier&cp={postalcode}&i2={elec_level}----{day_electricity_consumption}-{night_electricity_consumption}-{excl_night_electricity_consumption}-1----{gas_consumption}----1-{directdebit_invoice_n}%7C{email_invoice_n}%7C{online_support_n}%7C1-{electricity_injection_n}%7C%7C%7C%7C0%21{contract_type.code}%21A%21n%7C0%21{contract_type.code}%21A%7C{combine_elec_and_gas_n}%7C%7C%7C%7C%7C%7C%21%7C%7C%7C%7C-{electric_car_n}%7C0-0"
myenergy_url = f"https://www.mijnenergie.be/energie-vergelijken-3-resultaten-?Form=fe&e={comp}&d={electricity_digital_counter_n}&c=particulier&cp={postalcode}&i2={elec_level}----{day_electricity_consumption}-{night_electricity_consumption}-{excl_night_electricity_consumption}-1----{gas_consumption}----1-{directdebit_invoice_n}%7C{email_invoice_n}%7C{online_support_n}%7C1-{electricity_injection}%7C{electricity_injection_night}%7C{solar_panels_n}%7C%7C0%21{contract_type.code}%21A%21n%7C0%21{contract_type.code}%21A%7C{combine_elec_and_gas_n}%7C{inverter_power}%7C%7C%7C%7C%7C%21%7C%7C{inverter_power}%7C%7C{electric_car_n}-0%7C0-0"

_LOGGER.debug(f"myenergy_url: {myenergy_url}")
response = self.s.get(myenergy_url,timeout=30,allow_redirects=True)
Expand Down

0 comments on commit ef95a66

Please sign in to comment.