mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add device name to sensor name for mobile_app (#31756)
* Add device name to sensor name * Update test to include device name
This commit is contained in:
parent
3b3e062a35
commit
43256ebd83
@ -7,6 +7,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
ATTR_DEVICE_NAME,
|
||||||
ATTR_SENSOR_ATTRIBUTES,
|
ATTR_SENSOR_ATTRIBUTES,
|
||||||
ATTR_SENSOR_DEVICE_CLASS,
|
ATTR_SENSOR_DEVICE_CLASS,
|
||||||
ATTR_SENSOR_ICON,
|
ATTR_SENSOR_ICON,
|
||||||
@ -38,6 +39,7 @@ class MobileAppEntity(Entity):
|
|||||||
)
|
)
|
||||||
self._entity_type = config[ATTR_SENSOR_TYPE]
|
self._entity_type = config[ATTR_SENSOR_TYPE]
|
||||||
self.unsub_dispatcher = None
|
self.unsub_dispatcher = None
|
||||||
|
self._name = f"{entry.data[ATTR_DEVICE_NAME]} {config[ATTR_SENSOR_NAME]}"
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
@ -58,7 +60,7 @@ class MobileAppEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the mobile app sensor."""
|
"""Return the name of the mobile app sensor."""
|
||||||
return self._config[ATTR_SENSOR_NAME]
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
|
@ -35,7 +35,7 @@ async def test_sensor(hass, create_registrations, webhook_client):
|
|||||||
assert json == {"success": True}
|
assert json == {"success": True}
|
||||||
await hass.async_block_till_done()
|
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 is not None
|
||||||
|
|
||||||
assert entity.attributes["device_class"] == "battery"
|
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["unit_of_measurement"] == "%"
|
||||||
assert entity.attributes["foo"] == "bar"
|
assert entity.attributes["foo"] == "bar"
|
||||||
assert entity.domain == "sensor"
|
assert entity.domain == "sensor"
|
||||||
assert entity.name == "Battery State"
|
assert entity.name == "Test 1 Battery State"
|
||||||
assert entity.state == "100"
|
assert entity.state == "100"
|
||||||
|
|
||||||
update_resp = await webhook_client.post(
|
update_resp = await webhook_client.post(
|
||||||
@ -63,7 +63,7 @@ async def test_sensor(hass, create_registrations, webhook_client):
|
|||||||
|
|
||||||
assert update_resp.status == 200
|
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"
|
assert updated_entity.state == "123"
|
||||||
|
|
||||||
dev_reg = await device_registry.async_get_registry(hass)
|
dev_reg = await device_registry.async_get_registry(hass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user