Add device name to sensor name for mobile_app (#31756)
* Add device name to sensor name * Update test to include device namepull/31768/head
parent
3b3e062a35
commit
43256ebd83
|
@ -7,6 +7,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import (
|
||||
ATTR_DEVICE_NAME,
|
||||
ATTR_SENSOR_ATTRIBUTES,
|
||||
ATTR_SENSOR_DEVICE_CLASS,
|
||||
ATTR_SENSOR_ICON,
|
||||
|
@ -38,6 +39,7 @@ class MobileAppEntity(Entity):
|
|||
)
|
||||
self._entity_type = config[ATTR_SENSOR_TYPE]
|
||||
self.unsub_dispatcher = None
|
||||
self._name = f"{entry.data[ATTR_DEVICE_NAME]} {config[ATTR_SENSOR_NAME]}"
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
|
@ -58,7 +60,7 @@ class MobileAppEntity(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the mobile app sensor."""
|
||||
return self._config[ATTR_SENSOR_NAME]
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
|
|
|
@ -35,7 +35,7 @@ async def test_sensor(hass, create_registrations, webhook_client):
|
|||
assert json == {"success": True}
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity = hass.states.get("sensor.battery_state")
|
||||
entity = hass.states.get("sensor.test_1_battery_state")
|
||||
assert entity is not None
|
||||
|
||||
assert entity.attributes["device_class"] == "battery"
|
||||
|
@ -43,7 +43,7 @@ async def test_sensor(hass, create_registrations, webhook_client):
|
|||
assert entity.attributes["unit_of_measurement"] == "%"
|
||||
assert entity.attributes["foo"] == "bar"
|
||||
assert entity.domain == "sensor"
|
||||
assert entity.name == "Battery State"
|
||||
assert entity.name == "Test 1 Battery State"
|
||||
assert entity.state == "100"
|
||||
|
||||
update_resp = await webhook_client.post(
|
||||
|
@ -63,7 +63,7 @@ async def test_sensor(hass, create_registrations, webhook_client):
|
|||
|
||||
assert update_resp.status == 200
|
||||
|
||||
updated_entity = hass.states.get("sensor.battery_state")
|
||||
updated_entity = hass.states.get("sensor.test_1_battery_state")
|
||||
assert updated_entity.state == "123"
|
||||
|
||||
dev_reg = await device_registry.async_get_registry(hass)
|
||||
|
|
Loading…
Reference in New Issue