Skip to content

Instantly share code, notes, and snippets.

@jbouwh
Last active July 21, 2021 13:17
Show Gist options
  • Select an option

  • Save jbouwh/233d0938973d755befcee03b039c6c48 to your computer and use it in GitHub Desktop.

Select an option

Save jbouwh/233d0938973d755befcee03b039c6c48 to your computer and use it in GitHub Desktop.
tests/testing_config/custom_components/test
"""
Provide a mock select platform.
Call init before using it in your tests to ensure clean test data.
"""
from tests.common import MockEntity
UNIQUE_SELECT_1 = "unique_select_1"
UNIQUE_SELECT_2 = "unique_select_2"
UNIQUE_SELECT_3 = "unique_select_3"
ENTITIES = []
class MockSelectEntity(MockEntity):
"""Mock Select class."""
@property
def current_option(self):
"""Return the current option of this select."""
return self._handle("current_option")
@property
def options(self) -> list:
"""Return the list of available options of this select."""
return self._handle("options")
def init(empty=False):
"""Initialize the platform with entities."""
global ENTITIES
ENTITIES = (
[]
if empty
else [
MockSelectEntity(
name=f"select 1",
unique_id=f"unique_select_1",
options=["option 1", "option 2", "option 3"],
current_option="option 1",
),
MockSelectEntity(
name=f"select 2",
unique_id=f"unique_select_2",
options=["option 1", "option 2", "option 3"],
),
MockSelectEntity(
name=f"select 3",
unique_id=f"unique_select_3",
options=["option 1", "option 2", "option 3"],
min_value=0,
max_value=5,
),
]
)
async def async_setup_platform(
hass, config, async_add_entities_callback, discovery_info=None
):
"""Return mock entities."""
async_add_entities_callback(ENTITIES)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment