mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
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:
parent
e841f568c1
commit
17480a0398
@ -3,7 +3,7 @@
|
|||||||
"name": "Solax Inverter",
|
"name": "Solax Inverter",
|
||||||
"documentation": "https://www.home-assistant.io/components/solax",
|
"documentation": "https://www.home-assistant.io/components/solax",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"solax==0.1.0"
|
"solax==0.1.1"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@squishykid"]
|
"codeowners": ["@squishykid"]
|
||||||
|
@ -32,14 +32,17 @@ async def async_setup_platform(hass, config, async_add_entities,
|
|||||||
|
|
||||||
api = solax.RealTimeAPI(config[CONF_IP_ADDRESS])
|
api = solax.RealTimeAPI(config[CONF_IP_ADDRESS])
|
||||||
endpoint = RealTimeDataEndpoint(hass, api)
|
endpoint = RealTimeDataEndpoint(hass, api)
|
||||||
|
resp = await api.get_data()
|
||||||
|
serial = resp.serial_number
|
||||||
hass.async_add_job(endpoint.async_refresh)
|
hass.async_add_job(endpoint.async_refresh)
|
||||||
async_track_time_interval(hass, endpoint.async_refresh, SCAN_INTERVAL)
|
async_track_time_interval(hass, endpoint.async_refresh, SCAN_INTERVAL)
|
||||||
devices = []
|
devices = []
|
||||||
for sensor in solax.INVERTER_SENSORS:
|
for sensor in solax.INVERTER_SENSORS:
|
||||||
unit = solax.INVERTER_SENSORS[sensor][1]
|
idx, unit = solax.INVERTER_SENSORS[sensor]
|
||||||
if unit == 'C':
|
if unit == 'C':
|
||||||
unit = TEMP_CELSIUS
|
unit = TEMP_CELSIUS
|
||||||
devices.append(Inverter(sensor, unit))
|
uid = '{}-{}'.format(serial, idx)
|
||||||
|
devices.append(Inverter(uid, serial, sensor, unit))
|
||||||
endpoint.sensors = devices
|
endpoint.sensors = devices
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
|
|
||||||
@ -79,8 +82,10 @@ class RealTimeDataEndpoint:
|
|||||||
class Inverter(Entity):
|
class Inverter(Entity):
|
||||||
"""Class for a sensor."""
|
"""Class for a sensor."""
|
||||||
|
|
||||||
def __init__(self, key, unit):
|
def __init__(self, uid, serial, key, unit):
|
||||||
"""Initialize an inverter sensor."""
|
"""Initialize an inverter sensor."""
|
||||||
|
self.uid = uid
|
||||||
|
self.serial = serial
|
||||||
self.key = key
|
self.key = key
|
||||||
self.value = None
|
self.value = None
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
@ -90,10 +95,15 @@ class Inverter(Entity):
|
|||||||
"""State of this inverter attribute."""
|
"""State of this inverter attribute."""
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return unique id."""
|
||||||
|
return self.uid
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Name of this inverter attribute."""
|
"""Name of this inverter attribute."""
|
||||||
return self.key
|
return 'Solax {} {}'.format(self.serial, self.key)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
|
@ -1703,7 +1703,7 @@ solaredge-local==0.1.4
|
|||||||
solaredge==0.0.2
|
solaredge==0.0.2
|
||||||
|
|
||||||
# homeassistant.components.solax
|
# homeassistant.components.solax
|
||||||
solax==0.1.0
|
solax==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.honeywell
|
# homeassistant.components.honeywell
|
||||||
somecomfort==0.5.2
|
somecomfort==0.5.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user