Adjust D-Link entity naming (#86906)
parent
1958dd5550
commit
709d1cb8af
|
@ -1,7 +1,7 @@
|
||||||
"""Entity representing a D-Link Power Plug device."""
|
"""Entity representing a D-Link Power Plug device."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_CONNECTIONS
|
from homeassistant.const import ATTR_CONNECTIONS
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
|
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
|
||||||
|
@ -14,6 +14,7 @@ class DLinkEntity(Entity):
|
||||||
"""Representation of a D-Link Power Plug entity."""
|
"""Representation of a D-Link Power Plug entity."""
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -24,10 +25,6 @@ class DLinkEntity(Entity):
|
||||||
"""Initialize a D-Link Power Plug entity."""
|
"""Initialize a D-Link Power Plug entity."""
|
||||||
self.data = data
|
self.data = data
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
if config_entry.source == SOURCE_IMPORT:
|
|
||||||
self._attr_name = config_entry.title
|
|
||||||
else:
|
|
||||||
self._attr_has_entity_name = True
|
|
||||||
self._attr_unique_id = f"{config_entry.entry_id}_{description.key}"
|
self._attr_unique_id = f"{config_entry.entry_id}_{description.key}"
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, config_entry.entry_id)},
|
identifiers={(DOMAIN, config_entry.entry_id)},
|
||||||
|
|
|
@ -47,10 +47,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
SWITCH_TYPE = SwitchEntityDescription(
|
SWITCH_TYPE = SwitchEntityDescription(key="")
|
||||||
key="switch",
|
|
||||||
name="Switch",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(
|
def setup_platform(
|
||||||
|
|
|
@ -44,7 +44,7 @@ async def test_switch_state(
|
||||||
|
|
||||||
await setup_integration()
|
await setup_integration()
|
||||||
|
|
||||||
entity_id = "switch.mock_title_switch"
|
entity_id = "switch.mock_title"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert state.attributes["total_consumption"] == 1040.0
|
assert state.attributes["total_consumption"] == 1040.0
|
||||||
|
@ -71,7 +71,7 @@ async def test_switch_no_value(
|
||||||
"""Test we handle 'N/A' being passed by the pypi package."""
|
"""Test we handle 'N/A' being passed by the pypi package."""
|
||||||
await setup_integration_legacy()
|
await setup_integration_legacy()
|
||||||
|
|
||||||
state = hass.states.get("switch.mock_title_switch")
|
state = hass.states.get("switch.mock_title")
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert state.attributes["total_consumption"] is None
|
assert state.attributes["total_consumption"] is None
|
||||||
assert state.attributes["temperature"] is None
|
assert state.attributes["temperature"] is None
|
||||||
|
|
Loading…
Reference in New Issue