Add configuration_url to Sense (#57814)
parent
1cf7634942
commit
8405331204
|
@ -92,6 +92,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
update_method=gateway.update_trend_data,
|
update_method=gateway.update_trend_data,
|
||||||
update_interval=timedelta(seconds=300),
|
update_interval=timedelta(seconds=300),
|
||||||
)
|
)
|
||||||
|
# Start out as unavailable so we do not report 0 data
|
||||||
|
# until the update happens
|
||||||
|
trends_coordinator.last_update_success = False
|
||||||
|
|
||||||
# This can take longer than 60s and we already know
|
# This can take longer than 60s and we already know
|
||||||
# sense is online since get_discovered_device_data was
|
# sense is online since get_discovered_device_data was
|
||||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ACTIVE_NAME,
|
ACTIVE_NAME,
|
||||||
|
@ -85,11 +86,10 @@ def sense_to_mdi(sense_icon):
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up the Sense sensor."""
|
"""Set up the Sense sensor."""
|
||||||
data = hass.data[DOMAIN][config_entry.entry_id][SENSE_DATA]
|
base_data = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
sense_devices_data = hass.data[DOMAIN][config_entry.entry_id][SENSE_DEVICES_DATA]
|
data = base_data[SENSE_DATA]
|
||||||
trends_coordinator = hass.data[DOMAIN][config_entry.entry_id][
|
sense_devices_data = base_data[SENSE_DEVICES_DATA]
|
||||||
SENSE_TRENDS_COORDINATOR
|
trends_coordinator = base_data[SENSE_TRENDS_COORDINATOR]
|
||||||
]
|
|
||||||
|
|
||||||
# Request only in case it takes longer
|
# Request only in case it takes longer
|
||||||
# than 60s
|
# than 60s
|
||||||
|
@ -141,6 +141,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
variant_name,
|
variant_name,
|
||||||
trends_coordinator,
|
trends_coordinator,
|
||||||
unique_id,
|
unique_id,
|
||||||
|
sense_monitor_id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -245,7 +246,7 @@ class SenseVoltageSensor(SensorEntity):
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
class SenseTrendsSensor(SensorEntity):
|
class SenseTrendsSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Implementation of a Sense energy sensor."""
|
"""Implementation of a Sense energy sensor."""
|
||||||
|
|
||||||
_attr_device_class = DEVICE_CLASS_ENERGY
|
_attr_device_class = DEVICE_CLASS_ENERGY
|
||||||
|
@ -264,49 +265,34 @@ class SenseTrendsSensor(SensorEntity):
|
||||||
variant_name,
|
variant_name,
|
||||||
trends_coordinator,
|
trends_coordinator,
|
||||||
unique_id,
|
unique_id,
|
||||||
|
sense_monitor_id,
|
||||||
):
|
):
|
||||||
"""Initialize the Sense sensor."""
|
"""Initialize the Sense sensor."""
|
||||||
|
super().__init__(trends_coordinator)
|
||||||
self._attr_name = f"{name} {variant_name}"
|
self._attr_name = f"{name} {variant_name}"
|
||||||
self._attr_unique_id = unique_id
|
self._attr_unique_id = unique_id
|
||||||
self._data = data
|
self._data = data
|
||||||
self._sensor_type = sensor_type
|
self._sensor_type = sensor_type
|
||||||
self._coordinator = trends_coordinator
|
|
||||||
self._variant_id = variant_id
|
self._variant_id = variant_id
|
||||||
self._had_any_update = False
|
self._had_any_update = False
|
||||||
|
|
||||||
if variant_id in [PRODUCTION_PCT_ID, SOLAR_POWERED_ID]:
|
if variant_id in [PRODUCTION_PCT_ID, SOLAR_POWERED_ID]:
|
||||||
self._attr_native_unit_of_measurement = PERCENTAGE
|
self._attr_native_unit_of_measurement = PERCENTAGE
|
||||||
self._attr_entity_registry_enabled_default = False
|
self._attr_entity_registry_enabled_default = False
|
||||||
self._attr_state_class = None
|
self._attr_state_class = None
|
||||||
self._attr_device_class = None
|
self._attr_device_class = None
|
||||||
|
self._attr_device_info = {
|
||||||
|
"name": f"Sense {sense_monitor_id}",
|
||||||
|
"identifiers": {(DOMAIN, sense_monitor_id)},
|
||||||
|
"model": "Sense",
|
||||||
|
"manufacturer": "Sense Labs, Inc.",
|
||||||
|
"configuration_url": "https://home.sense.com",
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return round(self._data.get_trend(self._sensor_type, self._variant_id), 1)
|
return round(self._data.get_trend(self._sensor_type, self._variant_id), 1)
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self):
|
|
||||||
"""Return if entity is available."""
|
|
||||||
return self._had_any_update and self._coordinator.last_update_success
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def _async_update(self):
|
|
||||||
"""Track if we had an update so we do not report zero data."""
|
|
||||||
self._had_any_update = True
|
|
||||||
self.async_write_ha_state()
|
|
||||||
|
|
||||||
async def async_update(self):
|
|
||||||
"""Update the entity.
|
|
||||||
|
|
||||||
Only used by the generic entity update service.
|
|
||||||
"""
|
|
||||||
await self._coordinator.async_request_refresh()
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""When entity is added to hass."""
|
|
||||||
self.async_on_remove(self._coordinator.async_add_listener(self._async_update))
|
|
||||||
|
|
||||||
|
|
||||||
class SenseEnergyDevice(SensorEntity):
|
class SenseEnergyDevice(SensorEntity):
|
||||||
"""Implementation of a Sense energy device."""
|
"""Implementation of a Sense energy device."""
|
||||||
|
|
Loading…
Reference in New Issue