Skip to content

Commit

Permalink
#11, add option to allow extra fulldetail attribute with product deta…
Browse files Browse the repository at this point in the history
…ils json
  • Loading branch information
myTselection committed Jan 15, 2024
1 parent 778a3c0 commit 24bdd90
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

</details>

Expand Down
5 changes: 5 additions & 0 deletions custom_components/myenergy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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

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": "2.3.1"
"version": "2.4.0"
}
16 changes: 11 additions & 5 deletions custom_components/myenergy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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',"")
Expand Down Expand Up @@ -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"
}


Expand Down
9 changes: 6 additions & 3 deletions custom_components/myenergy/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}

Expand Down Expand Up @@ -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"
}
}
},
Expand Down
20 changes: 20 additions & 0 deletions custom_components/myenergy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 24bdd90

Please sign in to comment.