Add 'unique_id' Property to Inverter Sensors (#24707)

* Option to change sensor names

* Python 3.5 compatibility

* Oops

* Get serial number at start

* Remove config opportunity

* Oops comma

* Changes from review

* Check yourself before you commit.
This commit is contained in:
Robin Wohlers-Reichel 2019-06-25 01:34:20 +10:00 committed by Paulus Schoutsen
parent e841f568c1
commit 17480a0398
3 changed files with 16 additions and 6 deletions

View File

@ -3,7 +3,7 @@
"name": "Solax Inverter",
"documentation": "https://www.home-assistant.io/components/solax",
"requirements": [
"solax==0.1.0"
"solax==0.1.1"
],
"dependencies": [],
"codeowners": ["@squishykid"]

View File

@ -32,14 +32,17 @@ async def async_setup_platform(hass, config, async_add_entities,
api = solax.RealTimeAPI(config[CONF_IP_ADDRESS])
endpoint = RealTimeDataEndpoint(hass, api)
resp = await api.get_data()
serial = resp.serial_number
hass.async_add_job(endpoint.async_refresh)
async_track_time_interval(hass, endpoint.async_refresh, SCAN_INTERVAL)
devices = []
for sensor in solax.INVERTER_SENSORS:
unit = solax.INVERTER_SENSORS[sensor][1]
idx, unit = solax.INVERTER_SENSORS[sensor]
if unit == 'C':
unit = TEMP_CELSIUS
devices.append(Inverter(sensor, unit))
uid = '{}-{}'.format(serial, idx)
devices.append(Inverter(uid, serial, sensor, unit))
endpoint.sensors = devices
async_add_entities(devices)
@ -79,8 +82,10 @@ class RealTimeDataEndpoint:
class Inverter(Entity):
"""Class for a sensor."""
def __init__(self, key, unit):
def __init__(self, uid, serial, key, unit):
"""Initialize an inverter sensor."""
self.uid = uid
self.serial = serial
self.key = key
self.value = None
self.unit = unit
@ -90,10 +95,15 @@ class Inverter(Entity):
"""State of this inverter attribute."""
return self.value
@property
def unique_id(self):
"""Return unique id."""
return self.uid
@property
def name(self):
"""Name of this inverter attribute."""
return self.key
return 'Solax {} {}'.format(self.serial, self.key)
@property
def unit_of_measurement(self):

View File

@ -1703,7 +1703,7 @@ solaredge-local==0.1.4
solaredge==0.0.2
# homeassistant.components.solax
solax==0.1.0
solax==0.1.1
# homeassistant.components.honeywell
somecomfort==0.5.2