Skip to content

Commit

Permalink
v2.2.0, fix device info and sensor naming, fixing #8
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Oct 7, 2023
1 parent 4018943 commit d206de1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
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.1.0"
"version": "2.2.0"
}
28 changes: 16 additions & 12 deletions custom_components/myenergy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity, SensorDeviceClass
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity import Entity, DeviceInfo
from homeassistant.util import Throttle
from homeassistant.const import (
CONF_NAME,
Expand Down Expand Up @@ -150,11 +150,11 @@ def __init__(self, config, hass):

@property
def unique_id(self):
return f"{DOMAIN}-{self._postalcode}"
return f"{NAME} {self._postalcode}"
@property
def name(self) -> str:
"""Return the name of the sensor."""
return f"{DOMAIN}-{self._postalcode}"
return self.unique_id

# same as update, but without throttle to make sure init is always executed
async def _forced_update(self):
Expand Down Expand Up @@ -265,12 +265,12 @@ def icon(self) -> str:
@property
def unique_id(self) -> str:
"""Return the unique ID of the sensor."""
return f"{self._data.unique_id}-{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:
"""Return the name of the sensor."""
return self._name
return self.unique_id

@property
def extra_state_attributes(self) -> dict:
Expand All @@ -291,14 +291,18 @@ def extra_state_attributes(self) -> dict:
"total kWh per year": self._kWhyear
}


@property
def device_info(self) -> dict:
"""Device info dictionary."""
return {
"identifiers": {(DOMAIN, self._data.unique_id)},
"name": self.name,
"manufacturer": DOMAIN,
}
def device_info(self) -> DeviceInfo:
"""Return the device info."""
return DeviceInfo(
identifiers={
# Serial numbers are unique identifiers within a specific domain
(NAME, self._data.unique_id)
},
name=self._data.name,
manufacturer= NAME
)

@property
def unit(self) -> int:
Expand Down

0 comments on commit d206de1

Please sign in to comment.