Add button device classes to NAM (#60621)

This commit is contained in:
Franck Nijhof 2021-12-01 07:08:17 +01:00 committed by GitHub
parent 9efec244b9
commit 9715601255
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -3,7 +3,11 @@ from __future__ import annotations
import logging import logging
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription from homeassistant.components.button import (
ButtonDeviceClass,
ButtonEntity,
ButtonEntityDescription,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_CONFIG from homeassistant.const import ENTITY_CATEGORY_CONFIG
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -20,7 +24,7 @@ _LOGGER = logging.getLogger(__name__)
RESTART_BUTTON: ButtonEntityDescription = ButtonEntityDescription( RESTART_BUTTON: ButtonEntityDescription = ButtonEntityDescription(
key="restart", key="restart",
name=f"{DEFAULT_NAME} Restart", name=f"{DEFAULT_NAME} Restart",
icon="mdi:restart", device_class=ButtonDeviceClass.RESTART,
entity_category=ENTITY_CATEGORY_CONFIG, entity_category=ENTITY_CATEGORY_CONFIG,
) )

View File

@ -1,8 +1,8 @@
"""Test button of Nettigo Air Monitor integration.""" """Test button of Nettigo Air Monitor integration."""
from unittest.mock import patch from unittest.mock import patch
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, ButtonDeviceClass
from homeassistant.const import ATTR_ENTITY_ID, ATTR_ICON, STATE_UNKNOWN from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_ENTITY_ID, STATE_UNKNOWN
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
@ -18,7 +18,7 @@ async def test_button(hass):
state = hass.states.get("button.nettigo_air_monitor_restart") state = hass.states.get("button.nettigo_air_monitor_restart")
assert state assert state
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
assert state.attributes.get(ATTR_ICON) == "mdi:restart" assert state.attributes.get(ATTR_DEVICE_CLASS) == ButtonDeviceClass.RESTART
entry = registry.async_get("button.nettigo_air_monitor_restart") entry = registry.async_get("button.nettigo_air_monitor_restart")
assert entry assert entry