Skip to content

Commit

Permalink
Set correct entity categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Shutgun committed Jan 16, 2023
1 parent d9f0d1e commit 079abc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/devolo_home_network/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, IDENTIFY, PAIRING, RESTART, START_WPS
Expand All @@ -40,6 +41,7 @@ class DevoloButtonEntityDescription(
BUTTON_TYPES: dict[str, DevoloButtonEntityDescription] = {
IDENTIFY: DevoloButtonEntityDescription(
key=IDENTIFY,
entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:led-on",
name="Identify device with a blinking LED",
press_func=lambda device: device.plcnet.async_identify_device_start(), # type: ignore[union-attr]
Expand All @@ -53,6 +55,7 @@ class DevoloButtonEntityDescription(
RESTART: DevoloButtonEntityDescription(
key=RESTART,
device_class=ButtonDeviceClass.RESTART,
entity_category=EntityCategory.CONFIG,
name="Restart device",
press_func=lambda device: device.device.async_restart(), # type: ignore[union-attr]
),
Expand Down
9 changes: 6 additions & 3 deletions tests/components/devolo_home_network/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from homeassistant.config_entries import SOURCE_REAUTH
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry
from homeassistant.helpers.entity import EntityCategory

from . import configure_integration
from .mock import MockDevice
Expand Down Expand Up @@ -44,13 +46,14 @@ async def test_identify_device(hass: HomeAssistant, mock_device: MockDevice):
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_identify_device_with_a_blinking_led"

er = entity_registry.async_get(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

state = hass.states.get(state_key)
assert state is not None
assert state.state == STATE_UNKNOWN
assert er.async_get(state_key).entity_category is EntityCategory.DIAGNOSTIC

# Emulate button press
await hass.services.async_call(
Expand All @@ -74,7 +77,6 @@ async def test_start_plc_pairing(hass: HomeAssistant, mock_device: MockDevice):
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_start_plc_pairing"

await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

Expand Down Expand Up @@ -104,14 +106,15 @@ async def test_restart(hass: HomeAssistant, mock_device: MockDevice):
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_restart_device"

er = entity_registry.async_get(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

state = hass.states.get(state_key)
assert state is not None
assert state.state == STATE_UNKNOWN
assert state.attributes["device_class"] == ButtonDeviceClass.RESTART
assert er.async_get(state_key).entity_category is EntityCategory.CONFIG

# Emulate button press
await hass.services.async_call(
Expand Down

0 comments on commit 079abc3

Please sign in to comment.