mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix Tibber Pulse device name and sensor update (#51402)
This commit is contained in:
parent
e8762bdea1
commit
1062acfe9b
@ -186,6 +186,7 @@ class TibberSensor(SensorEntity):
|
|||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._tibber_home = tibber_home
|
self._tibber_home = tibber_home
|
||||||
self._home_name = tibber_home.info["viewer"]["home"]["appNickname"]
|
self._home_name = tibber_home.info["viewer"]["home"]["appNickname"]
|
||||||
|
self._device_name = None
|
||||||
if self._home_name is None:
|
if self._home_name is None:
|
||||||
self._home_name = tibber_home.info["viewer"]["home"]["address"].get(
|
self._home_name = tibber_home.info["viewer"]["home"]["address"].get(
|
||||||
"address1", ""
|
"address1", ""
|
||||||
@ -202,7 +203,7 @@ class TibberSensor(SensorEntity):
|
|||||||
"""Return the device_info of the device."""
|
"""Return the device_info of the device."""
|
||||||
device_info = {
|
device_info = {
|
||||||
"identifiers": {(TIBBER_DOMAIN, self.device_id)},
|
"identifiers": {(TIBBER_DOMAIN, self.device_id)},
|
||||||
"name": self.name,
|
"name": self._device_name,
|
||||||
"manufacturer": MANUFACTURER,
|
"manufacturer": MANUFACTURER,
|
||||||
}
|
}
|
||||||
if self._model is not None:
|
if self._model is not None:
|
||||||
@ -237,6 +238,8 @@ class TibberSensorElPrice(TibberSensor):
|
|||||||
self._attr_unique_id = f"{self._tibber_home.home_id}"
|
self._attr_unique_id = f"{self._tibber_home.home_id}"
|
||||||
self._model = "Price Sensor"
|
self._model = "Price Sensor"
|
||||||
|
|
||||||
|
self._device_name = self._attr_name
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest data and updates the states."""
|
"""Get the latest data and updates the states."""
|
||||||
now = dt_util.now()
|
now = dt_util.now()
|
||||||
@ -295,6 +298,7 @@ class TibberSensorRT(TibberSensor):
|
|||||||
super().__init__(tibber_home)
|
super().__init__(tibber_home)
|
||||||
self._sensor_name = sensor_name
|
self._sensor_name = sensor_name
|
||||||
self._model = "Tibber Pulse"
|
self._model = "Tibber Pulse"
|
||||||
|
self._device_name = f"{self._model} {self._home_name}"
|
||||||
|
|
||||||
self._attr_device_class = device_class
|
self._attr_device_class = device_class
|
||||||
self._attr_name = f"{self._sensor_name} {self._home_name}"
|
self._attr_name = f"{self._sensor_name} {self._home_name}"
|
||||||
@ -330,7 +334,7 @@ class TibberSensorRT(TibberSensor):
|
|||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
self.hass,
|
self.hass,
|
||||||
SIGNAL_UPDATE_ENTITY.format(self._sensor_name),
|
SIGNAL_UPDATE_ENTITY.format(self.unique_id),
|
||||||
self._set_state,
|
self._set_state,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -370,7 +374,7 @@ class TibberRtDataHandler:
|
|||||||
self._async_add_entities = async_add_entities
|
self._async_add_entities = async_add_entities
|
||||||
self._tibber_home = tibber_home
|
self._tibber_home = tibber_home
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._entities = set()
|
self._entities = {}
|
||||||
|
|
||||||
async def async_callback(self, payload):
|
async def async_callback(self, payload):
|
||||||
"""Handle received data."""
|
"""Handle received data."""
|
||||||
@ -393,7 +397,7 @@ class TibberRtDataHandler:
|
|||||||
if sensor_type in self._entities:
|
if sensor_type in self._entities:
|
||||||
async_dispatcher_send(
|
async_dispatcher_send(
|
||||||
self.hass,
|
self.hass,
|
||||||
SIGNAL_UPDATE_ENTITY.format(RT_SENSOR_MAP[sensor_type][0]),
|
SIGNAL_UPDATE_ENTITY.format(self._entities[sensor_type]),
|
||||||
state,
|
state,
|
||||||
timestamp,
|
timestamp,
|
||||||
)
|
)
|
||||||
@ -412,6 +416,6 @@ class TibberRtDataHandler:
|
|||||||
state_class,
|
state_class,
|
||||||
)
|
)
|
||||||
new_entities.append(entity)
|
new_entities.append(entity)
|
||||||
self._entities.add(sensor_type)
|
self._entities[sensor_type] = entity.unique_id
|
||||||
if new_entities:
|
if new_entities:
|
||||||
self._async_add_entities(new_entities)
|
self._async_add_entities(new_entities)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user