Skip to content
Snippets Groups Projects
Commit 5e973dd0 authored by fredericvl's avatar fredericvl Committed by Martin Hjelmare
Browse files

Change unique id for SAJ sensor based on device SN (#28663)

* Change unique id for SAJ sensor based on device SN

* Add SAJ device name + sn to state attributes

* Revert device state attributes (after review)
parent bc14e93a
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"name": "SAJ", "name": "SAJ",
"documentation": "https://www.home-assistant.io/integrations/saj", "documentation": "https://www.home-assistant.io/integrations/saj",
"requirements": [ "requirements": [
"pysaj==0.0.13" "pysaj==0.0.14"
], ],
"dependencies": [], "dependencies": [],
"codeowners": [ "codeowners": [
......
...@@ -69,9 +69,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ...@@ -69,9 +69,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
# Use all sensors by default # Use all sensors by default
hass_sensors = [] hass_sensors = []
for sensor in sensor_def:
hass_sensors.append(SAJsensor(sensor, inverter_name=config.get(CONF_NAME)))
kwargs = {} kwargs = {}
if wifi: if wifi:
kwargs["wifi"] = True kwargs["wifi"] = True
...@@ -81,7 +78,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ...@@ -81,7 +78,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
try: try:
saj = pysaj.SAJ(config[CONF_HOST], **kwargs) saj = pysaj.SAJ(config[CONF_HOST], **kwargs)
await saj.read(sensor_def) done = await saj.read(sensor_def)
except pysaj.UnauthorizedException: except pysaj.UnauthorizedException:
_LOGGER.error("Username and/or password is wrong.") _LOGGER.error("Username and/or password is wrong.")
return return
...@@ -91,7 +88,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ...@@ -91,7 +88,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
) )
return return
async_add_entities(hass_sensors) if done:
for sensor in sensor_def:
hass_sensors.append(
SAJsensor(saj.serialnumber, sensor, inverter_name=config.get(CONF_NAME))
)
async_add_entities(hass_sensors)
async def async_saj(): async def async_saj():
"""Update all the SAJ sensors.""" """Update all the SAJ sensors."""
...@@ -163,10 +166,11 @@ def async_track_time_interval_backoff(hass, action) -> CALLBACK_TYPE: ...@@ -163,10 +166,11 @@ def async_track_time_interval_backoff(hass, action) -> CALLBACK_TYPE:
class SAJsensor(Entity): class SAJsensor(Entity):
"""Representation of a SAJ sensor.""" """Representation of a SAJ sensor."""
def __init__(self, pysaj_sensor, inverter_name=None): def __init__(self, serialnumber, pysaj_sensor, inverter_name=None):
"""Initialize the sensor.""" """Initialize the sensor."""
self._sensor = pysaj_sensor self._sensor = pysaj_sensor
self._inverter_name = inverter_name self._inverter_name = inverter_name
self._serialnumber = serialnumber
self._state = self._sensor.value self._state = self._sensor.value
@property @property
...@@ -235,7 +239,4 @@ class SAJsensor(Entity): ...@@ -235,7 +239,4 @@ class SAJsensor(Entity):
@property @property
def unique_id(self): def unique_id(self):
"""Return a unique identifier for this sensor.""" """Return a unique identifier for this sensor."""
if self._inverter_name: return f"{self._serialnumber}_{self._sensor.name}"
return f"{self._inverter_name}_{self._sensor.name}"
return f"{self._sensor.name}"
...@@ -1435,7 +1435,7 @@ pyrepetier==3.0.5 ...@@ -1435,7 +1435,7 @@ pyrepetier==3.0.5
pysabnzbd==1.1.0 pysabnzbd==1.1.0
# homeassistant.components.saj # homeassistant.components.saj
pysaj==0.0.13 pysaj==0.0.14
# homeassistant.components.sony_projector # homeassistant.components.sony_projector
pysdcp==1 pysdcp==1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment