diff --git a/README.md b/README.md index f0617ba..5ff89fa 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Device `MyEnergy` should become available with the following sensors: | Promo | Promo (provider dependent promotion, part of subscription cost) of the cheapest subscription for which a match was found | | Total price per year | Total price per year of the cheapest subscription for which a match was found | | Total kWh per year | Total kWh per year on wich the lookup is based (total combination of day/night/... consumptions) | + | fulldetail | If configuration option to add product and price detail json is enabled, all site data will be added as a json to enable fetching extra contract specific data | diff --git a/custom_components/myenergy/config_flow.py b/custom_components/myenergy/config_flow.py index 66599be..84abb13 100644 --- a/custom_components/myenergy/config_flow.py +++ b/custom_components/myenergy/config_flow.py @@ -47,6 +47,7 @@ def create_schema(entry, option=False): default_combine_elec_and_gas = entry.data.get("combine_elec_and_gas", False) default_electricity_provider = entry.data.get("electricity_provider", "No provider") default_gas_provider = entry.data.get("gas_provider", "No provider") + default_add_details = entry.data.get("add_details", False) else: default_postalcode = "" default_electricity_digital_counter = False @@ -65,6 +66,7 @@ def create_schema(entry, option=False): default_combine_elec_and_gas = False default_electricity_provider = "No provider" default_gas_provider = "No provider" + default_add_details = False # _LOGGER.debug(f'provider_names: {provider_names}') data_schema = OrderedDict() @@ -129,6 +131,9 @@ def create_schema(entry, option=False): data_schema[ vol.Required("online_support", default=default_online_support, description="online_support") ] = bool + data_schema[ + vol.Required("add_details", default=default_add_details, description="add_details") + ] = bool return data_schema diff --git a/custom_components/myenergy/manifest.json b/custom_components/myenergy/manifest.json index 25b8c8e..48021e4 100644 --- a/custom_components/myenergy/manifest.json +++ b/custom_components/myenergy/manifest.json @@ -9,5 +9,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/myTselection/MyEnergy/issues", "requirements": ["bs4","requests"], - "version": "2.3.1" + "version": "2.4.0" } diff --git a/custom_components/myenergy/sensor.py b/custom_components/myenergy/sensor.py index 59c5255..b1ade84 100644 --- a/custom_components/myenergy/sensor.py +++ b/custom_components/myenergy/sensor.py @@ -36,6 +36,7 @@ vol.Required("directdebit_invoice"): cv.boolean, vol.Required("email_invoice"): cv.boolean, vol.Required("online_support"): cv.boolean, + vol.Required("add_details"): cv.boolean, vol.Required("electric_car"): cv.boolean, vol.Required("combine_elec_and_gas"): cv.boolean, vol.Required("electricity_digital_counter"): cv.boolean, @@ -143,6 +144,7 @@ def __init__(self, config, hass): self._directdebit_invoice = config.get("directdebit_invoice", True) self._email_invoice = config.get("email_invoice", True) self._online_support = config.get("online_support", True) + self._add_details = config.get("add_details", False) self._details = {} self._last_update = None self._refresh_required = True @@ -202,6 +204,7 @@ def __init__(self, data, postalcode, fuel_type: FuelType, contract_type: Contrac self._priceyear = None self._kWhyear = None self._fuel_type = fuel_type + self._fueltype_detail = None self._contract_type = contract_type self._postalcode = postalcode self._providerdetails = None @@ -212,6 +215,7 @@ def __init__(self, data, postalcode, fuel_type: FuelType, contract_type: Contrac self._netrate = None self._promo = None self._name = f"{NAME} {self._postalcode}" + self._add_details = data._add_details @property def state(self): @@ -220,7 +224,8 @@ def state(self): async def async_update(self): await self._data.update() - self._details = self._data._details + self._details = self._data._details + self._add_details = self._data._add_details self._last_update = self._data._last_update self._name = f"{NAME} {self._postalcode} {self._fuel_type.fullnameEN} {self._contract_type.fullname}" self._contract_type_details = self._details.get(self._contract_type.code) @@ -230,9 +235,9 @@ async def async_update(self): return for fueltype_name in self._contract_type_details.keys(): if self._fuel_type.fullnameNL in fueltype_name: - fueltype_detail = self._contract_type_details.get(fueltype_name) - _LOGGER.debug(f"fueltype_detail: {self._contract_type} - {fueltype_name} - {fueltype_detail}") - self._providerdetails = fueltype_detail[0] + self._fueltype_detail = self._contract_type_details.get(fueltype_name) + _LOGGER.debug(f"fueltype_detail: {self._contract_type} - {fueltype_name} - {self._fueltype_detail}") + self._providerdetails = self._fueltype_detail[0] self._url = self._providerdetails.get('url',"") self._providername = self._providerdetails.get('provider',"") self._contractname = self._providerdetails.get('name',"") @@ -291,7 +296,8 @@ def extra_state_attributes(self) -> dict: "netrate": self._netrate, "promo": self._promo, "total price per year": self._priceyear, - "total kWh per year": self._kWhyear + "total kWh per year": self._kWhyear, + "fulldetail": self._fueltype_detail if self._add_details else "details disabled in config" } diff --git a/custom_components/myenergy/translations/en.json b/custom_components/myenergy/translations/en.json index 3cc279e..af32f1e 100644 --- a/custom_components/myenergy/translations/en.json +++ b/custom_components/myenergy/translations/en.json @@ -21,7 +21,8 @@ "gas_provider": "Select your current gas provider", "directdebit_invoice": "Mandatory payment of invoice by direct debit", "email_invoice": "Send invoice only via e-mail", - "online_support": "Customer service access only via email/internet" + "online_support": "Customer service access only via email/internet", + "add_details": "Add extended product and price details as json" } }, "edit": { @@ -43,7 +44,8 @@ "gas_provider": "Select your current gas provider", "directdebit_invoice": "Mandatory payment of invoice by direct debit", "email_invoice": "Send invoice only via e-mail", - "online_support": "Customer service access only via email/internet" + "online_support": "Customer service access only via email/internet", + "add_details": "Add extended product and price details as json" } } @@ -74,7 +76,8 @@ "gas_provider": "Select your current gas provider", "directdebit_invoice": "Mandatory payment of invoice by direct debit", "email_invoice": "Send invoice only via e-mail", - "online_support": "Customer service access only via email/internet" + "online_support": "Customer service access only via email/internet", + "add_details": "Add extended product and price details as json" } } }, diff --git a/custom_components/myenergy/utils.py b/custom_components/myenergy/utils.py index b57a9de..3d25c3d 100644 --- a/custom_components/myenergy/utils.py +++ b/custom_components/myenergy/utils.py @@ -212,6 +212,26 @@ def get_data(self, config, contract_type: ContractType): # "email_invoice": True, # "online_support": True, # "electric_car": False} + + +# config = {"postalcode": "1190", +# "electricity_digital_counter": True, +# "day_electricity_consumption":960, +# "night_electricity_consumption": 1400, +# "excl_night_electricity_consumption": 0, +# "solar_panels": False, "electricity_injection": 0, +# "electricity_injection_night": 0, +# "electricity_provider": "No provider", +# "inverter_power": 0, +# "combine_elec_and_gas": False, +# "gas_consumption": 17000, +# "gas_provider": "No provider", +# "directdebit_invoice": True, +# "email_invoice": True, +# "online_support": True, +# "electric_car": False} + + # # print(session.get_data(config, ContractType.FIXED)) # print(session.get_data(config, ContractType.VARIABLE))