Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to define unique_id in yaml #416

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions custom_components/nordpool/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
vol.Optional("price_type", default="kWh"): vol.In(list(_PRICE_IN.keys())),
vol.Optional("price_in_cents", default=False): cv.boolean,
vol.Optional("additional_costs", default=DEFAULT_TEMPLATE): cv.template,
vol.Optional("unique_id"): cv.string,
}
)

Expand All @@ -101,6 +102,7 @@ def _dry_setup(hass, config, add_devices, discovery_info=None):
use_cents = config.get("price_in_cents")
ad_template = config.get("additional_costs")
api = hass.data[DOMAIN]
unique_id = config.get("unique_id")
sensor = NordpoolSensor(
friendly_name,
region,
Expand All @@ -113,6 +115,7 @@ def _dry_setup(hass, config, add_devices, discovery_info=None):
api,
ad_template,
hass,
unique_id,
)

add_devices([sensor])
Expand Down Expand Up @@ -148,6 +151,7 @@ def __init__(
api,
ad_template,
hass,
unique_id=None,
) -> None:
self._area = area
self._currency = currency or _REGIONS[area][0]
Expand All @@ -161,6 +165,7 @@ def __init__(
self._ad_template = ad_template
self._hass = hass
self._attr_force_update = True
self._user_unique_id = unique_id

if vat is True:
self._vat = _REGIONS[area][2]
Expand Down Expand Up @@ -228,6 +233,9 @@ def unit_of_measurement(self) -> str: # FIXME

@property
def unique_id(self):
if self._user_unique_id:
return self._user_unique_id

name = "nordpool_%s_%s_%s_%s_%s_%s" % (
self._price_type,
self._area,
Expand Down