hass-core/tests/components/drop_connect/test_select.py
Patrick Frazer 771409579a
Add select platform to drop_connect integration (#106309)
* Add select platform to drop_connect integration

* Fix select test

* Fix minor issues

* Make function definition more specific

* Revert change to switch.py for inclusion in separate PR

* Improve typing

* Add translation keys for select options

* Fix set function typing

* Remove redundant value check

* Remove args that match defaults
2023-12-24 15:03:10 +01:00

59 lines
2 KiB
Python

"""Test DROP select entities."""
from homeassistant.components.drop_connect.const import DOMAIN
from homeassistant.components.select import (
ATTR_OPTION,
ATTR_OPTIONS,
DOMAIN as SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .common import TEST_DATA_HUB, TEST_DATA_HUB_RESET, TEST_DATA_HUB_TOPIC
from tests.common import async_fire_mqtt_message
from tests.typing import MqttMockHAClient
async def test_selects_hub(
hass: HomeAssistant, config_entry_hub, mqtt_mock: MqttMockHAClient
) -> None:
"""Test DROP binary sensors for hubs."""
config_entry_hub.add_to_hass(hass)
assert await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
protect_mode_select_name = "select.hub_drop_1_c0ffee_protect_mode"
protect_mode_select = hass.states.get(protect_mode_select_name)
assert protect_mode_select
assert protect_mode_select.attributes.get(ATTR_OPTIONS) == [
"away",
"home",
"schedule",
]
async_fire_mqtt_message(hass, TEST_DATA_HUB_TOPIC, TEST_DATA_HUB_RESET)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, TEST_DATA_HUB_TOPIC, TEST_DATA_HUB)
await hass.async_block_till_done()
protect_mode_select = hass.states.get(protect_mode_select_name)
assert protect_mode_select
assert protect_mode_select.state == "home"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_OPTION: "away", ATTR_ENTITY_ID: protect_mode_select_name},
blocking=True,
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, TEST_DATA_HUB_TOPIC, TEST_DATA_HUB_RESET)
await hass.async_block_till_done()
protect_mode_select = hass.states.get(protect_mode_select_name)
assert protect_mode_select
assert protect_mode_select.state == "away"