Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
sequence
start_point
sequence
end_point
sequence
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
test_async_setup_entry
(hass)
Test a successful setup entry.
Test a successful setup entry.
async def test_async_setup_entry(hass): """Test a successful setup entry.""" await init_integration(hass) state = hass.states.get("air_quality.home") assert state is not None assert state.state != STATE_UNAVAILABLE assert state.state == "4"
[ "async", "def", "test_async_setup_entry", "(", "hass", ")", ":", "await", "init_integration", "(", "hass", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"air_quality.home\"", ")", "assert", "state", "is", "not", "None", "assert", "state", ".", "state", "!=", "STATE_UNAVAILABLE", "assert", "state", ".", "state", "==", "\"4\"" ]
[ 14, 0 ]
[ 21, 29 ]
python
en
['en', 'en', 'en']
True
test_config_not_ready
(hass)
Test for setup failure if connection to GIOS is missing.
Test for setup failure if connection to GIOS is missing.
async def test_config_not_ready(hass): """Test for setup failure if connection to GIOS is missing.""" entry = MockConfigEntry( domain=DOMAIN, title="Home", unique_id=123, data={"station_id": 123, "name": "Home"}, ) with patch( "homeassistant.components.gios.Gios._get_stations", side_effect=ConnectionError(), ): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) assert entry.state == ENTRY_STATE_SETUP_RETRY
[ "async", "def", "test_config_not_ready", "(", "hass", ")", ":", "entry", "=", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "title", "=", "\"Home\"", ",", "unique_id", "=", "123", ",", "data", "=", "{", "\"station_id\"", ":", "123", ",", "\"name\"", ":", "\"Home\"", "}", ",", ")", "with", "patch", "(", "\"homeassistant.components.gios.Gios._get_stations\"", ",", "side_effect", "=", "ConnectionError", "(", ")", ",", ")", ":", "entry", ".", "add_to_hass", "(", "hass", ")", "await", "hass", ".", "config_entries", ".", "async_setup", "(", "entry", ".", "entry_id", ")", "assert", "entry", ".", "state", "==", "ENTRY_STATE_SETUP_RETRY" ]
[ 24, 0 ]
[ 39, 53 ]
python
en
['en', 'en', 'en']
True
test_unload_entry
(hass)
Test successful unload of entry.
Test successful unload of entry.
async def test_unload_entry(hass): """Test successful unload of entry.""" entry = await init_integration(hass) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert entry.state == ENTRY_STATE_LOADED assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() assert entry.state == ENTRY_STATE_NOT_LOADED assert not hass.data.get(DOMAIN)
[ "async", "def", "test_unload_entry", "(", "hass", ")", ":", "entry", "=", "await", "init_integration", "(", "hass", ")", "assert", "len", "(", "hass", ".", "config_entries", ".", "async_entries", "(", "DOMAIN", ")", ")", "==", "1", "assert", "entry", ".", "state", "==", "ENTRY_STATE_LOADED", "assert", "await", "hass", ".", "config_entries", ".", "async_unload", "(", "entry", ".", "entry_id", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "entry", ".", "state", "==", "ENTRY_STATE_NOT_LOADED", "assert", "not", "hass", ".", "data", ".", "get", "(", "DOMAIN", ")" ]
[ 42, 0 ]
[ 53, 36 ]
python
en
['en', 'en', 'en']
True
async_setup_platform
( hass: HomeAssistant, config: dict, add_entities: Callable, discovery_info=None )
Convert old style file configs to new style configs.
Convert old style file configs to new style configs.
async def async_setup_platform( hass: HomeAssistant, config: dict, add_entities: Callable, discovery_info=None ) -> None: """Convert old style file configs to new style configs.""" hass.async_create_task( hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=config ) )
[ "async", "def", "async_setup_platform", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "dict", ",", "add_entities", ":", "Callable", ",", "discovery_info", "=", "None", ")", "->", "None", ":", "hass", ".", "async_create_task", "(", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "SOURCE_IMPORT", "}", ",", "data", "=", "config", ")", ")" ]
[ 49, 0 ]
[ 57, 5 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable[[List[Entity], Optional[bool]], None], )
Set up the config entry.
Set up the config entry.
async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable[[List[Entity], Optional[bool]], None], ) -> None: """Set up the config entry.""" data_update_coordinator = get_data_update_coordinator(hass, config_entry) async_add_entities( [ DeviceCover(config_entry, data_update_coordinator, door) for door in get_configured_doors(data_update_coordinator.data) ] )
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistant", ",", "config_entry", ":", "ConfigEntry", ",", "async_add_entities", ":", "Callable", "[", "[", "List", "[", "Entity", "]", ",", "Optional", "[", "bool", "]", "]", ",", "None", "]", ",", ")", "->", "None", ":", "data_update_coordinator", "=", "get_data_update_coordinator", "(", "hass", ",", "config_entry", ")", "async_add_entities", "(", "[", "DeviceCover", "(", "config_entry", ",", "data_update_coordinator", ",", "door", ")", "for", "door", "in", "get_configured_doors", "(", "data_update_coordinator", ".", "data", ")", "]", ")" ]
[ 60, 0 ]
[ 73, 5 ]
python
en
['en', 'en', 'en']
True
DeviceCover.__init__
( self, config_entry: ConfigEntry, data_update_coordinator: DeviceDataUpdateCoordinator, door: AbstractDoor, )
Initialize the object.
Initialize the object.
def __init__( self, config_entry: ConfigEntry, data_update_coordinator: DeviceDataUpdateCoordinator, door: AbstractDoor, ) -> None: """Initialize the object.""" super().__init__(data_update_coordinator) self._config_entry = config_entry self._door = door self._api = data_update_coordinator.api self._unique_id = cover_unique_id(config_entry, door) self._is_available = True
[ "def", "__init__", "(", "self", ",", "config_entry", ":", "ConfigEntry", ",", "data_update_coordinator", ":", "DeviceDataUpdateCoordinator", ",", "door", ":", "AbstractDoor", ",", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "data_update_coordinator", ")", "self", ".", "_config_entry", "=", "config_entry", "self", ".", "_door", "=", "door", "self", ".", "_api", "=", "data_update_coordinator", ".", "api", "self", ".", "_unique_id", "=", "cover_unique_id", "(", "config_entry", ",", "door", ")", "self", ".", "_is_available", "=", "True" ]
[ 79, 4 ]
[ 91, 33 ]
python
en
['en', 'en', 'en']
True
DeviceCover.unique_id
(self)
Return a unique ID.
Return a unique ID.
def unique_id(self) -> Optional[str]: """Return a unique ID.""" return self._unique_id
[ "def", "unique_id", "(", "self", ")", "->", "Optional", "[", "str", "]", ":", "return", "self", ".", "_unique_id" ]
[ 94, 4 ]
[ 96, 30 ]
python
ca
['fr', 'ca', 'en']
False
DeviceCover.name
(self)
Return the name of the door.
Return the name of the door.
def name(self): """Return the name of the door.""" return self._get_door().name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_get_door", "(", ")", ".", "name" ]
[ 99, 4 ]
[ 101, 36 ]
python
en
['en', 'nl', 'en']
True
DeviceCover.is_closed
(self)
Return true if cover is closed, else False.
Return true if cover is closed, else False.
def is_closed(self): """Return true if cover is closed, else False.""" door = self._get_door() if door.status == DoorStatus.OPENED: return False if door.status == DoorStatus.CLOSED: return True return None
[ "def", "is_closed", "(", "self", ")", ":", "door", "=", "self", ".", "_get_door", "(", ")", "if", "door", ".", "status", "==", "DoorStatus", ".", "OPENED", ":", "return", "False", "if", "door", ".", "status", "==", "DoorStatus", ".", "CLOSED", ":", "return", "True", "return", "None" ]
[ 104, 4 ]
[ 113, 19 ]
python
en
['en', 'en', 'en']
True
DeviceCover.device_class
(self)
Return the class of this device, from component DEVICE_CLASSES.
Return the class of this device, from component DEVICE_CLASSES.
def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" door = self._get_door() if door.gate: return DEVICE_CLASS_GATE return DEVICE_CLASS_GARAGE
[ "def", "device_class", "(", "self", ")", ":", "door", "=", "self", ".", "_get_door", "(", ")", "if", "door", ".", "gate", ":", "return", "DEVICE_CLASS_GATE", "return", "DEVICE_CLASS_GARAGE" ]
[ 116, 4 ]
[ 122, 34 ]
python
en
['en', 'en', 'en']
True
DeviceCover.supported_features
(self)
Flag supported features.
Flag supported features.
def supported_features(self): """Flag supported features.""" return SUPPORT_OPEN | SUPPORT_CLOSE
[ "def", "supported_features", "(", "self", ")", ":", "return", "SUPPORT_OPEN", "|", "SUPPORT_CLOSE" ]
[ 125, 4 ]
[ 127, 43 ]
python
en
['da', 'en', 'en']
True
DeviceCover.async_open_cover
(self, **kwargs)
Open the door.
Open the door.
async def async_open_cover(self, **kwargs): """Open the door.""" await self.hass.async_add_executor_job( self._api.open_door, self._get_door().door_id )
[ "async", "def", "async_open_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "self", ".", "_api", ".", "open_door", ",", "self", ".", "_get_door", "(", ")", ".", "door_id", ")" ]
[ 129, 4 ]
[ 133, 9 ]
python
en
['en', 'nl', 'en']
True
DeviceCover.async_close_cover
(self, **kwargs)
Close the door.
Close the door.
async def async_close_cover(self, **kwargs): """Close the door.""" await self.hass.async_add_executor_job( self._api.close_door, self._get_door().door_id )
[ "async", "def", "async_close_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "self", ".", "_api", ".", "close_door", ",", "self", ".", "_get_door", "(", ")", ".", "door_id", ")" ]
[ 135, 4 ]
[ 139, 9 ]
python
en
['en', 'nl', 'en']
True
DeviceCover.state_attributes
(self)
Return the state attributes.
Return the state attributes.
def state_attributes(self): """Return the state attributes.""" attrs = super().state_attributes attrs["door_id"] = self._get_door().door_id return attrs
[ "def", "state_attributes", "(", "self", ")", ":", "attrs", "=", "super", "(", ")", ".", "state_attributes", "attrs", "[", "\"door_id\"", "]", "=", "self", ".", "_get_door", "(", ")", ".", "door_id", "return", "attrs" ]
[ 142, 4 ]
[ 146, 20 ]
python
en
['en', 'en', 'en']
True
DeviceCover.device_info
(self)
Device info for the controller.
Device info for the controller.
def device_info(self): """Device info for the controller.""" data = self.coordinator.data return { "identifiers": {(DOMAIN, self._config_entry.unique_id)}, "name": self._config_entry.title, "manufacturer": MANUFACTURER, "model": data.model, "sw_version": data.firmwareversion, }
[ "def", "device_info", "(", "self", ")", ":", "data", "=", "self", ".", "coordinator", ".", "data", "return", "{", "\"identifiers\"", ":", "{", "(", "DOMAIN", ",", "self", ".", "_config_entry", ".", "unique_id", ")", "}", ",", "\"name\"", ":", "self", ".", "_config_entry", ".", "title", ",", "\"manufacturer\"", ":", "MANUFACTURER", ",", "\"model\"", ":", "data", ".", "model", ",", "\"sw_version\"", ":", "data", ".", "firmwareversion", ",", "}" ]
[ 154, 4 ]
[ 163, 9 ]
python
en
['en', 'en', 'en']
True
load_tf_weights_in_openai_gpt
(model, config, openai_checkpoint_folder_path)
Load tf pre-trained weights in a pytorch model (from NumPy arrays here)
Load tf pre-trained weights in a pytorch model (from NumPy arrays here)
def load_tf_weights_in_openai_gpt(model, config, openai_checkpoint_folder_path): """Load tf pre-trained weights in a pytorch model (from NumPy arrays here)""" import re import numpy as np if ".ckpt" in openai_checkpoint_folder_path: openai_checkpoint_folder_path = os.path.dirname(openai_checkpoint_folder_path) logger.info("Loading weights from {}".format(openai_checkpoint_folder_path)) with open(openai_checkpoint_folder_path + "/parameters_names.json", "r", encoding="utf-8") as names_handle: names = json.load(names_handle) with open(openai_checkpoint_folder_path + "/params_shapes.json", "r", encoding="utf-8") as shapes_handle: shapes = json.load(shapes_handle) offsets = np.cumsum([np.prod(shape) for shape in shapes]) init_params = [np.load(openai_checkpoint_folder_path + "/params_{}.npy".format(n)) for n in range(10)] init_params = np.split(np.concatenate(init_params, 0), offsets)[:-1] init_params = [param.reshape(shape) for param, shape in zip(init_params, shapes)] # This was used when we had a single embedding matrix for positions and tokens # init_params[0] = np.concatenate([init_params[1], init_params[0]], 0) # del init_params[1] init_params = [arr.squeeze() for arr in init_params] try: assert model.tokens_embed.weight.shape == init_params[1].shape assert model.positions_embed.weight.shape == init_params[0].shape except AssertionError as e: e.args += (model.tokens_embed.weight.shape, init_params[1].shape) e.args += (model.positions_embed.weight.shape, init_params[0].shape) raise model.tokens_embed.weight.data = torch.from_numpy(init_params[1]) model.positions_embed.weight.data = torch.from_numpy(init_params[0]) names.pop(0) # Pop position and token embedding arrays init_params.pop(0) init_params.pop(0) for name, array in zip(names, init_params): # names[1:n_transfer], init_params[1:n_transfer]): name = name[6:] # skip "model/" assert name[-2:] == ":0" name = name[:-2] name = name.split("/") pointer = model for m_name in name: if re.fullmatch(r"[A-Za-z]+\d+", m_name): scope_names = re.split(r"(\d+)", m_name) else: scope_names = [m_name] if scope_names[0] == "g": pointer = getattr(pointer, "weight") elif scope_names[0] == "b": pointer = getattr(pointer, "bias") elif scope_names[0] == "w": pointer = getattr(pointer, "weight") else: pointer = getattr(pointer, scope_names[0]) if len(scope_names) >= 2: num = int(scope_names[1]) pointer = pointer[num] try: assert ( pointer.shape == array.shape ), f"Pointer shape {pointer.shape} and array shape {array.shape} mismatched" except AssertionError as e: e.args += (pointer.shape, array.shape) raise try: assert ( pointer.shape == array.shape ), f"Pointer shape {pointer.shape} and array shape {array.shape} mismatched" except AssertionError as e: e.args += (pointer.shape, array.shape) raise logger.info("Initialize PyTorch weight {}".format(name)) pointer.data = torch.from_numpy(array) return model
[ "def", "load_tf_weights_in_openai_gpt", "(", "model", ",", "config", ",", "openai_checkpoint_folder_path", ")", ":", "import", "re", "import", "numpy", "as", "np", "if", "\".ckpt\"", "in", "openai_checkpoint_folder_path", ":", "openai_checkpoint_folder_path", "=", "os", ".", "path", ".", "dirname", "(", "openai_checkpoint_folder_path", ")", "logger", ".", "info", "(", "\"Loading weights from {}\"", ".", "format", "(", "openai_checkpoint_folder_path", ")", ")", "with", "open", "(", "openai_checkpoint_folder_path", "+", "\"/parameters_names.json\"", ",", "\"r\"", ",", "encoding", "=", "\"utf-8\"", ")", "as", "names_handle", ":", "names", "=", "json", ".", "load", "(", "names_handle", ")", "with", "open", "(", "openai_checkpoint_folder_path", "+", "\"/params_shapes.json\"", ",", "\"r\"", ",", "encoding", "=", "\"utf-8\"", ")", "as", "shapes_handle", ":", "shapes", "=", "json", ".", "load", "(", "shapes_handle", ")", "offsets", "=", "np", ".", "cumsum", "(", "[", "np", ".", "prod", "(", "shape", ")", "for", "shape", "in", "shapes", "]", ")", "init_params", "=", "[", "np", ".", "load", "(", "openai_checkpoint_folder_path", "+", "\"/params_{}.npy\"", ".", "format", "(", "n", ")", ")", "for", "n", "in", "range", "(", "10", ")", "]", "init_params", "=", "np", ".", "split", "(", "np", ".", "concatenate", "(", "init_params", ",", "0", ")", ",", "offsets", ")", "[", ":", "-", "1", "]", "init_params", "=", "[", "param", ".", "reshape", "(", "shape", ")", "for", "param", ",", "shape", "in", "zip", "(", "init_params", ",", "shapes", ")", "]", "# This was used when we had a single embedding matrix for positions and tokens", "# init_params[0] = np.concatenate([init_params[1], init_params[0]], 0)", "# del init_params[1]", "init_params", "=", "[", "arr", ".", "squeeze", "(", ")", "for", "arr", "in", "init_params", "]", "try", ":", "assert", "model", ".", "tokens_embed", ".", "weight", ".", "shape", "==", "init_params", "[", "1", "]", ".", "shape", "assert", "model", ".", "positions_embed", ".", "weight", ".", "shape", "==", "init_params", "[", "0", "]", ".", "shape", "except", "AssertionError", "as", "e", ":", "e", ".", "args", "+=", "(", "model", ".", "tokens_embed", ".", "weight", ".", "shape", ",", "init_params", "[", "1", "]", ".", "shape", ")", "e", ".", "args", "+=", "(", "model", ".", "positions_embed", ".", "weight", ".", "shape", ",", "init_params", "[", "0", "]", ".", "shape", ")", "raise", "model", ".", "tokens_embed", ".", "weight", ".", "data", "=", "torch", ".", "from_numpy", "(", "init_params", "[", "1", "]", ")", "model", ".", "positions_embed", ".", "weight", ".", "data", "=", "torch", ".", "from_numpy", "(", "init_params", "[", "0", "]", ")", "names", ".", "pop", "(", "0", ")", "# Pop position and token embedding arrays", "init_params", ".", "pop", "(", "0", ")", "init_params", ".", "pop", "(", "0", ")", "for", "name", ",", "array", "in", "zip", "(", "names", ",", "init_params", ")", ":", "# names[1:n_transfer], init_params[1:n_transfer]):", "name", "=", "name", "[", "6", ":", "]", "# skip \"model/\"", "assert", "name", "[", "-", "2", ":", "]", "==", "\":0\"", "name", "=", "name", "[", ":", "-", "2", "]", "name", "=", "name", ".", "split", "(", "\"/\"", ")", "pointer", "=", "model", "for", "m_name", "in", "name", ":", "if", "re", ".", "fullmatch", "(", "r\"[A-Za-z]+\\d+\"", ",", "m_name", ")", ":", "scope_names", "=", "re", ".", "split", "(", "r\"(\\d+)\"", ",", "m_name", ")", "else", ":", "scope_names", "=", "[", "m_name", "]", "if", "scope_names", "[", "0", "]", "==", "\"g\"", ":", "pointer", "=", "getattr", "(", "pointer", ",", "\"weight\"", ")", "elif", "scope_names", "[", "0", "]", "==", "\"b\"", ":", "pointer", "=", "getattr", "(", "pointer", ",", "\"bias\"", ")", "elif", "scope_names", "[", "0", "]", "==", "\"w\"", ":", "pointer", "=", "getattr", "(", "pointer", ",", "\"weight\"", ")", "else", ":", "pointer", "=", "getattr", "(", "pointer", ",", "scope_names", "[", "0", "]", ")", "if", "len", "(", "scope_names", ")", ">=", "2", ":", "num", "=", "int", "(", "scope_names", "[", "1", "]", ")", "pointer", "=", "pointer", "[", "num", "]", "try", ":", "assert", "(", "pointer", ".", "shape", "==", "array", ".", "shape", ")", ",", "f\"Pointer shape {pointer.shape} and array shape {array.shape} mismatched\"", "except", "AssertionError", "as", "e", ":", "e", ".", "args", "+=", "(", "pointer", ".", "shape", ",", "array", ".", "shape", ")", "raise", "try", ":", "assert", "(", "pointer", ".", "shape", "==", "array", ".", "shape", ")", ",", "f\"Pointer shape {pointer.shape} and array shape {array.shape} mismatched\"", "except", "AssertionError", "as", "e", ":", "e", ".", "args", "+=", "(", "pointer", ".", "shape", ",", "array", ".", "shape", ")", "raise", "logger", ".", "info", "(", "\"Initialize PyTorch weight {}\"", ".", "format", "(", "name", ")", ")", "pointer", ".", "data", "=", "torch", ".", "from_numpy", "(", "array", ")", "return", "model" ]
[ 60, 0 ]
[ 138, 16 ]
python
en
['en', 'en', 'en']
True
OpenAIGPTPreTrainedModel._init_weights
(self, module)
Initialize the weights.
Initialize the weights.
def _init_weights(self, module): """Initialize the weights.""" if isinstance(module, (nn.Linear, Conv1D)): # Slightly different from the TF version which uses truncated_normal for initialization # cf https://github.com/pytorch/pytorch/pull/5617 module.weight.data.normal_(mean=0.0, std=self.config.initializer_range) if module.bias is not None: module.bias.data.zero_() elif isinstance(module, nn.Embedding): module.weight.data.normal_(mean=0.0, std=self.config.initializer_range) if module.padding_idx is not None: module.weight.data[module.padding_idx].zero_() elif isinstance(module, nn.LayerNorm): module.bias.data.zero_() module.weight.data.fill_(1.0)
[ "def", "_init_weights", "(", "self", ",", "module", ")", ":", "if", "isinstance", "(", "module", ",", "(", "nn", ".", "Linear", ",", "Conv1D", ")", ")", ":", "# Slightly different from the TF version which uses truncated_normal for initialization", "# cf https://github.com/pytorch/pytorch/pull/5617", "module", ".", "weight", ".", "data", ".", "normal_", "(", "mean", "=", "0.0", ",", "std", "=", "self", ".", "config", ".", "initializer_range", ")", "if", "module", ".", "bias", "is", "not", "None", ":", "module", ".", "bias", ".", "data", ".", "zero_", "(", ")", "elif", "isinstance", "(", "module", ",", "nn", ".", "Embedding", ")", ":", "module", ".", "weight", ".", "data", ".", "normal_", "(", "mean", "=", "0.0", ",", "std", "=", "self", ".", "config", ".", "initializer_range", ")", "if", "module", ".", "padding_idx", "is", "not", "None", ":", "module", ".", "weight", ".", "data", "[", "module", ".", "padding_idx", "]", ".", "zero_", "(", ")", "elif", "isinstance", "(", "module", ",", "nn", ".", "LayerNorm", ")", ":", "module", ".", "bias", ".", "data", ".", "zero_", "(", ")", "module", ".", "weight", ".", "data", ".", "fill_", "(", "1.0", ")" ]
[ 284, 4 ]
[ 298, 41 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass: HomeAssistantType, config: ConfigType)
Set up the component.
Set up the component.
async def async_setup(hass: HomeAssistantType, config: ConfigType): """Set up the component.""" hass.data[DOMAIN_DATA_ENTRIES] = {} hass.data[DOMAIN_DATA_TASKS] = {} async def _stop(_): asyncio.gather( *[_await_cancel(task) for task in hass.data[DOMAIN_DATA_TASKS].values()] ) hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _stop) return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistantType", ",", "config", ":", "ConfigType", ")", ":", "hass", ".", "data", "[", "DOMAIN_DATA_ENTRIES", "]", "=", "{", "}", "hass", ".", "data", "[", "DOMAIN_DATA_TASKS", "]", "=", "{", "}", "async", "def", "_stop", "(", "_", ")", ":", "asyncio", ".", "gather", "(", "*", "[", "_await_cancel", "(", "task", ")", "for", "task", "in", "hass", ".", "data", "[", "DOMAIN_DATA_TASKS", "]", ".", "values", "(", ")", "]", ")", "hass", ".", "bus", ".", "async_listen_once", "(", "EVENT_HOMEASSISTANT_STOP", ",", "_stop", ")", "return", "True" ]
[ 36, 0 ]
[ 48, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass: HomeAssistantType, entry: config_entries.ConfigEntry)
Set up config entry.
Set up config entry.
async def async_setup_entry(hass: HomeAssistantType, entry: config_entries.ConfigEntry): """Set up config entry.""" entries = hass.data[DOMAIN_DATA_ENTRIES] tasks = hass.data[DOMAIN_DATA_TASKS] client = Client(entry.data[CONF_HOST], entry.data[CONF_PORT]) entries[entry.entry_id] = client task = asyncio.create_task(_run_client(hass, client, DEFAULT_SCAN_INTERVAL)) tasks[entry.entry_id] = task hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, "media_player") ) return True
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistantType", ",", "entry", ":", "config_entries", ".", "ConfigEntry", ")", ":", "entries", "=", "hass", ".", "data", "[", "DOMAIN_DATA_ENTRIES", "]", "tasks", "=", "hass", ".", "data", "[", "DOMAIN_DATA_TASKS", "]", "client", "=", "Client", "(", "entry", ".", "data", "[", "CONF_HOST", "]", ",", "entry", ".", "data", "[", "CONF_PORT", "]", ")", "entries", "[", "entry", ".", "entry_id", "]", "=", "client", "task", "=", "asyncio", ".", "create_task", "(", "_run_client", "(", "hass", ",", "client", ",", "DEFAULT_SCAN_INTERVAL", ")", ")", "tasks", "[", "entry", ".", "entry_id", "]", "=", "task", "hass", ".", "async_create_task", "(", "hass", ".", "config_entries", ".", "async_forward_entry_setup", "(", "entry", ",", "\"media_player\"", ")", ")", "return", "True" ]
[ 51, 0 ]
[ 66, 15 ]
python
en
['en', 'en', 'en']
True
async_unload_entry
(hass, entry)
Cleanup before removing config entry.
Cleanup before removing config entry.
async def async_unload_entry(hass, entry): """Cleanup before removing config entry.""" await hass.config_entries.async_forward_entry_unload(entry, "media_player") task = hass.data[DOMAIN_DATA_TASKS].pop(entry.entry_id) await _await_cancel(task) hass.data[DOMAIN_DATA_ENTRIES].pop(entry.entry_id) return True
[ "async", "def", "async_unload_entry", "(", "hass", ",", "entry", ")", ":", "await", "hass", ".", "config_entries", ".", "async_forward_entry_unload", "(", "entry", ",", "\"media_player\"", ")", "task", "=", "hass", ".", "data", "[", "DOMAIN_DATA_TASKS", "]", ".", "pop", "(", "entry", ".", "entry_id", ")", "await", "_await_cancel", "(", "task", ")", "hass", ".", "data", "[", "DOMAIN_DATA_ENTRIES", "]", ".", "pop", "(", "entry", ".", "entry_id", ")", "return", "True" ]
[ 69, 0 ]
[ 78, 15 ]
python
en
['en', 'en', 'en']
True
setup
(hass, config)
Set up the Hunter Hydrawise component.
Set up the Hunter Hydrawise component.
def setup(hass, config): """Set up the Hunter Hydrawise component.""" conf = config[DOMAIN] access_token = conf[CONF_ACCESS_TOKEN] scan_interval = conf.get(CONF_SCAN_INTERVAL) try: hydrawise = Hydrawiser(user_token=access_token) hass.data[DATA_HYDRAWISE] = HydrawiseHub(hydrawise) except (ConnectTimeout, HTTPError) as ex: _LOGGER.error("Unable to connect to Hydrawise cloud service: %s", str(ex)) hass.components.persistent_notification.create( f"Error: {ex}<br />You will need to restart hass after fixing.", title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID, ) return False def hub_refresh(event_time): """Call Hydrawise hub to refresh information.""" _LOGGER.debug("Updating Hydrawise Hub component") hass.data[DATA_HYDRAWISE].data.update_controller_info() dispatcher_send(hass, SIGNAL_UPDATE_HYDRAWISE) # Call the Hydrawise API to refresh updates track_time_interval(hass, hub_refresh, scan_interval) return True
[ "def", "setup", "(", "hass", ",", "config", ")", ":", "conf", "=", "config", "[", "DOMAIN", "]", "access_token", "=", "conf", "[", "CONF_ACCESS_TOKEN", "]", "scan_interval", "=", "conf", ".", "get", "(", "CONF_SCAN_INTERVAL", ")", "try", ":", "hydrawise", "=", "Hydrawiser", "(", "user_token", "=", "access_token", ")", "hass", ".", "data", "[", "DATA_HYDRAWISE", "]", "=", "HydrawiseHub", "(", "hydrawise", ")", "except", "(", "ConnectTimeout", ",", "HTTPError", ")", "as", "ex", ":", "_LOGGER", ".", "error", "(", "\"Unable to connect to Hydrawise cloud service: %s\"", ",", "str", "(", "ex", ")", ")", "hass", ".", "components", ".", "persistent_notification", ".", "create", "(", "f\"Error: {ex}<br />You will need to restart hass after fixing.\"", ",", "title", "=", "NOTIFICATION_TITLE", ",", "notification_id", "=", "NOTIFICATION_ID", ",", ")", "return", "False", "def", "hub_refresh", "(", "event_time", ")", ":", "\"\"\"Call Hydrawise hub to refresh information.\"\"\"", "_LOGGER", ".", "debug", "(", "\"Updating Hydrawise Hub component\"", ")", "hass", ".", "data", "[", "DATA_HYDRAWISE", "]", ".", "data", ".", "update_controller_info", "(", ")", "dispatcher_send", "(", "hass", ",", "SIGNAL_UPDATE_HYDRAWISE", ")", "# Call the Hydrawise API to refresh updates", "track_time_interval", "(", "hass", ",", "hub_refresh", ",", "scan_interval", ")", "return", "True" ]
[ 79, 0 ]
[ 106, 15 ]
python
en
['en', 'en', 'en']
True
HydrawiseHub.__init__
(self, data)
Initialize the entity.
Initialize the entity.
def __init__(self, data): """Initialize the entity.""" self.data = data
[ "def", "__init__", "(", "self", ",", "data", ")", ":", "self", ".", "data", "=", "data" ]
[ 112, 4 ]
[ 114, 24 ]
python
en
['en', 'en', 'en']
True
HydrawiseEntity.__init__
(self, data, sensor_type)
Initialize the Hydrawise entity.
Initialize the Hydrawise entity.
def __init__(self, data, sensor_type): """Initialize the Hydrawise entity.""" self.data = data self._sensor_type = sensor_type self._name = f"{self.data['name']} {DEVICE_MAP[self._sensor_type][DEVICE_MAP_INDEX.index('KEY_INDEX')]}" self._state = None
[ "def", "__init__", "(", "self", ",", "data", ",", "sensor_type", ")", ":", "self", ".", "data", "=", "data", "self", ".", "_sensor_type", "=", "sensor_type", "self", ".", "_name", "=", "f\"{self.data['name']} {DEVICE_MAP[self._sensor_type][DEVICE_MAP_INDEX.index('KEY_INDEX')]}\"", "self", ".", "_state", "=", "None" ]
[ 120, 4 ]
[ 125, 26 ]
python
en
['en', 'en', 'en']
True
HydrawiseEntity.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 128, 4 ]
[ 130, 25 ]
python
en
['en', 'mi', 'en']
True
HydrawiseEntity.async_added_to_hass
(self)
Register callbacks.
Register callbacks.
async def async_added_to_hass(self): """Register callbacks.""" self.async_on_remove( async_dispatcher_connect( self.hass, SIGNAL_UPDATE_HYDRAWISE, self._update_callback ) )
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "self", ".", "async_on_remove", "(", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "SIGNAL_UPDATE_HYDRAWISE", ",", "self", ".", "_update_callback", ")", ")" ]
[ 132, 4 ]
[ 138, 9 ]
python
en
['en', 'no', 'en']
False
HydrawiseEntity._update_callback
(self)
Call update method.
Call update method.
def _update_callback(self): """Call update method.""" self.async_schedule_update_ha_state(True)
[ "def", "_update_callback", "(", "self", ")", ":", "self", ".", "async_schedule_update_ha_state", "(", "True", ")" ]
[ 141, 4 ]
[ 143, 49 ]
python
en
['en', 'sn', 'en']
True
HydrawiseEntity.unit_of_measurement
(self)
Return the units of measurement.
Return the units of measurement.
def unit_of_measurement(self): """Return the units of measurement.""" return DEVICE_MAP[self._sensor_type][ DEVICE_MAP_INDEX.index("UNIT_OF_MEASURE_INDEX") ]
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "DEVICE_MAP", "[", "self", ".", "_sensor_type", "]", "[", "DEVICE_MAP_INDEX", ".", "index", "(", "\"UNIT_OF_MEASURE_INDEX\"", ")", "]" ]
[ 146, 4 ]
[ 150, 9 ]
python
en
['en', 'bg', 'en']
True
HydrawiseEntity.device_state_attributes
(self)
Return the state attributes.
Return the state attributes.
def device_state_attributes(self): """Return the state attributes.""" return {ATTR_ATTRIBUTION: ATTRIBUTION, "identifier": self.data.get("relay")}
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "{", "ATTR_ATTRIBUTION", ":", "ATTRIBUTION", ",", "\"identifier\"", ":", "self", ".", "data", ".", "get", "(", "\"relay\"", ")", "}" ]
[ 153, 4 ]
[ 155, 84 ]
python
en
['en', 'en', 'en']
True
HydrawiseEntity.device_class
(self)
Return the device class of the sensor type.
Return the device class of the sensor type.
def device_class(self): """Return the device class of the sensor type.""" return DEVICE_MAP[self._sensor_type][ DEVICE_MAP_INDEX.index("DEVICE_CLASS_INDEX") ]
[ "def", "device_class", "(", "self", ")", ":", "return", "DEVICE_MAP", "[", "self", ".", "_sensor_type", "]", "[", "DEVICE_MAP_INDEX", ".", "index", "(", "\"DEVICE_CLASS_INDEX\"", ")", "]" ]
[ 158, 4 ]
[ 162, 9 ]
python
en
['en', 'en', 'en']
True
HydrawiseEntity.icon
(self)
Return the icon to use in the frontend, if any.
Return the icon to use in the frontend, if any.
def icon(self): """Return the icon to use in the frontend, if any.""" return DEVICE_MAP[self._sensor_type][DEVICE_MAP_INDEX.index("ICON_INDEX")]
[ "def", "icon", "(", "self", ")", ":", "return", "DEVICE_MAP", "[", "self", ".", "_sensor_type", "]", "[", "DEVICE_MAP_INDEX", ".", "index", "(", "\"ICON_INDEX\"", ")", "]" ]
[ 165, 4 ]
[ 167, 82 ]
python
en
['en', 'en', 'en']
True
predict
(parameters_value, regressor_gp)
Predict by Gaussian Process Model
Predict by Gaussian Process Model
def predict(parameters_value, regressor_gp): ''' Predict by Gaussian Process Model ''' parameters_value = numpy.array(parameters_value).reshape(-1, len(parameters_value)) mu, sigma = regressor_gp.predict(parameters_value, return_std=True) return mu[0], sigma[0]
[ "def", "predict", "(", "parameters_value", ",", "regressor_gp", ")", ":", "parameters_value", "=", "numpy", ".", "array", "(", "parameters_value", ")", ".", "reshape", "(", "-", "1", ",", "len", "(", "parameters_value", ")", ")", "mu", ",", "sigma", "=", "regressor_gp", ".", "predict", "(", "parameters_value", ",", "return_std", "=", "True", ")", "return", "mu", "[", "0", "]", ",", "sigma", "[", "0", "]" ]
[ 11, 0 ]
[ 18, 26 ]
python
en
['en', 'error', 'th']
False
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up the switch platform.
Set up the switch platform.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the switch platform.""" switches = [] processor = hass.data[DOMAIN] for switch_type in config[CONF_MONITORED_CONDITIONS]: switches.append(AquaLogicSwitch(processor, switch_type)) async_add_entities(switches)
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "switches", "=", "[", "]", "processor", "=", "hass", ".", "data", "[", "DOMAIN", "]", "for", "switch_type", "in", "config", "[", "CONF_MONITORED_CONDITIONS", "]", ":", "switches", ".", "append", "(", "AquaLogicSwitch", "(", "processor", ",", "switch_type", ")", ")", "async_add_entities", "(", "switches", ")" ]
[ 32, 0 ]
[ 40, 32 ]
python
en
['en', 'cs', 'en']
True
AquaLogicSwitch.__init__
(self, processor, switch_type)
Initialize switch.
Initialize switch.
def __init__(self, processor, switch_type): """Initialize switch.""" self._processor = processor self._type = switch_type self._state_name = { "lights": States.LIGHTS, "filter": States.FILTER, "filter_low_speed": States.FILTER_LOW_SPEED, "aux_1": States.AUX_1, "aux_2": States.AUX_2, "aux_3": States.AUX_3, "aux_4": States.AUX_4, "aux_5": States.AUX_5, "aux_6": States.AUX_6, "aux_7": States.AUX_7, }[switch_type]
[ "def", "__init__", "(", "self", ",", "processor", ",", "switch_type", ")", ":", "self", ".", "_processor", "=", "processor", "self", ".", "_type", "=", "switch_type", "self", ".", "_state_name", "=", "{", "\"lights\"", ":", "States", ".", "LIGHTS", ",", "\"filter\"", ":", "States", ".", "FILTER", ",", "\"filter_low_speed\"", ":", "States", ".", "FILTER_LOW_SPEED", ",", "\"aux_1\"", ":", "States", ".", "AUX_1", ",", "\"aux_2\"", ":", "States", ".", "AUX_2", ",", "\"aux_3\"", ":", "States", ".", "AUX_3", ",", "\"aux_4\"", ":", "States", ".", "AUX_4", ",", "\"aux_5\"", ":", "States", ".", "AUX_5", ",", "\"aux_6\"", ":", "States", ".", "AUX_6", ",", "\"aux_7\"", ":", "States", ".", "AUX_7", ",", "}", "[", "switch_type", "]" ]
[ 46, 4 ]
[ 61, 22 ]
python
en
['en', 'pl', 'en']
False
AquaLogicSwitch.name
(self)
Return the name of the switch.
Return the name of the switch.
def name(self): """Return the name of the switch.""" return f"AquaLogic {SWITCH_TYPES[self._type]}"
[ "def", "name", "(", "self", ")", ":", "return", "f\"AquaLogic {SWITCH_TYPES[self._type]}\"" ]
[ 64, 4 ]
[ 66, 54 ]
python
en
['en', 'en', 'en']
True
AquaLogicSwitch.should_poll
(self)
Return the polling state.
Return the polling state.
def should_poll(self): """Return the polling state.""" return False
[ "def", "should_poll", "(", "self", ")", ":", "return", "False" ]
[ 69, 4 ]
[ 71, 20 ]
python
en
['en', 'en', 'en']
True
AquaLogicSwitch.is_on
(self)
Return true if device is on.
Return true if device is on.
def is_on(self): """Return true if device is on.""" panel = self._processor.panel if panel is None: return False state = panel.get_state(self._state_name) return state
[ "def", "is_on", "(", "self", ")", ":", "panel", "=", "self", ".", "_processor", ".", "panel", "if", "panel", "is", "None", ":", "return", "False", "state", "=", "panel", ".", "get_state", "(", "self", ".", "_state_name", ")", "return", "state" ]
[ 74, 4 ]
[ 80, 20 ]
python
en
['en', 'fy', 'en']
True
AquaLogicSwitch.turn_on
(self, **kwargs)
Turn the device on.
Turn the device on.
def turn_on(self, **kwargs): """Turn the device on.""" panel = self._processor.panel if panel is None: return panel.set_state(self._state_name, True)
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "panel", "=", "self", ".", "_processor", ".", "panel", "if", "panel", "is", "None", ":", "return", "panel", ".", "set_state", "(", "self", ".", "_state_name", ",", "True", ")" ]
[ 82, 4 ]
[ 87, 47 ]
python
en
['en', 'en', 'en']
True
AquaLogicSwitch.turn_off
(self, **kwargs)
Turn the device off.
Turn the device off.
def turn_off(self, **kwargs): """Turn the device off.""" panel = self._processor.panel if panel is None: return panel.set_state(self._state_name, False)
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "panel", "=", "self", ".", "_processor", ".", "panel", "if", "panel", "is", "None", ":", "return", "panel", ".", "set_state", "(", "self", ".", "_state_name", ",", "False", ")" ]
[ 89, 4 ]
[ 94, 48 ]
python
en
['en', 'en', 'en']
True
AquaLogicSwitch.async_added_to_hass
(self)
Register callbacks.
Register callbacks.
async def async_added_to_hass(self): """Register callbacks.""" self.async_on_remove( self.hass.helpers.dispatcher.async_dispatcher_connect( UPDATE_TOPIC, self.async_write_ha_state ) )
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "self", ".", "async_on_remove", "(", "self", ".", "hass", ".", "helpers", ".", "dispatcher", ".", "async_dispatcher_connect", "(", "UPDATE_TOPIC", ",", "self", ".", "async_write_ha_state", ")", ")" ]
[ 96, 4 ]
[ 102, 9 ]
python
en
['en', 'no', 'en']
False
calls_fixture
(hass)
Track calls to a mock service.
Track calls to a mock service.
def calls_fixture(hass): """Track calls to a mock service.""" return async_mock_service(hass, "test", "automation")
[ "def", "calls_fixture", "(", "hass", ")", ":", "return", "async_mock_service", "(", "hass", ",", "\"test\"", ",", "\"automation\"", ")" ]
[ 29, 0 ]
[ 31, 57 ]
python
en
['en', 'en', 'en']
True
test_template_state_text
(hass, calls)
Test the state text of a template.
Test the state text of a template.
async def test_template_state_text(hass, calls): """Test the state text of a template.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ states.cover.test_state.state }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.async_set("cover.test_state", STATE_OPEN) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_OPEN state = hass.states.async_set("cover.test_state", STATE_CLOSED) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_CLOSED
[ "async", "def", "test_template_state_text", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ states.cover.test_state.state }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "async_set", "(", "\"cover.test_state\"", ",", "STATE_OPEN", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_OPEN", "state", "=", "hass", ".", "states", ".", "async_set", "(", "\"cover.test_state\"", ",", "STATE_CLOSED", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_CLOSED" ]
[ 34, 0 ]
[ 74, 38 ]
python
en
['en', 'en', 'en']
True
test_template_state_boolean
(hass, calls)
Test the value_template attribute.
Test the value_template attribute.
async def test_template_state_boolean(hass, calls): """Test the value_template attribute.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ 1 == 1 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_OPEN
[ "async", "def", "test_template_state_boolean", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ 1 == 1 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_OPEN" ]
[ 77, 0 ]
[ 108, 36 ]
python
en
['en', 'en', 'en']
True
test_template_position
(hass, calls)
Test the position_template attribute.
Test the position_template attribute.
async def test_template_position(hass, calls): """Test the position_template attribute.""" hass.states.async_set("cover.test", STATE_OPEN) with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ states.cover.test.attributes.position }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.async_set("cover.test", STATE_CLOSED) await hass.async_block_till_done() entity = hass.states.get("cover.test") attrs = {} attrs["position"] = 42 hass.states.async_set(entity.entity_id, entity.state, attributes=attrs) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") == 42.0 assert state.state == STATE_OPEN state = hass.states.async_set("cover.test", STATE_OPEN) await hass.async_block_till_done() entity = hass.states.get("cover.test") attrs["position"] = 0.0 hass.states.async_set(entity.entity_id, entity.state, attributes=attrs) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") == 0.0 assert state.state == STATE_CLOSED
[ "async", "def", "test_template_position", "(", "hass", ",", "calls", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"cover.test\"", ",", "STATE_OPEN", ")", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ states.cover.test.attributes.position }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "async_set", "(", "\"cover.test\"", ",", "STATE_CLOSED", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "entity", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test\"", ")", "attrs", "=", "{", "}", "attrs", "[", "\"position\"", "]", "=", "42", "hass", ".", "states", ".", "async_set", "(", "entity", ".", "entity_id", ",", "entity", ".", "state", ",", "attributes", "=", "attrs", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "==", "42.0", "assert", "state", ".", "state", "==", "STATE_OPEN", "state", "=", "hass", ".", "states", ".", "async_set", "(", "\"cover.test\"", ",", "STATE_OPEN", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "entity", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test\"", ")", "attrs", "[", "\"position\"", "]", "=", "0.0", "hass", ".", "states", ".", "async_set", "(", "entity", ".", "entity_id", ",", "entity", ".", "state", ",", "attributes", "=", "attrs", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "==", "0.0", "assert", "state", ".", "state", "==", "STATE_CLOSED" ]
[ 111, 0 ]
[ 164, 38 ]
python
en
['en', 'en', 'en']
True
test_template_tilt
(hass, calls)
Test the tilt_template attribute.
Test the tilt_template attribute.
async def test_template_tilt(hass, calls): """Test the tilt_template attribute.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ 1 == 1 }}", "tilt_template": "{{ 42 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") == 42.0
[ "async", "def", "test_template_tilt", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ 1 == 1 }}\"", ",", "\"tilt_template\"", ":", "\"{{ 42 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "==", "42.0" ]
[ 167, 0 ]
[ 199, 64 ]
python
en
['en', 'en', 'en']
True
test_template_out_of_bounds
(hass, calls)
Test template out-of-bounds condition.
Test template out-of-bounds condition.
async def test_template_out_of_bounds(hass, calls): """Test template out-of-bounds condition.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ -1 }}", "tilt_template": "{{ 110 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") is None assert state.attributes.get("current_position") is None
[ "async", "def", "test_template_out_of_bounds", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ -1 }}\"", ",", "\"tilt_template\"", ":", "\"{{ 110 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "is", "None", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "is", "None" ]
[ 202, 0 ]
[ 235, 59 ]
python
en
['en', 'en', 'en']
True
test_template_mutex
(hass, calls)
Test that only value or position template can be used.
Test that only value or position template can be used.
async def test_template_mutex(hass, calls): """Test that only value or position template can be used.""" with assert_setup_component(0, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ 1 == 1 }}", "position_template": "{{ 42 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, "icon_template": "{% if states.cover.test_state.state %}" "mdi:check" "{% endif %}", } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() assert hass.states.async_all() == []
[ "async", "def", "test_template_mutex", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "0", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ 1 == 1 }}\"", ",", "\"position_template\"", ":", "\"{{ 42 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"icon_template\"", ":", "\"{% if states.cover.test_state.state %}\"", "\"mdi:check\"", "\"{% endif %}\"", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "hass", ".", "states", ".", "async_all", "(", ")", "==", "[", "]" ]
[ 238, 0 ]
[ 272, 40 ]
python
en
['en', 'en', 'en']
True
test_template_open_or_position
(hass, caplog)
Test that at least one of open_cover or set_position is used.
Test that at least one of open_cover or set_position is used.
async def test_template_open_or_position(hass, caplog): """Test that at least one of open_cover or set_position is used.""" assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": {"test_template_cover": {"value_template": "{{ 1 == 1 }}"}}, } }, ) await hass.async_block_till_done() assert hass.states.async_all() == [] assert "Invalid config for [cover.template]" in caplog.text
[ "async", "def", "test_template_open_or_position", "(", "hass", ",", "caplog", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ 1 == 1 }}\"", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "hass", ".", "states", ".", "async_all", "(", ")", "==", "[", "]", "assert", "\"Invalid config for [cover.template]\"", "in", "caplog", ".", "text" ]
[ 275, 0 ]
[ 290, 63 ]
python
en
['en', 'en', 'en']
True
test_template_open_and_close
(hass, calls)
Test that if open_cover is specified, close_cover is too.
Test that if open_cover is specified, close_cover is too.
async def test_template_open_and_close(hass, calls): """Test that if open_cover is specified, close_cover is too.""" with assert_setup_component(0, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ 1 == 1 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() assert hass.states.async_all() == []
[ "async", "def", "test_template_open_and_close", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "0", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ 1 == 1 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "hass", ".", "states", ".", "async_all", "(", ")", "==", "[", "]" ]
[ 293, 0 ]
[ 319, 40 ]
python
en
['en', 'en', 'en']
True
test_template_non_numeric
(hass, calls)
Test that tilt_template values are numeric.
Test that tilt_template values are numeric.
async def test_template_non_numeric(hass, calls): """Test that tilt_template values are numeric.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ on }}", "tilt_template": "{% if states.cover.test_state.state %}" "on" "{% else %}" "off" "{% endif %}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") is None assert state.attributes.get("current_position") is None
[ "async", "def", "test_template_non_numeric", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ on }}\"", ",", "\"tilt_template\"", ":", "\"{% if states.cover.test_state.state %}\"", "\"on\"", "\"{% else %}\"", "\"off\"", "\"{% endif %}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "is", "None", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "is", "None" ]
[ 322, 0 ]
[ 359, 59 ]
python
en
['en', 'en', 'en']
True
test_open_action
(hass, calls)
Test the open_cover command.
Test the open_cover command.
async def test_open_action(hass, calls): """Test the open_cover command.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ 0 }}", "open_cover": {"service": "test.automation"}, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_CLOSED await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() assert len(calls) == 1
[ "async", "def", "test_open_action", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ 0 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_CLOSED", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_OPEN_COVER", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "calls", ")", "==", "1" ]
[ 362, 0 ]
[ 397, 26 ]
python
en
['en', 'en', 'en']
True
test_close_stop_action
(hass, calls)
Test the close-cover and stop_cover commands.
Test the close-cover and stop_cover commands.
async def test_close_stop_action(hass, calls): """Test the close-cover and stop_cover commands.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ 100 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": {"service": "test.automation"}, "stop_cover": {"service": "test.automation"}, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_OPEN await hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() await hass.services.async_call( DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() assert len(calls) == 2
[ "async", "def", "test_close_stop_action", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ 100 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", ",", "\"stop_cover\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_OPEN", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_CLOSE_COVER", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_STOP_COVER", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "calls", ")", "==", "2" ]
[ 400, 0 ]
[ 441, 26 ]
python
en
['en', 'en', 'en']
True
test_set_position
(hass, calls)
Test the set_position command.
Test the set_position command.
async def test_set_position(hass, calls): """Test the set_position command.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "input_number", {"input_number": {"test": {"min": "0", "max": "100", "initial": "42"}}}, ) assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ states.input_number.test.state | int }}", "set_cover_position": { "service": "input_number.set_value", "entity_id": "input_number.test", "data_template": {"value": "{{ position }}"}, }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.async_set("input_number.test", 42) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_OPEN await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") == 100.0 await hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") == 0.0 await hass.services.async_call( DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") == 100.0 await hass.services.async_call( DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") == 0.0 await hass.services.async_call( DOMAIN, SERVICE_SET_COVER_POSITION, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 25}, blocking=True, ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") == 25.0
[ "async", "def", "test_set_position", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"input_number\"", ",", "{", "\"input_number\"", ":", "{", "\"test\"", ":", "{", "\"min\"", ":", "\"0\"", ",", "\"max\"", ":", "\"100\"", ",", "\"initial\"", ":", "\"42\"", "}", "}", "}", ",", ")", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ states.input_number.test.state | int }}\"", ",", "\"set_cover_position\"", ":", "{", "\"service\"", ":", "\"input_number.set_value\"", ",", "\"entity_id\"", ":", "\"input_number.test\"", ",", "\"data_template\"", ":", "{", "\"value\"", ":", "\"{{ position }}\"", "}", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "async_set", "(", "\"input_number.test\"", ",", "42", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_OPEN", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_OPEN_COVER", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "==", "100.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_CLOSE_COVER", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "==", "0.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_TOGGLE", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "==", "100.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_TOGGLE", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "==", "0.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_SET_COVER_POSITION", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", ",", "ATTR_POSITION", ":", "25", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "==", "25.0" ]
[ 444, 0 ]
[ 517, 59 ]
python
en
['en', 'fr', 'en']
True
test_set_tilt_position
(hass, calls)
Test the set_tilt_position command.
Test the set_tilt_position command.
async def test_set_tilt_position(hass, calls): """Test the set_tilt_position command.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ 100 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, "set_cover_tilt_position": {"service": "test.automation"}, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() await hass.services.async_call( DOMAIN, SERVICE_SET_COVER_TILT_POSITION, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_TILT_POSITION: 42}, blocking=True, ) await hass.async_block_till_done() assert len(calls) == 1
[ "async", "def", "test_set_tilt_position", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ 100 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"set_cover_tilt_position\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_SET_COVER_TILT_POSITION", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", ",", "ATTR_TILT_POSITION", ":", "42", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "calls", ")", "==", "1" ]
[ 520, 0 ]
[ 559, 26 ]
python
en
['en', 'fr', 'en']
True
test_open_tilt_action
(hass, calls)
Test the open_cover_tilt command.
Test the open_cover_tilt command.
async def test_open_tilt_action(hass, calls): """Test the open_cover_tilt command.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ 100 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, "set_cover_tilt_position": {"service": "test.automation"}, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() assert len(calls) == 1
[ "async", "def", "test_open_tilt_action", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ 100 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"set_cover_tilt_position\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_OPEN_COVER_TILT", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "calls", ")", "==", "1" ]
[ 562, 0 ]
[ 598, 26 ]
python
en
['en', 'no', 'en']
True
test_close_tilt_action
(hass, calls)
Test the close_cover_tilt command.
Test the close_cover_tilt command.
async def test_close_tilt_action(hass, calls): """Test the close_cover_tilt command.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ 100 }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, "set_cover_tilt_position": {"service": "test.automation"}, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() await hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER_TILT, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() assert len(calls) == 1
[ "async", "def", "test_close_tilt_action", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ 100 }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"set_cover_tilt_position\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_CLOSE_COVER_TILT", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "calls", ")", "==", "1" ]
[ 601, 0 ]
[ 637, 26 ]
python
en
['en', 'fr', 'en']
True
test_set_position_optimistic
(hass, calls)
Test optimistic position mode.
Test optimistic position mode.
async def test_set_position_optimistic(hass, calls): """Test optimistic position mode.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "set_cover_position": {"service": "test.automation"} } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") is None await hass.services.async_call( DOMAIN, SERVICE_SET_COVER_POSITION, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 42}, blocking=True, ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_position") == 42.0 await hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_CLOSED await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_OPEN await hass.services.async_call( DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_CLOSED await hass.services.async_call( DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state == STATE_OPEN
[ "async", "def", "test_set_position_optimistic", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"set_cover_position\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "is", "None", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_SET_COVER_POSITION", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", ",", "ATTR_POSITION", ":", "42", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_position\"", ")", "==", "42.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_CLOSE_COVER", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_CLOSED", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_OPEN_COVER", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_OPEN", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_TOGGLE", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_CLOSED", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_TOGGLE", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "==", "STATE_OPEN" ]
[ 640, 0 ]
[ 700, 36 ]
python
en
['en', 'fr', 'en']
True
test_set_tilt_position_optimistic
(hass, calls)
Test the optimistic tilt_position mode.
Test the optimistic tilt_position mode.
async def test_set_tilt_position_optimistic(hass, calls): """Test the optimistic tilt_position mode.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "position_template": "{{ 100 }}", "set_cover_position": {"service": "test.automation"}, "set_cover_tilt_position": {"service": "test.automation"}, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") is None await hass.services.async_call( DOMAIN, SERVICE_SET_COVER_TILT_POSITION, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_TILT_POSITION: 42}, blocking=True, ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") == 42.0 await hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER_TILT, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") == 0.0 await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") == 100.0 await hass.services.async_call( DOMAIN, SERVICE_TOGGLE_COVER_TILT, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") == 0.0 await hass.services.async_call( DOMAIN, SERVICE_TOGGLE_COVER_TILT, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True ) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("current_tilt_position") == 100.0
[ "async", "def", "test_set_tilt_position_optimistic", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"position_template\"", ":", "\"{{ 100 }}\"", ",", "\"set_cover_position\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", ",", "\"set_cover_tilt_position\"", ":", "{", "\"service\"", ":", "\"test.automation\"", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "is", "None", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_SET_COVER_TILT_POSITION", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", ",", "ATTR_TILT_POSITION", ":", "42", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "==", "42.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_CLOSE_COVER_TILT", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "==", "0.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_OPEN_COVER_TILT", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "==", "100.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_TOGGLE_COVER_TILT", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "==", "0.0", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_TOGGLE_COVER_TILT", ",", "{", "ATTR_ENTITY_ID", ":", "ENTITY_COVER", "}", ",", "blocking", "=", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_tilt_position\"", ")", "==", "100.0" ]
[ 703, 0 ]
[ 765, 65 ]
python
en
['en', 'no', 'en']
True
test_icon_template
(hass, calls)
Test icon template.
Test icon template.
async def test_icon_template(hass, calls): """Test icon template.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ states.cover.test_state.state }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, "icon_template": "{% if states.cover.test_state.state %}" "mdi:check" "{% endif %}", } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("icon") == "" state = hass.states.async_set("cover.test_state", STATE_OPEN) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes["icon"] == "mdi:check"
[ "async", "def", "test_icon_template", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ states.cover.test_state.state }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"icon_template\"", ":", "\"{% if states.cover.test_state.state %}\"", "\"mdi:check\"", "\"{% endif %}\"", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"icon\"", ")", "==", "\"\"", "state", "=", "hass", ".", "states", ".", "async_set", "(", "\"cover.test_state\"", ",", "STATE_OPEN", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", "[", "\"icon\"", "]", "==", "\"mdi:check\"" ]
[ 768, 0 ]
[ 809, 50 ]
python
en
['en', 'en', 'en']
True
test_entity_picture_template
(hass, calls)
Test icon template.
Test icon template.
async def test_entity_picture_template(hass, calls): """Test icon template.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ states.cover.test_state.state }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, "entity_picture_template": "{% if states.cover.test_state.state %}" "/local/cover.png" "{% endif %}", } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("entity_picture") == "" state = hass.states.async_set("cover.test_state", STATE_OPEN) await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes["entity_picture"] == "/local/cover.png"
[ "async", "def", "test_entity_picture_template", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ states.cover.test_state.state }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"entity_picture_template\"", ":", "\"{% if states.cover.test_state.state %}\"", "\"/local/cover.png\"", "\"{% endif %}\"", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"entity_picture\"", ")", "==", "\"\"", "state", "=", "hass", ".", "states", ".", "async_set", "(", "\"cover.test_state\"", ",", "STATE_OPEN", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", "[", "\"entity_picture\"", "]", "==", "\"/local/cover.png\"" ]
[ 812, 0 ]
[ 853, 67 ]
python
en
['en', 'en', 'en']
True
test_availability_template
(hass, calls)
Test availability template.
Test availability template.
async def test_availability_template(hass, calls): """Test availability template.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "open", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, "availability_template": "{{ is_state('availability_state.state','on') }}", } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() hass.states.async_set("availability_state.state", STATE_OFF) await hass.async_block_till_done() assert hass.states.get("cover.test_template_cover").state == STATE_UNAVAILABLE hass.states.async_set("availability_state.state", STATE_ON) await hass.async_block_till_done() assert hass.states.get("cover.test_template_cover").state != STATE_UNAVAILABLE
[ "async", "def", "test_availability_template", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"open\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"availability_template\"", ":", "\"{{ is_state('availability_state.state','on') }}\"", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "hass", ".", "states", ".", "async_set", "(", "\"availability_state.state\"", ",", "STATE_OFF", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", ".", "state", "==", "STATE_UNAVAILABLE", "hass", ".", "states", ".", "async_set", "(", "\"availability_state.state\"", ",", "STATE_ON", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", ".", "state", "!=", "STATE_UNAVAILABLE" ]
[ 856, 0 ]
[ 895, 82 ]
python
en
['en', 'ga', 'en']
True
test_availability_without_availability_template
(hass, calls)
Test that component is available if there is no.
Test that component is available if there is no.
async def test_availability_without_availability_template(hass, calls): """Test that component is available if there is no.""" assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "open", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.state != STATE_UNAVAILABLE
[ "async", "def", "test_availability_without_availability_template", "(", "hass", ",", "calls", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"open\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "state", "!=", "STATE_UNAVAILABLE" ]
[ 898, 0 ]
[ 928, 43 ]
python
en
['en', 'en', 'en']
True
test_invalid_availability_template_keeps_component_available
(hass, caplog)
Test that an invalid availability keeps the device available.
Test that an invalid availability keeps the device available.
async def test_invalid_availability_template_keeps_component_available(hass, caplog): """Test that an invalid availability keeps the device available.""" assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "availability_template": "{{ x - 12 }}", "value_template": "open", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() assert hass.states.get("cover.test_template_cover") != STATE_UNAVAILABLE assert ("UndefinedError: 'x' is undefined") in caplog.text
[ "async", "def", "test_invalid_availability_template_keeps_component_available", "(", "hass", ",", "caplog", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"availability_template\"", ":", "\"{{ x - 12 }}\"", ",", "\"value_template\"", ":", "\"open\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "!=", "STATE_UNAVAILABLE", "assert", "(", "\"UndefinedError: 'x' is undefined\"", ")", "in", "caplog", ".", "text" ]
[ 931, 0 ]
[ 962, 62 ]
python
en
['en', 'en', 'en']
True
test_device_class
(hass, calls)
Test device class.
Test device class.
async def test_device_class(hass, calls): """Test device class.""" with assert_setup_component(1, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ states.cover.test_state.state }}", "device_class": "door", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert state.attributes.get("device_class") == "door"
[ "async", "def", "test_device_class", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "1", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ states.cover.test_state.state }}\"", ",", "\"device_class\"", ":", "\"door\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"device_class\"", ")", "==", "\"door\"" ]
[ 965, 0 ]
[ 997, 57 ]
python
en
['fr', 'en', 'en']
True
test_invalid_device_class
(hass, calls)
Test device class.
Test device class.
async def test_invalid_device_class(hass, calls): """Test device class.""" with assert_setup_component(0, "cover"): assert await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover": { "value_template": "{{ states.cover.test_state.state }}", "device_class": "barnacle_bill", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, } }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() state = hass.states.get("cover.test_template_cover") assert not state
[ "async", "def", "test_invalid_device_class", "(", "hass", ",", "calls", ")", ":", "with", "assert_setup_component", "(", "0", ",", "\"cover\"", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover\"", ":", "{", "\"value_template\"", ":", "\"{{ states.cover.test_state.state }}\"", ",", "\"device_class\"", ":", "\"barnacle_bill\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"cover.test_template_cover\"", ")", "assert", "not", "state" ]
[ 1000, 0 ]
[ 1032, 20 ]
python
en
['fr', 'en', 'en']
True
test_unique_id
(hass)
Test unique_id option only creates one cover per id.
Test unique_id option only creates one cover per id.
async def test_unique_id(hass): """Test unique_id option only creates one cover per id.""" await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "test_template_cover_01": { "unique_id": "not-so-unique-anymore", "value_template": "{{ true }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, }, "test_template_cover_02": { "unique_id": "not-so-unique-anymore", "value_template": "{{ false }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, }, }, }, }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() assert len(hass.states.async_all()) == 1
[ "async", "def", "test_unique_id", "(", "hass", ")", ":", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"test_template_cover_01\"", ":", "{", "\"unique_id\"", ":", "\"not-so-unique-anymore\"", ",", "\"value_template\"", ":", "\"{{ true }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", ",", "\"test_template_cover_02\"", ":", "{", "\"unique_id\"", ":", "\"not-so-unique-anymore\"", ",", "\"value_template\"", ":", "\"{{ false }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", ",", "}", ",", "}", ",", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "1" ]
[ 1035, 0 ]
[ 1077, 44 ]
python
en
['en', 'en', 'en']
True
test_state_gets_lowercased
(hass)
Test True/False is lowercased.
Test True/False is lowercased.
async def test_state_gets_lowercased(hass): """Test True/False is lowercased.""" hass.states.async_set("binary_sensor.garage_door_sensor", "off") await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "garage_door": { "friendly_name": "Garage Door", "value_template": "{{ is_state('binary_sensor.garage_door_sensor', 'off') }}", "open_cover": { "service": "cover.open_cover", "entity_id": "cover.test_state", }, "close_cover": { "service": "cover.close_cover", "entity_id": "cover.test_state", }, }, }, }, }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() assert len(hass.states.async_all()) == 2 assert hass.states.get("cover.garage_door").state == STATE_OPEN hass.states.async_set("binary_sensor.garage_door_sensor", "on") await hass.async_block_till_done() assert hass.states.get("cover.garage_door").state == STATE_CLOSED
[ "async", "def", "test_state_gets_lowercased", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"binary_sensor.garage_door_sensor\"", ",", "\"off\"", ")", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"garage_door\"", ":", "{", "\"friendly_name\"", ":", "\"Garage Door\"", ",", "\"value_template\"", ":", "\"{{ is_state('binary_sensor.garage_door_sensor', 'off') }}\"", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"cover.open_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"cover.close_cover\"", ",", "\"entity_id\"", ":", "\"cover.test_state\"", ",", "}", ",", "}", ",", "}", ",", "}", ",", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "2", "assert", "hass", ".", "states", ".", "get", "(", "\"cover.garage_door\"", ")", ".", "state", "==", "STATE_OPEN", "hass", ".", "states", ".", "async_set", "(", "\"binary_sensor.garage_door_sensor\"", ",", "\"on\"", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"cover.garage_door\"", ")", ".", "state", "==", "STATE_CLOSED" ]
[ 1080, 0 ]
[ 1118, 69 ]
python
en
['en', 'et', 'en']
True
test_self_referencing_icon_with_no_template_is_not_a_loop
(hass, caplog)
Test a self referencing icon with no value template is not a loop.
Test a self referencing icon with no value template is not a loop.
async def test_self_referencing_icon_with_no_template_is_not_a_loop(hass, caplog): """Test a self referencing icon with no value template is not a loop.""" icon_template_str = """{% if is_state('cover.office', 'open') %} mdi:window-shutter-open {% else %} mdi:window-shutter {% endif %}""" await setup.async_setup_component( hass, "cover", { "cover": { "platform": "template", "covers": { "office": { "icon_template": icon_template_str, "open_cover": { "service": "switch.turn_on", "entity_id": "switch.office_blinds_up", }, "close_cover": { "service": "switch.turn_on", "entity_id": "switch.office_blinds_down", }, "stop_cover": { "service": "switch.turn_on", "entity_id": "switch.office_blinds_up", }, }, }, } }, ) await hass.async_block_till_done() await hass.async_start() await hass.async_block_till_done() assert len(hass.states.async_all()) == 1 assert "Template loop detected" not in caplog.text
[ "async", "def", "test_self_referencing_icon_with_no_template_is_not_a_loop", "(", "hass", ",", "caplog", ")", ":", "icon_template_str", "=", "\"\"\"{% if is_state('cover.office', 'open') %}\n mdi:window-shutter-open\n {% else %}\n mdi:window-shutter\n {% endif %}\"\"\"", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cover\"", ",", "{", "\"cover\"", ":", "{", "\"platform\"", ":", "\"template\"", ",", "\"covers\"", ":", "{", "\"office\"", ":", "{", "\"icon_template\"", ":", "icon_template_str", ",", "\"open_cover\"", ":", "{", "\"service\"", ":", "\"switch.turn_on\"", ",", "\"entity_id\"", ":", "\"switch.office_blinds_up\"", ",", "}", ",", "\"close_cover\"", ":", "{", "\"service\"", ":", "\"switch.turn_on\"", ",", "\"entity_id\"", ":", "\"switch.office_blinds_down\"", ",", "}", ",", "\"stop_cover\"", ":", "{", "\"service\"", ":", "\"switch.turn_on\"", ",", "\"entity_id\"", ":", "\"switch.office_blinds_up\"", ",", "}", ",", "}", ",", "}", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "hass", ".", "async_start", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "1", "assert", "\"Template loop detected\"", "not", "in", "caplog", ".", "text" ]
[ 1121, 0 ]
[ 1163, 54 ]
python
en
['en', 'en', 'en']
True
setFixtureParamNames
(request, orderedParamNameList)
Given a request fixture and a list of param names ordered based on the order the params are specified for a parameterized fixture, this will set the names so reporting tools can label the parameterized benchmark runs accordingly. This is only needed for parameterized fixtures, since parameterized benchmarks already assign param names to param values. Order matters. For example, if the fixture's params are set like this: params = product([True, False], [True, False]) and the param names are set like this: orderedParamNameList = ["managed_memory", "pool_allocator"] then the reports show the options that were set for the benchmark like this: my_benchmark[managed_memory=True, pool_allocator=True] my_benchmark[managed_memory=True, pool_allocator=False] my_benchmark[managed_memory=False, pool_allocator=True] my_benchmark[managed_memory=False, pool_allocator=False] orderedParamNameList can have more params specified than are used. For example, if a fixture only has 2 params, only the first 2 names in orderedParamNameList are used. NOTE: the fixture param names set by this function are currently only used for ASV reporting.
Given a request fixture and a list of param names ordered based on the order the params are specified for a parameterized fixture, this will set the names so reporting tools can label the parameterized benchmark runs accordingly. This is only needed for parameterized fixtures, since parameterized benchmarks already assign param names to param values.
def setFixtureParamNames(request, orderedParamNameList): """ Given a request fixture and a list of param names ordered based on the order the params are specified for a parameterized fixture, this will set the names so reporting tools can label the parameterized benchmark runs accordingly. This is only needed for parameterized fixtures, since parameterized benchmarks already assign param names to param values. Order matters. For example, if the fixture's params are set like this: params = product([True, False], [True, False]) and the param names are set like this: orderedParamNameList = ["managed_memory", "pool_allocator"] then the reports show the options that were set for the benchmark like this: my_benchmark[managed_memory=True, pool_allocator=True] my_benchmark[managed_memory=True, pool_allocator=False] my_benchmark[managed_memory=False, pool_allocator=True] my_benchmark[managed_memory=False, pool_allocator=False] orderedParamNameList can have more params specified than are used. For example, if a fixture only has 2 params, only the first 2 names in orderedParamNameList are used. NOTE: the fixture param names set by this function are currently only used for ASV reporting. """ # This function can also be called on a single test param, which may result # in request.param *not* being a list of param values. if type(request.param) is list: numParams = len(request.param) else: numParams = 1 if len(orderedParamNameList) < numParams: raise IndexError("setFixtureParamNames: the number of parameter names " "is less than the number of parameters.") request.keywords.setdefault( "fixture_param_names", dict())[request.fixturename] = orderedParamNameList[:numParams]
[ "def", "setFixtureParamNames", "(", "request", ",", "orderedParamNameList", ")", ":", "# This function can also be called on a single test param, which may result", "# in request.param *not* being a list of param values.", "if", "type", "(", "request", ".", "param", ")", "is", "list", ":", "numParams", "=", "len", "(", "request", ".", "param", ")", "else", ":", "numParams", "=", "1", "if", "len", "(", "orderedParamNameList", ")", "<", "numParams", ":", "raise", "IndexError", "(", "\"setFixtureParamNames: the number of parameter names \"", "\"is less than the number of parameters.\"", ")", "request", ".", "keywords", ".", "setdefault", "(", "\"fixture_param_names\"", ",", "dict", "(", ")", ")", "[", "request", ".", "fixturename", "]", "=", "orderedParamNameList", "[", ":", "numParams", "]" ]
[ 2, 0 ]
[ 42, 71 ]
python
en
['en', 'error', 'th']
False
async_setup_entry
(hass, config_entry, async_add_entities)
Set up tuya sensors dynamically through tuya discovery.
Set up tuya sensors dynamically through tuya discovery.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up tuya sensors dynamically through tuya discovery.""" platform = config_entry.data[CONF_PLATFORM] async def async_discover_sensor(dev_ids): """Discover and add a discovered tuya sensor.""" if not dev_ids: return entities = await hass.async_add_executor_job( _setup_entities, hass, dev_ids, platform, ) async_add_entities(entities) async_dispatcher_connect( hass, TUYA_DISCOVERY_NEW.format(SENSOR_DOMAIN), async_discover_sensor ) devices_ids = hass.data[DOMAIN]["pending"].pop(SENSOR_DOMAIN) await async_discover_sensor(devices_ids)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "platform", "=", "config_entry", ".", "data", "[", "CONF_PLATFORM", "]", "async", "def", "async_discover_sensor", "(", "dev_ids", ")", ":", "\"\"\"Discover and add a discovered tuya sensor.\"\"\"", "if", "not", "dev_ids", ":", "return", "entities", "=", "await", "hass", ".", "async_add_executor_job", "(", "_setup_entities", ",", "hass", ",", "dev_ids", ",", "platform", ",", ")", "async_add_entities", "(", "entities", ")", "async_dispatcher_connect", "(", "hass", ",", "TUYA_DISCOVERY_NEW", ".", "format", "(", "SENSOR_DOMAIN", ")", ",", "async_discover_sensor", ")", "devices_ids", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "\"pending\"", "]", ".", "pop", "(", "SENSOR_DOMAIN", ")", "await", "async_discover_sensor", "(", "devices_ids", ")" ]
[ 20, 0 ]
[ 42, 44 ]
python
en
['en', 'zu', 'en']
True
_setup_entities
(hass, dev_ids, platform)
Set up Tuya Cover device.
Set up Tuya Cover device.
def _setup_entities(hass, dev_ids, platform): """Set up Tuya Cover device.""" tuya = hass.data[DOMAIN][TUYA_DATA] entities = [] for dev_id in dev_ids: device = tuya.get_device_by_id(dev_id) if device is None: continue entities.append(TuyaCover(device, platform)) return entities
[ "def", "_setup_entities", "(", "hass", ",", "dev_ids", ",", "platform", ")", ":", "tuya", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "TUYA_DATA", "]", "entities", "=", "[", "]", "for", "dev_id", "in", "dev_ids", ":", "device", "=", "tuya", ".", "get_device_by_id", "(", "dev_id", ")", "if", "device", "is", "None", ":", "continue", "entities", ".", "append", "(", "TuyaCover", "(", "device", ",", "platform", ")", ")", "return", "entities" ]
[ 45, 0 ]
[ 54, 19 ]
python
ca
['ca', 'zu', 'en']
False
TuyaCover.__init__
(self, tuya, platform)
Init tuya cover device.
Init tuya cover device.
def __init__(self, tuya, platform): """Init tuya cover device.""" super().__init__(tuya, platform) self.entity_id = ENTITY_ID_FORMAT.format(tuya.object_id()) self._was_closing = False self._was_opening = False
[ "def", "__init__", "(", "self", ",", "tuya", ",", "platform", ")", ":", "super", "(", ")", ".", "__init__", "(", "tuya", ",", "platform", ")", "self", ".", "entity_id", "=", "ENTITY_ID_FORMAT", ".", "format", "(", "tuya", ".", "object_id", "(", ")", ")", "self", ".", "_was_closing", "=", "False", "self", ".", "_was_opening", "=", "False" ]
[ 60, 4 ]
[ 65, 33 ]
python
en
['ca', 'en', 'en']
True
TuyaCover.supported_features
(self)
Flag supported features.
Flag supported features.
def supported_features(self): """Flag supported features.""" if self._tuya.support_stop(): return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP return SUPPORT_OPEN | SUPPORT_CLOSE
[ "def", "supported_features", "(", "self", ")", ":", "if", "self", ".", "_tuya", ".", "support_stop", "(", ")", ":", "return", "SUPPORT_OPEN", "|", "SUPPORT_CLOSE", "|", "SUPPORT_STOP", "return", "SUPPORT_OPEN", "|", "SUPPORT_CLOSE" ]
[ 68, 4 ]
[ 72, 43 ]
python
en
['da', 'en', 'en']
True
TuyaCover.is_opening
(self)
Return if the cover is opening or not.
Return if the cover is opening or not.
def is_opening(self): """Return if the cover is opening or not.""" state = self._tuya.state() if state == 1: self._was_opening = True self._was_closing = False return True return False
[ "def", "is_opening", "(", "self", ")", ":", "state", "=", "self", ".", "_tuya", ".", "state", "(", ")", "if", "state", "==", "1", ":", "self", ".", "_was_opening", "=", "True", "self", ".", "_was_closing", "=", "False", "return", "True", "return", "False" ]
[ 75, 4 ]
[ 82, 20 ]
python
en
['en', 'en', 'en']
True
TuyaCover.is_closing
(self)
Return if the cover is closing or not.
Return if the cover is closing or not.
def is_closing(self): """Return if the cover is closing or not.""" state = self._tuya.state() if state == 2: self._was_opening = False self._was_closing = True return True return False
[ "def", "is_closing", "(", "self", ")", ":", "state", "=", "self", ".", "_tuya", ".", "state", "(", ")", "if", "state", "==", "2", ":", "self", ".", "_was_opening", "=", "False", "self", ".", "_was_closing", "=", "True", "return", "True", "return", "False" ]
[ 85, 4 ]
[ 92, 20 ]
python
en
['en', 'en', 'en']
True
TuyaCover.is_closed
(self)
Return if the cover is closed or not.
Return if the cover is closed or not.
def is_closed(self): """Return if the cover is closed or not.""" state = self._tuya.state() if state != 2 and self._was_closing: return True if state != 1 and self._was_opening: return False return None
[ "def", "is_closed", "(", "self", ")", ":", "state", "=", "self", ".", "_tuya", ".", "state", "(", ")", "if", "state", "!=", "2", "and", "self", ".", "_was_closing", ":", "return", "True", "if", "state", "!=", "1", "and", "self", ".", "_was_opening", ":", "return", "False", "return", "None" ]
[ 95, 4 ]
[ 102, 19 ]
python
en
['en', 'en', 'en']
True
TuyaCover.open_cover
(self, **kwargs)
Open the cover.
Open the cover.
def open_cover(self, **kwargs): """Open the cover.""" self._tuya.open_cover()
[ "def", "open_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_tuya", ".", "open_cover", "(", ")" ]
[ 104, 4 ]
[ 106, 31 ]
python
en
['en', 'en', 'en']
True
TuyaCover.close_cover
(self, **kwargs)
Close cover.
Close cover.
def close_cover(self, **kwargs): """Close cover.""" self._tuya.close_cover()
[ "def", "close_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_tuya", ".", "close_cover", "(", ")" ]
[ 108, 4 ]
[ 110, 32 ]
python
en
['en', 'la', 'en']
False
TuyaCover.stop_cover
(self, **kwargs)
Stop the cover.
Stop the cover.
def stop_cover(self, **kwargs): """Stop the cover.""" if self.is_closed is None: self._was_opening = False self._was_closing = False self._tuya.stop_cover()
[ "def", "stop_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "is_closed", "is", "None", ":", "self", ".", "_was_opening", "=", "False", "self", ".", "_was_closing", "=", "False", "self", ".", "_tuya", ".", "stop_cover", "(", ")" ]
[ 112, 4 ]
[ 117, 31 ]
python
en
['en', 'en', 'en']
True
get_scanner
(hass, config)
Validate the configuration and return a Quantum Gateway scanner.
Validate the configuration and return a Quantum Gateway scanner.
def get_scanner(hass, config): """Validate the configuration and return a Quantum Gateway scanner.""" scanner = QuantumGatewayDeviceScanner(config[DOMAIN]) return scanner if scanner.success_init else None
[ "def", "get_scanner", "(", "hass", ",", "config", ")", ":", "scanner", "=", "QuantumGatewayDeviceScanner", "(", "config", "[", "DOMAIN", "]", ")", "return", "scanner", "if", "scanner", ".", "success_init", "else", "None" ]
[ 28, 0 ]
[ 32, 52 ]
python
en
['en', 'en', 'en']
True
QuantumGatewayDeviceScanner.__init__
(self, config)
Initialize the scanner.
Initialize the scanner.
def __init__(self, config): """Initialize the scanner.""" self.host = config[CONF_HOST] self.password = config[CONF_PASSWORD] self.use_https = config[CONF_SSL] _LOGGER.debug("Initializing") try: self.quantum = QuantumGatewayScanner( self.host, self.password, self.use_https ) self.success_init = self.quantum.success_init except RequestException: self.success_init = False _LOGGER.error("Unable to connect to gateway. Check host") if not self.success_init: _LOGGER.error("Unable to login to gateway. Check password and host")
[ "def", "__init__", "(", "self", ",", "config", ")", ":", "self", ".", "host", "=", "config", "[", "CONF_HOST", "]", "self", ".", "password", "=", "config", "[", "CONF_PASSWORD", "]", "self", ".", "use_https", "=", "config", "[", "CONF_SSL", "]", "_LOGGER", ".", "debug", "(", "\"Initializing\"", ")", "try", ":", "self", ".", "quantum", "=", "QuantumGatewayScanner", "(", "self", ".", "host", ",", "self", ".", "password", ",", "self", ".", "use_https", ")", "self", ".", "success_init", "=", "self", ".", "quantum", ".", "success_init", "except", "RequestException", ":", "self", ".", "success_init", "=", "False", "_LOGGER", ".", "error", "(", "\"Unable to connect to gateway. Check host\"", ")", "if", "not", "self", ".", "success_init", ":", "_LOGGER", ".", "error", "(", "\"Unable to login to gateway. Check password and host\"", ")" ]
[ 38, 4 ]
[ 56, 80 ]
python
en
['en', 'en', 'en']
True
QuantumGatewayDeviceScanner.scan_devices
(self)
Scan for new devices and return a list of found MACs.
Scan for new devices and return a list of found MACs.
def scan_devices(self): """Scan for new devices and return a list of found MACs.""" connected_devices = [] try: connected_devices = self.quantum.scan_devices() except RequestException: _LOGGER.error("Unable to scan devices. Check connection to router") return connected_devices
[ "def", "scan_devices", "(", "self", ")", ":", "connected_devices", "=", "[", "]", "try", ":", "connected_devices", "=", "self", ".", "quantum", ".", "scan_devices", "(", ")", "except", "RequestException", ":", "_LOGGER", ".", "error", "(", "\"Unable to scan devices. Check connection to router\"", ")", "return", "connected_devices" ]
[ 58, 4 ]
[ 65, 32 ]
python
en
['en', 'en', 'en']
True
QuantumGatewayDeviceScanner.get_device_name
(self, device)
Return the name of the given device or None if we don't know.
Return the name of the given device or None if we don't know.
def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" return self.quantum.get_device_name(device)
[ "def", "get_device_name", "(", "self", ",", "device", ")", ":", "return", "self", ".", "quantum", ".", "get_device_name", "(", "device", ")" ]
[ 67, 4 ]
[ 69, 51 ]
python
en
['en', 'en', 'en']
True
get_service
(hass, config, discovery_info=None)
Get the Clickatell notification service.
Get the Clickatell notification service.
def get_service(hass, config, discovery_info=None): """Get the Clickatell notification service.""" return ClickatellNotificationService(config)
[ "def", "get_service", "(", "hass", ",", "config", ",", "discovery_info", "=", "None", ")", ":", "return", "ClickatellNotificationService", "(", "config", ")" ]
[ 21, 0 ]
[ 23, 48 ]
python
en
['en', 'en', 'en']
True
ClickatellNotificationService.__init__
(self, config)
Initialize the service.
Initialize the service.
def __init__(self, config): """Initialize the service.""" self.api_key = config[CONF_API_KEY] self.recipient = config[CONF_RECIPIENT]
[ "def", "__init__", "(", "self", ",", "config", ")", ":", "self", ".", "api_key", "=", "config", "[", "CONF_API_KEY", "]", "self", ".", "recipient", "=", "config", "[", "CONF_RECIPIENT", "]" ]
[ 29, 4 ]
[ 32, 47 ]
python
en
['en', 'en', 'en']
True
ClickatellNotificationService.send_message
(self, message="", **kwargs)
Send a message to a user.
Send a message to a user.
def send_message(self, message="", **kwargs): """Send a message to a user.""" data = {"apiKey": self.api_key, "to": self.recipient, "content": message} resp = requests.get(BASE_API_URL, params=data, timeout=5) if (resp.status_code != HTTP_OK) or (resp.status_code != HTTP_ACCEPTED): _LOGGER.error("Error %s : %s", resp.status_code, resp.text)
[ "def", "send_message", "(", "self", ",", "message", "=", "\"\"", ",", "*", "*", "kwargs", ")", ":", "data", "=", "{", "\"apiKey\"", ":", "self", ".", "api_key", ",", "\"to\"", ":", "self", ".", "recipient", ",", "\"content\"", ":", "message", "}", "resp", "=", "requests", ".", "get", "(", "BASE_API_URL", ",", "params", "=", "data", ",", "timeout", "=", "5", ")", "if", "(", "resp", ".", "status_code", "!=", "HTTP_OK", ")", "or", "(", "resp", ".", "status_code", "!=", "HTTP_ACCEPTED", ")", ":", "_LOGGER", ".", "error", "(", "\"Error %s : %s\"", ",", "resp", ".", "status_code", ",", "resp", ".", "text", ")" ]
[ 34, 4 ]
[ 40, 71 ]
python
en
['en', 'en', 'en']
True
test_setup
(hass: HomeAssistant)
Test setting up manually.
Test setting up manually.
async def test_setup(hass: HomeAssistant) -> None: """Test setting up manually.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, ) assert result["type"] == RESULT_TYPE_FORM assert result["step_id"] == "confirm" assert not result["errors"] with patch(MODULE, return_value=MagicMock()): result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) assert result["type"] == RESULT_TYPE_CREATE_ENTRY
[ "async", "def", "test_setup", "(", "hass", ":", "HomeAssistant", ")", "->", "None", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "SOURCE_USER", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "RESULT_TYPE_FORM", "assert", "result", "[", "\"step_id\"", "]", "==", "\"confirm\"", "assert", "not", "result", "[", "\"errors\"", "]", "with", "patch", "(", "MODULE", ",", "return_value", "=", "MagicMock", "(", ")", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "RESULT_TYPE_CREATE_ENTRY" ]
[ 16, 0 ]
[ 28, 53 ]
python
en
['en', 'en', 'en']
True
test_not_supported
(hass: HomeAssistant)
Test setting up on not supported system.
Test setting up on not supported system.
async def test_not_supported(hass: HomeAssistant) -> None: """Test setting up on not supported system.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, ) with patch(MODULE, return_value=None): result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) assert result["type"] == RESULT_TYPE_ABORT assert result["reason"] == "no_devices_found"
[ "async", "def", "test_not_supported", "(", "hass", ":", "HomeAssistant", ")", "->", "None", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "SOURCE_USER", "}", ",", ")", "with", "patch", "(", "MODULE", ",", "return_value", "=", "None", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "RESULT_TYPE_ABORT", "assert", "result", "[", "\"reason\"", "]", "==", "\"no_devices_found\"" ]
[ 31, 0 ]
[ 41, 49 ]
python
en
['en', 'en', 'en']
True
test_onboarding
(hass: HomeAssistant)
Test setting up via onboarding.
Test setting up via onboarding.
async def test_onboarding(hass: HomeAssistant) -> None: """Test setting up via onboarding.""" with patch(MODULE, return_value=MagicMock()): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": "onboarding"}, ) assert result["type"] == RESULT_TYPE_CREATE_ENTRY
[ "async", "def", "test_onboarding", "(", "hass", ":", "HomeAssistant", ")", "->", "None", ":", "with", "patch", "(", "MODULE", ",", "return_value", "=", "MagicMock", "(", ")", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "\"onboarding\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "RESULT_TYPE_CREATE_ENTRY" ]
[ 44, 0 ]
[ 51, 53 ]
python
en
['en', 'en', 'en']
True
test_onboarding_not_supported
(hass: HomeAssistant)
Test setting up via onboarding with unsupported system.
Test setting up via onboarding with unsupported system.
async def test_onboarding_not_supported(hass: HomeAssistant) -> None: """Test setting up via onboarding with unsupported system.""" with patch(MODULE, return_value=None): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": "onboarding"}, ) assert result["type"] == RESULT_TYPE_ABORT assert result["reason"] == "no_devices_found"
[ "async", "def", "test_onboarding_not_supported", "(", "hass", ":", "HomeAssistant", ")", "->", "None", ":", "with", "patch", "(", "MODULE", ",", "return_value", "=", "None", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "\"onboarding\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "RESULT_TYPE_ABORT", "assert", "result", "[", "\"reason\"", "]", "==", "\"no_devices_found\"" ]
[ 54, 0 ]
[ 62, 49 ]
python
en
['en', 'en', 'en']
True
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up the Volvo sensors.
Set up the Volvo sensors.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Volvo sensors.""" if discovery_info is None: return async_add_entities([VolvoSensor(hass.data[DATA_KEY], *discovery_info)])
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "discovery_info", "is", "None", ":", "return", "async_add_entities", "(", "[", "VolvoSensor", "(", "hass", ".", "data", "[", "DATA_KEY", "]", ",", "*", "discovery_info", ")", "]", ")" ]
[ 4, 0 ]
[ 8, 75 ]
python
en
['en', 'ko', 'en']
True
VolvoSensor.state
(self)
Return the state.
Return the state.
def state(self): """Return the state.""" return self.instrument.state
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "instrument", ".", "state" ]
[ 15, 4 ]
[ 17, 36 ]
python
en
['en', 'en', 'en']
True
VolvoSensor.unit_of_measurement
(self)
Return the unit of measurement.
Return the unit of measurement.
def unit_of_measurement(self): """Return the unit of measurement.""" return self.instrument.unit
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "self", ".", "instrument", ".", "unit" ]
[ 20, 4 ]
[ 22, 35 ]
python
en
['en', 'la', 'en']
True
async_get_triggers
(hass: HomeAssistant, device_id: str)
List device triggers for Lock devices.
List device triggers for Lock devices.
async def async_get_triggers(hass: HomeAssistant, device_id: str) -> List[dict]: """List device triggers for Lock devices.""" registry = await entity_registry.async_get_registry(hass) triggers = [] # Get all the integrations entities for this device for entry in entity_registry.async_entries_for_device(registry, device_id): if entry.domain != DOMAIN: continue # Add triggers for each entity that belongs to this integration triggers.append( { CONF_PLATFORM: "device", CONF_DEVICE_ID: device_id, CONF_DOMAIN: DOMAIN, CONF_ENTITY_ID: entry.entity_id, CONF_TYPE: "locked", } ) triggers.append( { CONF_PLATFORM: "device", CONF_DEVICE_ID: device_id, CONF_DOMAIN: DOMAIN, CONF_ENTITY_ID: entry.entity_id, CONF_TYPE: "unlocked", } ) return triggers
[ "async", "def", "async_get_triggers", "(", "hass", ":", "HomeAssistant", ",", "device_id", ":", "str", ")", "->", "List", "[", "dict", "]", ":", "registry", "=", "await", "entity_registry", ".", "async_get_registry", "(", "hass", ")", "triggers", "=", "[", "]", "# Get all the integrations entities for this device", "for", "entry", "in", "entity_registry", ".", "async_entries_for_device", "(", "registry", ",", "device_id", ")", ":", "if", "entry", ".", "domain", "!=", "DOMAIN", ":", "continue", "# Add triggers for each entity that belongs to this integration", "triggers", ".", "append", "(", "{", "CONF_PLATFORM", ":", "\"device\"", ",", "CONF_DEVICE_ID", ":", "device_id", ",", "CONF_DOMAIN", ":", "DOMAIN", ",", "CONF_ENTITY_ID", ":", "entry", ".", "entity_id", ",", "CONF_TYPE", ":", "\"locked\"", ",", "}", ")", "triggers", ".", "append", "(", "{", "CONF_PLATFORM", ":", "\"device\"", ",", "CONF_DEVICE_ID", ":", "device_id", ",", "CONF_DOMAIN", ":", "DOMAIN", ",", "CONF_ENTITY_ID", ":", "entry", ".", "entity_id", ",", "CONF_TYPE", ":", "\"unlocked\"", ",", "}", ")", "return", "triggers" ]
[ 33, 0 ]
[ 63, 19 ]
python
en
['da', 'en', 'en']
True
async_attach_trigger
( hass: HomeAssistant, config: ConfigType, action: AutomationActionType, automation_info: dict, )
Attach a trigger.
Attach a trigger.
async def async_attach_trigger( hass: HomeAssistant, config: ConfigType, action: AutomationActionType, automation_info: dict, ) -> CALLBACK_TYPE: """Attach a trigger.""" config = TRIGGER_SCHEMA(config) if config[CONF_TYPE] == "locked": from_state = STATE_UNLOCKED to_state = STATE_LOCKED else: from_state = STATE_LOCKED to_state = STATE_UNLOCKED state_config = { CONF_PLATFORM: "state", CONF_ENTITY_ID: config[CONF_ENTITY_ID], state_trigger.CONF_FROM: from_state, state_trigger.CONF_TO: to_state, } state_config = state_trigger.TRIGGER_SCHEMA(state_config) return await state_trigger.async_attach_trigger( hass, state_config, action, automation_info, platform_type="device" )
[ "async", "def", "async_attach_trigger", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "ConfigType", ",", "action", ":", "AutomationActionType", ",", "automation_info", ":", "dict", ",", ")", "->", "CALLBACK_TYPE", ":", "config", "=", "TRIGGER_SCHEMA", "(", "config", ")", "if", "config", "[", "CONF_TYPE", "]", "==", "\"locked\"", ":", "from_state", "=", "STATE_UNLOCKED", "to_state", "=", "STATE_LOCKED", "else", ":", "from_state", "=", "STATE_LOCKED", "to_state", "=", "STATE_UNLOCKED", "state_config", "=", "{", "CONF_PLATFORM", ":", "\"state\"", ",", "CONF_ENTITY_ID", ":", "config", "[", "CONF_ENTITY_ID", "]", ",", "state_trigger", ".", "CONF_FROM", ":", "from_state", ",", "state_trigger", ".", "CONF_TO", ":", "to_state", ",", "}", "state_config", "=", "state_trigger", ".", "TRIGGER_SCHEMA", "(", "state_config", ")", "return", "await", "state_trigger", ".", "async_attach_trigger", "(", "hass", ",", "state_config", ",", "action", ",", "automation_info", ",", "platform_type", "=", "\"device\"", ")" ]
[ 66, 0 ]
[ 91, 5 ]
python
en
['en', 'lb', 'en']
True
setup
(hass, config)
Set up the component.
Set up the component.
def setup(hass, config): """Set up the component.""" # Create API Clients for later use hass.data[PROXMOX_CLIENTS] = {} for entry in config[DOMAIN]: host = entry[CONF_HOST] port = entry[CONF_PORT] user = entry[CONF_USERNAME] realm = entry[CONF_REALM] password = entry[CONF_PASSWORD] verify_ssl = entry[CONF_VERIFY_SSL] try: # Construct an API client with the given data for the given host proxmox_client = ProxmoxClient( host, port, user, realm, password, verify_ssl ) proxmox_client.build_client() except AuthenticationError: _LOGGER.warning( "Invalid credentials for proxmox instance %s:%d", host, port ) continue except SSLError: _LOGGER.error( 'Unable to verify proxmox server SSL. Try using "verify_ssl: false"' ) continue hass.data[PROXMOX_CLIENTS][f"{host}:{port}"] = proxmox_client if hass.data[PROXMOX_CLIENTS]: hass.helpers.discovery.load_platform( "binary_sensor", DOMAIN, {"entries": config[DOMAIN]}, config ) return True return False
[ "def", "setup", "(", "hass", ",", "config", ")", ":", "# Create API Clients for later use", "hass", ".", "data", "[", "PROXMOX_CLIENTS", "]", "=", "{", "}", "for", "entry", "in", "config", "[", "DOMAIN", "]", ":", "host", "=", "entry", "[", "CONF_HOST", "]", "port", "=", "entry", "[", "CONF_PORT", "]", "user", "=", "entry", "[", "CONF_USERNAME", "]", "realm", "=", "entry", "[", "CONF_REALM", "]", "password", "=", "entry", "[", "CONF_PASSWORD", "]", "verify_ssl", "=", "entry", "[", "CONF_VERIFY_SSL", "]", "try", ":", "# Construct an API client with the given data for the given host", "proxmox_client", "=", "ProxmoxClient", "(", "host", ",", "port", ",", "user", ",", "realm", ",", "password", ",", "verify_ssl", ")", "proxmox_client", ".", "build_client", "(", ")", "except", "AuthenticationError", ":", "_LOGGER", ".", "warning", "(", "\"Invalid credentials for proxmox instance %s:%d\"", ",", "host", ",", "port", ")", "continue", "except", "SSLError", ":", "_LOGGER", ".", "error", "(", "'Unable to verify proxmox server SSL. Try using \"verify_ssl: false\"'", ")", "continue", "hass", ".", "data", "[", "PROXMOX_CLIENTS", "]", "[", "f\"{host}:{port}\"", "]", "=", "proxmox_client", "if", "hass", ".", "data", "[", "PROXMOX_CLIENTS", "]", ":", "hass", ".", "helpers", ".", "discovery", ".", "load_platform", "(", "\"binary_sensor\"", ",", "DOMAIN", ",", "{", "\"entries\"", ":", "config", "[", "DOMAIN", "]", "}", ",", "config", ")", "return", "True", "return", "False" ]
[ 73, 0 ]
[ 111, 16 ]
python
en
['en', 'en', 'en']
True
ProxmoxClient.__init__
(self, host, port, user, realm, password, verify_ssl)
Initialize the ProxmoxClient.
Initialize the ProxmoxClient.
def __init__(self, host, port, user, realm, password, verify_ssl): """Initialize the ProxmoxClient.""" self._host = host self._port = port self._user = user self._realm = realm self._password = password self._verify_ssl = verify_ssl self._proxmox = None self._connection_start_time = None
[ "def", "__init__", "(", "self", ",", "host", ",", "port", ",", "user", ",", "realm", ",", "password", ",", "verify_ssl", ")", ":", "self", ".", "_host", "=", "host", "self", ".", "_port", "=", "port", "self", ".", "_user", "=", "user", "self", ".", "_realm", "=", "realm", "self", ".", "_password", "=", "password", "self", ".", "_verify_ssl", "=", "verify_ssl", "self", ".", "_proxmox", "=", "None", "self", ".", "_connection_start_time", "=", "None" ]
[ 124, 4 ]
[ 135, 42 ]
python
en
['en', 'en', 'en']
True
ProxmoxClient.build_client
(self)
Construct the ProxmoxAPI client. Allows inserting the realm within the `user` value.
Construct the ProxmoxAPI client. Allows inserting the realm within the `user` value.
def build_client(self): """Construct the ProxmoxAPI client. Allows inserting the realm within the `user` value.""" if "@" in self._user: user_id = self._user else: user_id = f"{self._user}@{self._realm}" self._proxmox = ProxmoxAPI( self._host, port=self._port, user=user_id, password=self._password, verify_ssl=self._verify_ssl, )
[ "def", "build_client", "(", "self", ")", ":", "if", "\"@\"", "in", "self", ".", "_user", ":", "user_id", "=", "self", ".", "_user", "else", ":", "user_id", "=", "f\"{self._user}@{self._realm}\"", "self", ".", "_proxmox", "=", "ProxmoxAPI", "(", "self", ".", "_host", ",", "port", "=", "self", ".", "_port", ",", "user", "=", "user_id", ",", "password", "=", "self", ".", "_password", ",", "verify_ssl", "=", "self", ".", "_verify_ssl", ",", ")" ]
[ 137, 4 ]
[ 151, 9 ]
python
en
['en', 'en', 'en']
True
ProxmoxClient.get_api_client
(self)
Return the ProxmoxAPI client.
Return the ProxmoxAPI client.
def get_api_client(self): """Return the ProxmoxAPI client.""" return self._proxmox
[ "def", "get_api_client", "(", "self", ")", ":", "return", "self", ".", "_proxmox" ]
[ 153, 4 ]
[ 155, 28 ]
python
en
['en', 'sq', 'en']
True
async_setup_entry
( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: Callable )
Set up Notion sensors based on a config entry.
Set up Notion sensors based on a config entry.
async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: Callable ): """Set up Notion sensors based on a config entry.""" coordinator = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] sensor_list = [] for task_id, task in coordinator.data["tasks"].items(): if task["task_type"] not in SENSOR_TYPES: continue name, device_class, unit = SENSOR_TYPES[task["task_type"]] sensor = coordinator.data["sensors"][task["sensor_id"]] sensor_list.append( NotionSensor( coordinator, task_id, sensor["id"], sensor["bridge"]["id"], sensor["system_id"], name, device_class, unit, ) ) async_add_entities(sensor_list)
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ",", "async_add_entities", ":", "Callable", ")", ":", "coordinator", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "DATA_COORDINATOR", "]", "[", "entry", ".", "entry_id", "]", "sensor_list", "=", "[", "]", "for", "task_id", ",", "task", "in", "coordinator", ".", "data", "[", "\"tasks\"", "]", ".", "items", "(", ")", ":", "if", "task", "[", "\"task_type\"", "]", "not", "in", "SENSOR_TYPES", ":", "continue", "name", ",", "device_class", ",", "unit", "=", "SENSOR_TYPES", "[", "task", "[", "\"task_type\"", "]", "]", "sensor", "=", "coordinator", ".", "data", "[", "\"sensors\"", "]", "[", "task", "[", "\"sensor_id\"", "]", "]", "sensor_list", ".", "append", "(", "NotionSensor", "(", "coordinator", ",", "task_id", ",", "sensor", "[", "\"id\"", "]", ",", "sensor", "[", "\"bridge\"", "]", "[", "\"id\"", "]", ",", "sensor", "[", "\"system_id\"", "]", ",", "name", ",", "device_class", ",", "unit", ",", ")", ")", "async_add_entities", "(", "sensor_list", ")" ]
[ 17, 0 ]
[ 44, 35 ]
python
en
['en', 'da', 'en']
True
NotionSensor.__init__
( self, coordinator: DataUpdateCoordinator, task_id: str, sensor_id: str, bridge_id: str, system_id: str, name: str, device_class: str, unit: str, )
Initialize the entity.
Initialize the entity.
def __init__( self, coordinator: DataUpdateCoordinator, task_id: str, sensor_id: str, bridge_id: str, system_id: str, name: str, device_class: str, unit: str, ): """Initialize the entity.""" super().__init__( coordinator, task_id, sensor_id, bridge_id, system_id, name, device_class ) self._unit = unit
[ "def", "__init__", "(", "self", ",", "coordinator", ":", "DataUpdateCoordinator", ",", "task_id", ":", "str", ",", "sensor_id", ":", "str", ",", "bridge_id", ":", "str", ",", "system_id", ":", "str", ",", "name", ":", "str", ",", "device_class", ":", "str", ",", "unit", ":", "str", ",", ")", ":", "super", "(", ")", ".", "__init__", "(", "coordinator", ",", "task_id", ",", "sensor_id", ",", "bridge_id", ",", "system_id", ",", "name", ",", "device_class", ")", "self", ".", "_unit", "=", "unit" ]
[ 50, 4 ]
[ 66, 25 ]
python
en
['en', 'en', 'en']
True