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
HeosMediaPlayer.is_volume_muted
(self)
Boolean if volume is currently muted.
Boolean if volume is currently muted.
def is_volume_muted(self) -> bool: """Boolean if volume is currently muted.""" return self._player.is_muted
[ "def", "is_volume_muted", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_player", ".", "is_muted" ]
[ 275, 4 ]
[ 277, 36 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_album_name
(self)
Album name of current playing media, music track only.
Album name of current playing media, music track only.
def media_album_name(self) -> str: """Album name of current playing media, music track only.""" return self._player.now_playing_media.album
[ "def", "media_album_name", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_player", ".", "now_playing_media", ".", "album" ]
[ 280, 4 ]
[ 282, 51 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_artist
(self)
Artist of current playing media, music track only.
Artist of current playing media, music track only.
def media_artist(self) -> str: """Artist of current playing media, music track only.""" return self._player.now_playing_media.artist
[ "def", "media_artist", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_player", ".", "now_playing_media", ".", "artist" ]
[ 285, 4 ]
[ 287, 52 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_content_id
(self)
Content ID of current playing media.
Content ID of current playing media.
def media_content_id(self) -> str: """Content ID of current playing media.""" return self._player.now_playing_media.media_id
[ "def", "media_content_id", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_player", ".", "now_playing_media", ".", "media_id" ]
[ 290, 4 ]
[ 292, 54 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_content_type
(self)
Content type of current playing media.
Content type of current playing media.
def media_content_type(self) -> str: """Content type of current playing media.""" return MEDIA_TYPE_MUSIC
[ "def", "media_content_type", "(", "self", ")", "->", "str", ":", "return", "MEDIA_TYPE_MUSIC" ]
[ 295, 4 ]
[ 297, 31 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_duration
(self)
Duration of current playing media in seconds.
Duration of current playing media in seconds.
def media_duration(self): """Duration of current playing media in seconds.""" duration = self._player.now_playing_media.duration if isinstance(duration, int): return duration / 1000 return None
[ "def", "media_duration", "(", "self", ")", ":", "duration", "=", "self", ".", "_player", ".", "now_playing_media", ".", "duration", "if", "isinstance", "(", "duration", ",", "int", ")", ":", "return", "duration", "/", "1000", "return", "None" ]
[ 300, 4 ]
[ 305, 19 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_position
(self)
Position of current playing media in seconds.
Position of current playing media in seconds.
def media_position(self): """Position of current playing media in seconds.""" # Some media doesn't have duration but reports position, return None if not self._player.now_playing_media.duration: return None return self._player.now_playing_media.current_position / 1000
[ "def", "media_position", "(", "self", ")", ":", "# Some media doesn't have duration but reports position, return None", "if", "not", "self", ".", "_player", ".", "now_playing_media", ".", "duration", ":", "return", "None", "return", "self", ".", "_player", ".", "now_playing_media", ".", "current_position", "/", "1000" ]
[ 308, 4 ]
[ 313, 69 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_position_updated_at
(self)
When was the position of the current playing media valid.
When was the position of the current playing media valid.
def media_position_updated_at(self): """When was the position of the current playing media valid.""" # Some media doesn't have duration but reports position, return None if not self._player.now_playing_media.duration: return None return self._media_position_updated_at
[ "def", "media_position_updated_at", "(", "self", ")", ":", "# Some media doesn't have duration but reports position, return None", "if", "not", "self", ".", "_player", ".", "now_playing_media", ".", "duration", ":", "return", "None", "return", "self", ".", "_media_position_updated_at" ]
[ 316, 4 ]
[ 321, 46 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_image_remotely_accessible
(self)
If the image url is remotely accessible.
If the image url is remotely accessible.
def media_image_remotely_accessible(self) -> bool: """If the image url is remotely accessible.""" return True
[ "def", "media_image_remotely_accessible", "(", "self", ")", "->", "bool", ":", "return", "True" ]
[ 324, 4 ]
[ 326, 19 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_image_url
(self)
Image url of current playing media.
Image url of current playing media.
def media_image_url(self) -> str: """Image url of current playing media.""" # May be an empty string, if so, return None image_url = self._player.now_playing_media.image_url return image_url if image_url else None
[ "def", "media_image_url", "(", "self", ")", "->", "str", ":", "# May be an empty string, if so, return None", "image_url", "=", "self", ".", "_player", ".", "now_playing_media", ".", "image_url", "return", "image_url", "if", "image_url", "else", "None" ]
[ 329, 4 ]
[ 333, 47 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.media_title
(self)
Title of current playing media.
Title of current playing media.
def media_title(self) -> str: """Title of current playing media.""" return self._player.now_playing_media.song
[ "def", "media_title", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_player", ".", "now_playing_media", ".", "song" ]
[ 336, 4 ]
[ 338, 50 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.name
(self)
Return the name of the device.
Return the name of the device.
def name(self) -> str: """Return the name of the device.""" return self._player.name
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_player", ".", "name" ]
[ 341, 4 ]
[ 343, 32 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.should_poll
(self)
No polling needed for this device.
No polling needed for this device.
def should_poll(self) -> bool: """No polling needed for this device.""" return False
[ "def", "should_poll", "(", "self", ")", "->", "bool", ":", "return", "False" ]
[ 346, 4 ]
[ 348, 20 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.shuffle
(self)
Boolean if shuffle is enabled.
Boolean if shuffle is enabled.
def shuffle(self) -> bool: """Boolean if shuffle is enabled.""" return self._player.shuffle
[ "def", "shuffle", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_player", ".", "shuffle" ]
[ 351, 4 ]
[ 353, 35 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.source
(self)
Name of the current input source.
Name of the current input source.
def source(self) -> str: """Name of the current input source.""" return self._source_manager.get_current_source(self._player.now_playing_media)
[ "def", "source", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_source_manager", ".", "get_current_source", "(", "self", ".", "_player", ".", "now_playing_media", ")" ]
[ 356, 4 ]
[ 358, 86 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.source_list
(self)
List of available input sources.
List of available input sources.
def source_list(self) -> Sequence[str]: """List of available input sources.""" return self._source_manager.source_list
[ "def", "source_list", "(", "self", ")", "->", "Sequence", "[", "str", "]", ":", "return", "self", ".", "_source_manager", ".", "source_list" ]
[ 361, 4 ]
[ 363, 47 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.state
(self)
State of the player.
State of the player.
def state(self) -> str: """State of the player.""" return PLAY_STATE_TO_STATE[self._player.state]
[ "def", "state", "(", "self", ")", "->", "str", ":", "return", "PLAY_STATE_TO_STATE", "[", "self", ".", "_player", ".", "state", "]" ]
[ 366, 4 ]
[ 368, 54 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.supported_features
(self)
Flag media player features that are supported.
Flag media player features that are supported.
def supported_features(self) -> int: """Flag media player features that are supported.""" return self._supported_features
[ "def", "supported_features", "(", "self", ")", "->", "int", ":", "return", "self", ".", "_supported_features" ]
[ 371, 4 ]
[ 373, 39 ]
python
en
['en', 'en', 'en']
True
HeosMediaPlayer.unique_id
(self)
Return a unique ID.
Return a unique ID.
def unique_id(self) -> str: """Return a unique ID.""" return str(self._player.player_id)
[ "def", "unique_id", "(", "self", ")", "->", "str", ":", "return", "str", "(", "self", ".", "_player", ".", "player_id", ")" ]
[ 376, 4 ]
[ 378, 42 ]
python
ca
['fr', 'ca', 'en']
False
HeosMediaPlayer.volume_level
(self)
Volume level of the media player (0..1).
Volume level of the media player (0..1).
def volume_level(self) -> float: """Volume level of the media player (0..1).""" return self._player.volume / 100
[ "def", "volume_level", "(", "self", ")", "->", "float", ":", "return", "self", ".", "_player", ".", "volume", "/", "100" ]
[ 381, 4 ]
[ 383, 40 ]
python
en
['en', 'en', 'en']
True
Subprocess.run
(command: str, timeout: int = None)
Run one-time command with subprocess.run(). Args: command (str): command to be executed. timeout (int): timeout in seconds. Returns: str: return stdout of the command.
Run one-time command with subprocess.run().
def run(command: str, timeout: int = None) -> str: """Run one-time command with subprocess.run(). Args: command (str): command to be executed. timeout (int): timeout in seconds. Returns: str: return stdout of the command. """ # TODO: Windows master completed_process = subprocess.run( command, executable="/bin/bash", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, timeout=timeout ) if completed_process.returncode != 0: raise Exception(completed_process.stderr) return completed_process.stdout.strip("\n")
[ "def", "run", "(", "command", ":", "str", ",", "timeout", ":", "int", "=", "None", ")", "->", "str", ":", "# TODO: Windows master", "completed_process", "=", "subprocess", ".", "run", "(", "command", ",", "executable", "=", "\"/bin/bash\"", ",", "shell", "=", "True", ",", "stdout", "=", "subprocess", ".", "PIPE", ",", "stderr", "=", "subprocess", ".", "PIPE", ",", "universal_newlines", "=", "True", ",", "timeout", "=", "timeout", ")", "if", "completed_process", ".", "returncode", "!=", "0", ":", "raise", "Exception", "(", "completed_process", ".", "stderr", ")", "return", "completed_process", ".", "stdout", ".", "strip", "(", "\"\\n\"", ")" ]
[ 13, 4 ]
[ 35, 51 ]
python
en
['en', 'en', 'en']
True
Subprocess.interactive_run
(command: str)
Run one-time command with subprocess.popen() and write stdout output interactively. Args: command (str): command to be executed. Returns: None.
Run one-time command with subprocess.popen() and write stdout output interactively.
def interactive_run(command: str) -> None: """Run one-time command with subprocess.popen() and write stdout output interactively. Args: command (str): command to be executed. Returns: None. """ # TODO: Windows master process = subprocess.Popen( command, executable="/bin/bash", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True ) while True: next_line = process.stdout.readline() if next_line == "" and process.poll() is not None: break sys.stdout.write(next_line) sys.stdout.flush() _, stderr = process.communicate() if stderr: sys.stderr.write(stderr)
[ "def", "interactive_run", "(", "command", ":", "str", ")", "->", "None", ":", "# TODO: Windows master", "process", "=", "subprocess", ".", "Popen", "(", "command", ",", "executable", "=", "\"/bin/bash\"", ",", "shell", "=", "True", ",", "stdout", "=", "subprocess", ".", "PIPE", ",", "stderr", "=", "subprocess", ".", "PIPE", ",", "universal_newlines", "=", "True", ")", "while", "True", ":", "next_line", "=", "process", ".", "stdout", ".", "readline", "(", ")", "if", "next_line", "==", "\"\"", "and", "process", ".", "poll", "(", ")", "is", "not", "None", ":", "break", "sys", ".", "stdout", ".", "write", "(", "next_line", ")", "sys", ".", "stdout", ".", "flush", "(", ")", "_", ",", "stderr", "=", "process", ".", "communicate", "(", ")", "if", "stderr", ":", "sys", ".", "stderr", ".", "write", "(", "stderr", ")" ]
[ 38, 4 ]
[ 64, 36 ]
python
en
['en', 'en', 'en']
True
panasonic_viera_setup_fixture
()
Mock panasonic_viera setup.
Mock panasonic_viera setup.
def panasonic_viera_setup_fixture(): """Mock panasonic_viera setup.""" with patch( "homeassistant.components.panasonic_viera.async_setup", return_value=True ), patch( "homeassistant.components.panasonic_viera.async_setup_entry", return_value=True, ): yield
[ "def", "panasonic_viera_setup_fixture", "(", ")", ":", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.async_setup\"", ",", "return_value", "=", "True", ")", ",", "patch", "(", "\"homeassistant.components.panasonic_viera.async_setup_entry\"", ",", "return_value", "=", "True", ",", ")", ":", "yield" ]
[ 28, 0 ]
[ 36, 13 ]
python
lv
['lv', 'ny', 'sw']
False
get_mock_remote
( host="1.2.3.4", request_error=None, authorize_error=None, encrypted=False, app_id=None, encryption_key=None, name=DEFAULT_NAME, manufacturer=DEFAULT_MANUFACTURER, model_number=DEFAULT_MODEL_NUMBER, unique_id="mock-unique-id", )
Return a mock remote.
Return a mock remote.
def get_mock_remote( host="1.2.3.4", request_error=None, authorize_error=None, encrypted=False, app_id=None, encryption_key=None, name=DEFAULT_NAME, manufacturer=DEFAULT_MANUFACTURER, model_number=DEFAULT_MODEL_NUMBER, unique_id="mock-unique-id", ): """Return a mock remote.""" mock_remote = Mock() mock_remote.type = TV_TYPE_ENCRYPTED if encrypted else TV_TYPE_NONENCRYPTED mock_remote.app_id = app_id mock_remote.enc_key = encryption_key def request_pin_code(name=None): if request_error is not None: raise request_error mock_remote.request_pin_code = request_pin_code def authorize_pin_code(pincode): if pincode == "1234": return if authorize_error is not None: raise authorize_error mock_remote.authorize_pin_code = authorize_pin_code def get_device_info(): return { ATTR_FRIENDLY_NAME: name, ATTR_MANUFACTURER: manufacturer, ATTR_MODEL_NUMBER: model_number, ATTR_UDN: unique_id, } mock_remote.get_device_info = get_device_info return mock_remote
[ "def", "get_mock_remote", "(", "host", "=", "\"1.2.3.4\"", ",", "request_error", "=", "None", ",", "authorize_error", "=", "None", ",", "encrypted", "=", "False", ",", "app_id", "=", "None", ",", "encryption_key", "=", "None", ",", "name", "=", "DEFAULT_NAME", ",", "manufacturer", "=", "DEFAULT_MANUFACTURER", ",", "model_number", "=", "DEFAULT_MODEL_NUMBER", ",", "unique_id", "=", "\"mock-unique-id\"", ",", ")", ":", "mock_remote", "=", "Mock", "(", ")", "mock_remote", ".", "type", "=", "TV_TYPE_ENCRYPTED", "if", "encrypted", "else", "TV_TYPE_NONENCRYPTED", "mock_remote", ".", "app_id", "=", "app_id", "mock_remote", ".", "enc_key", "=", "encryption_key", "def", "request_pin_code", "(", "name", "=", "None", ")", ":", "if", "request_error", "is", "not", "None", ":", "raise", "request_error", "mock_remote", ".", "request_pin_code", "=", "request_pin_code", "def", "authorize_pin_code", "(", "pincode", ")", ":", "if", "pincode", "==", "\"1234\"", ":", "return", "if", "authorize_error", "is", "not", "None", ":", "raise", "authorize_error", "mock_remote", ".", "authorize_pin_code", "=", "authorize_pin_code", "def", "get_device_info", "(", ")", ":", "return", "{", "ATTR_FRIENDLY_NAME", ":", "name", ",", "ATTR_MANUFACTURER", ":", "manufacturer", ",", "ATTR_MODEL_NUMBER", ":", "model_number", ",", "ATTR_UDN", ":", "unique_id", ",", "}", "mock_remote", ".", "get_device_info", "=", "get_device_info", "return", "mock_remote" ]
[ 39, 0 ]
[ 83, 22 ]
python
en
['en', 'co', 'en']
True
test_flow_non_encrypted
(hass)
Test flow without encryption.
Test flow without encryption.
async def test_flow_non_encrypted(hass): """Test flow without encryption.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" mock_remote = get_mock_remote(encrypted=False) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "create_entry" assert result["title"] == DEFAULT_NAME assert result["data"] == { CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: None, ATTR_DEVICE_INFO: { ATTR_FRIENDLY_NAME: DEFAULT_NAME, ATTR_MANUFACTURER: DEFAULT_MANUFACTURER, ATTR_MODEL_NUMBER: DEFAULT_MODEL_NUMBER, ATTR_UDN: "mock-unique-id", }, }
[ "async", "def", "test_flow_non_encrypted", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "False", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result", "[", "\"title\"", "]", "==", "DEFAULT_NAME", "assert", "result", "[", "\"data\"", "]", "==", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "None", ",", "ATTR_DEVICE_INFO", ":", "{", "ATTR_FRIENDLY_NAME", ":", "DEFAULT_NAME", ",", "ATTR_MANUFACTURER", ":", "DEFAULT_MANUFACTURER", ",", "ATTR_MODEL_NUMBER", ":", "DEFAULT_MODEL_NUMBER", ",", "ATTR_UDN", ":", "\"mock-unique-id\"", ",", "}", ",", "}" ]
[ 86, 0 ]
[ 120, 5 ]
python
en
['en', 'en', 'en']
True
test_flow_not_connected_error
(hass)
Test flow with connection error.
Test flow with connection error.
async def test_flow_not_connected_error(hass): """Test flow with connection error.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", side_effect=TimeoutError, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "form" assert result["step_id"] == "user" assert result["errors"] == {"base": "cannot_connect"}
[ "async", "def", "test_flow_not_connected_error", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "side_effect", "=", "TimeoutError", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "assert", "result", "[", "\"errors\"", "]", "==", "{", "\"base\"", ":", "\"cannot_connect\"", "}" ]
[ 123, 0 ]
[ 144, 57 ]
python
en
['en', 'en', 'en']
True
test_flow_unknown_abort
(hass)
Test flow with unknown error abortion.
Test flow with unknown error abortion.
async def test_flow_unknown_abort(hass): """Test flow with unknown error abortion.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", side_effect=Exception, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "abort" assert result["reason"] == "unknown"
[ "async", "def", "test_flow_unknown_abort", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "side_effect", "=", "Exception", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"unknown\"" ]
[ 147, 0 ]
[ 167, 40 ]
python
en
['en', 'de', 'en']
True
test_flow_encrypted_not_connected_pin_code_request
(hass)
Test flow with encryption and PIN code request connection error abortion during pairing request step.
Test flow with encryption and PIN code request connection error abortion during pairing request step.
async def test_flow_encrypted_not_connected_pin_code_request(hass): """Test flow with encryption and PIN code request connection error abortion during pairing request step.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" mock_remote = get_mock_remote(encrypted=True, request_error=TimeoutError) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "abort" assert result["reason"] == "cannot_connect"
[ "async", "def", "test_flow_encrypted_not_connected_pin_code_request", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "request_error", "=", "TimeoutError", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"cannot_connect\"" ]
[ 170, 0 ]
[ 192, 47 ]
python
en
['en', 'en', 'en']
True
test_flow_encrypted_unknown_pin_code_request
(hass)
Test flow with encryption and PIN code request unknown error abortion during pairing request step.
Test flow with encryption and PIN code request unknown error abortion during pairing request step.
async def test_flow_encrypted_unknown_pin_code_request(hass): """Test flow with encryption and PIN code request unknown error abortion during pairing request step.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" mock_remote = get_mock_remote(encrypted=True, request_error=Exception) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "abort" assert result["reason"] == "unknown"
[ "async", "def", "test_flow_encrypted_unknown_pin_code_request", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "request_error", "=", "Exception", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"unknown\"" ]
[ 195, 0 ]
[ 217, 40 ]
python
en
['en', 'en', 'en']
True
test_flow_encrypted_valid_pin_code
(hass)
Test flow with encryption and valid PIN code.
Test flow with encryption and valid PIN code.
async def test_flow_encrypted_valid_pin_code(hass): """Test flow with encryption and valid PIN code.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" mock_remote = get_mock_remote( encrypted=True, app_id="test-app-id", encryption_key="test-encryption-key", ) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "form" assert result["step_id"] == "pairing" result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_PIN: "1234"}, ) assert result["type"] == "create_entry" assert result["title"] == DEFAULT_NAME assert result["data"] == { CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: None, CONF_APP_ID: "test-app-id", CONF_ENCRYPTION_KEY: "test-encryption-key", ATTR_DEVICE_INFO: { ATTR_FRIENDLY_NAME: DEFAULT_NAME, ATTR_MANUFACTURER: DEFAULT_MANUFACTURER, ATTR_MODEL_NUMBER: DEFAULT_MODEL_NUMBER, ATTR_UDN: "mock-unique-id", }, }
[ "async", "def", "test_flow_encrypted_valid_pin_code", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "app_id", "=", "\"test-app-id\"", ",", "encryption_key", "=", "\"test-encryption-key\"", ",", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_PIN", ":", "\"1234\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result", "[", "\"title\"", "]", "==", "DEFAULT_NAME", "assert", "result", "[", "\"data\"", "]", "==", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "None", ",", "CONF_APP_ID", ":", "\"test-app-id\"", ",", "CONF_ENCRYPTION_KEY", ":", "\"test-encryption-key\"", ",", "ATTR_DEVICE_INFO", ":", "{", "ATTR_FRIENDLY_NAME", ":", "DEFAULT_NAME", ",", "ATTR_MANUFACTURER", ":", "DEFAULT_MANUFACTURER", ",", "ATTR_MODEL_NUMBER", ":", "DEFAULT_MODEL_NUMBER", ",", "ATTR_UDN", ":", "\"mock-unique-id\"", ",", "}", ",", "}" ]
[ 220, 0 ]
[ 268, 5 ]
python
en
['en', 'en', 'en']
True
test_flow_encrypted_invalid_pin_code_error
(hass)
Test flow with encryption and invalid PIN code error during pairing step.
Test flow with encryption and invalid PIN code error during pairing step.
async def test_flow_encrypted_invalid_pin_code_error(hass): """Test flow with encryption and invalid PIN code error during pairing step.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" mock_remote = get_mock_remote(encrypted=True, authorize_error=SOAPError) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "form" assert result["step_id"] == "pairing" with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_PIN: "0000"}, ) assert result["type"] == "form" assert result["step_id"] == "pairing" assert result["errors"] == {"base": ERROR_INVALID_PIN_CODE}
[ "async", "def", "test_flow_encrypted_invalid_pin_code_error", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "authorize_error", "=", "SOAPError", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_PIN", ":", "\"0000\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "assert", "result", "[", "\"errors\"", "]", "==", "{", "\"base\"", ":", "ERROR_INVALID_PIN_CODE", "}" ]
[ 271, 0 ]
[ 306, 63 ]
python
en
['en', 'en', 'en']
True
test_flow_encrypted_not_connected_abort
(hass)
Test flow with encryption and PIN code connection error abortion during pairing step.
Test flow with encryption and PIN code connection error abortion during pairing step.
async def test_flow_encrypted_not_connected_abort(hass): """Test flow with encryption and PIN code connection error abortion during pairing step.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" mock_remote = get_mock_remote(encrypted=True, authorize_error=TimeoutError) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "form" assert result["step_id"] == "pairing" result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_PIN: "0000"}, ) assert result["type"] == "abort" assert result["reason"] == "cannot_connect"
[ "async", "def", "test_flow_encrypted_not_connected_abort", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "authorize_error", "=", "TimeoutError", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_PIN", ":", "\"0000\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"cannot_connect\"" ]
[ 309, 0 ]
[ 339, 47 ]
python
en
['en', 'en', 'en']
True
test_flow_encrypted_unknown_abort
(hass)
Test flow with encryption and PIN code unknown error abortion during pairing step.
Test flow with encryption and PIN code unknown error abortion during pairing step.
async def test_flow_encrypted_unknown_abort(hass): """Test flow with encryption and PIN code unknown error abortion during pairing step.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" mock_remote = get_mock_remote(encrypted=True, authorize_error=Exception) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "form" assert result["step_id"] == "pairing" result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_PIN: "0000"}, ) assert result["type"] == "abort" assert result["reason"] == "unknown"
[ "async", "def", "test_flow_encrypted_unknown_abort", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "authorize_error", "=", "Exception", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_PIN", ":", "\"0000\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"unknown\"" ]
[ 342, 0 ]
[ 372, 40 ]
python
en
['en', 'en', 'en']
True
test_flow_non_encrypted_already_configured_abort
(hass)
Test flow without encryption and existing config entry abortion.
Test flow without encryption and existing config entry abortion.
async def test_flow_non_encrypted_already_configured_abort(hass): """Test flow without encryption and existing config entry abortion.""" MockConfigEntry( domain=DOMAIN, unique_id="1.2.3.4", data={CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT}, ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data={CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "abort" assert result["reason"] == "already_configured"
[ "async", "def", "test_flow_non_encrypted_already_configured_abort", "(", "hass", ")", ":", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "unique_id", "=", "\"1.2.3.4\"", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", "}", ",", ")", ".", "add_to_hass", "(", "hass", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"already_configured\"" ]
[ 375, 0 ]
[ 391, 51 ]
python
en
['en', 'en', 'en']
True
test_flow_encrypted_already_configured_abort
(hass)
Test flow with encryption and existing config entry abortion.
Test flow with encryption and existing config entry abortion.
async def test_flow_encrypted_already_configured_abort(hass): """Test flow with encryption and existing config entry abortion.""" MockConfigEntry( domain=DOMAIN, unique_id="1.2.3.4", data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_APP_ID: "test-app-id", CONF_ENCRYPTION_KEY: "test-encryption-key", }, ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data={CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "abort" assert result["reason"] == "already_configured"
[ "async", "def", "test_flow_encrypted_already_configured_abort", "(", "hass", ")", ":", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "unique_id", "=", "\"1.2.3.4\"", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_APP_ID", ":", "\"test-app-id\"", ",", "CONF_ENCRYPTION_KEY", ":", "\"test-encryption-key\"", ",", "}", ",", ")", ".", "add_to_hass", "(", "hass", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"already_configured\"" ]
[ 394, 0 ]
[ 416, 51 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_non_encrypted
(hass)
Test imported flow without encryption.
Test imported flow without encryption.
async def test_imported_flow_non_encrypted(hass): """Test imported flow without encryption.""" mock_remote = get_mock_remote(encrypted=False) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", }, ) assert result["type"] == "create_entry" assert result["title"] == DEFAULT_NAME assert result["data"] == { CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", ATTR_DEVICE_INFO: { ATTR_FRIENDLY_NAME: DEFAULT_NAME, ATTR_MANUFACTURER: DEFAULT_MANUFACTURER, ATTR_MODEL_NUMBER: DEFAULT_MODEL_NUMBER, ATTR_UDN: "mock-unique-id", }, }
[ "async", "def", "test_imported_flow_non_encrypted", "(", "hass", ")", ":", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "False", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result", "[", "\"title\"", "]", "==", "DEFAULT_NAME", "assert", "result", "[", "\"data\"", "]", "==", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "ATTR_DEVICE_INFO", ":", "{", "ATTR_FRIENDLY_NAME", ":", "DEFAULT_NAME", ",", "ATTR_MANUFACTURER", ":", "DEFAULT_MANUFACTURER", ",", "ATTR_MODEL_NUMBER", ":", "DEFAULT_MODEL_NUMBER", ",", "ATTR_UDN", ":", "\"mock-unique-id\"", ",", "}", ",", "}" ]
[ 419, 0 ]
[ 452, 5 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_encrypted_valid_pin_code
(hass)
Test imported flow with encryption and valid PIN code.
Test imported flow with encryption and valid PIN code.
async def test_imported_flow_encrypted_valid_pin_code(hass): """Test imported flow with encryption and valid PIN code.""" mock_remote = get_mock_remote( encrypted=True, app_id="test-app-id", encryption_key="test-encryption-key", ) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", }, ) assert result["type"] == "form" assert result["step_id"] == "pairing" result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_PIN: "1234"}, ) assert result["type"] == "create_entry" assert result["title"] == DEFAULT_NAME assert result["data"] == { CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", CONF_APP_ID: "test-app-id", CONF_ENCRYPTION_KEY: "test-encryption-key", ATTR_DEVICE_INFO: { ATTR_FRIENDLY_NAME: DEFAULT_NAME, ATTR_MANUFACTURER: DEFAULT_MANUFACTURER, ATTR_MODEL_NUMBER: DEFAULT_MODEL_NUMBER, ATTR_UDN: "mock-unique-id", }, }
[ "async", "def", "test_imported_flow_encrypted_valid_pin_code", "(", "hass", ")", ":", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "app_id", "=", "\"test-app-id\"", ",", "encryption_key", "=", "\"test-encryption-key\"", ",", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_PIN", ":", "\"1234\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result", "[", "\"title\"", "]", "==", "DEFAULT_NAME", "assert", "result", "[", "\"data\"", "]", "==", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "CONF_APP_ID", ":", "\"test-app-id\"", ",", "CONF_ENCRYPTION_KEY", ":", "\"test-encryption-key\"", ",", "ATTR_DEVICE_INFO", ":", "{", "ATTR_FRIENDLY_NAME", ":", "DEFAULT_NAME", ",", "ATTR_MANUFACTURER", ":", "DEFAULT_MANUFACTURER", ",", "ATTR_MODEL_NUMBER", ":", "DEFAULT_MODEL_NUMBER", ",", "ATTR_UDN", ":", "\"mock-unique-id\"", ",", "}", ",", "}" ]
[ 455, 0 ]
[ 502, 5 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_encrypted_invalid_pin_code_error
(hass)
Test imported flow with encryption and invalid PIN code error during pairing step.
Test imported flow with encryption and invalid PIN code error during pairing step.
async def test_imported_flow_encrypted_invalid_pin_code_error(hass): """Test imported flow with encryption and invalid PIN code error during pairing step.""" mock_remote = get_mock_remote(encrypted=True, authorize_error=SOAPError) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", }, ) assert result["type"] == "form" assert result["step_id"] == "pairing" with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_PIN: "0000"}, ) assert result["type"] == "form" assert result["step_id"] == "pairing" assert result["errors"] == {"base": ERROR_INVALID_PIN_CODE}
[ "async", "def", "test_imported_flow_encrypted_invalid_pin_code_error", "(", "hass", ")", ":", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "authorize_error", "=", "SOAPError", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_PIN", ":", "\"0000\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "assert", "result", "[", "\"errors\"", "]", "==", "{", "\"base\"", ":", "ERROR_INVALID_PIN_CODE", "}" ]
[ 505, 0 ]
[ 539, 63 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_encrypted_not_connected_abort
(hass)
Test imported flow with encryption and PIN code connection error abortion during pairing step.
Test imported flow with encryption and PIN code connection error abortion during pairing step.
async def test_imported_flow_encrypted_not_connected_abort(hass): """Test imported flow with encryption and PIN code connection error abortion during pairing step.""" mock_remote = get_mock_remote(encrypted=True, authorize_error=TimeoutError) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", }, ) assert result["type"] == "form" assert result["step_id"] == "pairing" result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_PIN: "0000"}, ) assert result["type"] == "abort" assert result["reason"] == "cannot_connect"
[ "async", "def", "test_imported_flow_encrypted_not_connected_abort", "(", "hass", ")", ":", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "authorize_error", "=", "TimeoutError", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_PIN", ":", "\"0000\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"cannot_connect\"" ]
[ 542, 0 ]
[ 571, 47 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_encrypted_unknown_abort
(hass)
Test imported flow with encryption and PIN code unknown error abortion during pairing step.
Test imported flow with encryption and PIN code unknown error abortion during pairing step.
async def test_imported_flow_encrypted_unknown_abort(hass): """Test imported flow with encryption and PIN code unknown error abortion during pairing step.""" mock_remote = get_mock_remote(encrypted=True, authorize_error=Exception) with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", return_value=mock_remote, ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", }, ) assert result["type"] == "form" assert result["step_id"] == "pairing" result = await hass.config_entries.flow.async_configure( result["flow_id"], {CONF_PIN: "0000"}, ) assert result["type"] == "abort" assert result["reason"] == "unknown"
[ "async", "def", "test_imported_flow_encrypted_unknown_abort", "(", "hass", ")", ":", "mock_remote", "=", "get_mock_remote", "(", "encrypted", "=", "True", ",", "authorize_error", "=", "Exception", ")", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "return_value", "=", "mock_remote", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"pairing\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "CONF_PIN", ":", "\"0000\"", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"unknown\"" ]
[ 574, 0 ]
[ 603, 40 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_not_connected_error
(hass)
Test imported flow with connection error abortion.
Test imported flow with connection error abortion.
async def test_imported_flow_not_connected_error(hass): """Test imported flow with connection error abortion.""" with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", side_effect=TimeoutError, ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", }, ) assert result["type"] == "form" assert result["step_id"] == "user" assert result["errors"] == {"base": "cannot_connect"}
[ "async", "def", "test_imported_flow_not_connected_error", "(", "hass", ")", ":", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "side_effect", "=", "TimeoutError", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"step_id\"", "]", "==", "\"user\"", "assert", "result", "[", "\"errors\"", "]", "==", "{", "\"base\"", ":", "\"cannot_connect\"", "}" ]
[ 606, 0 ]
[ 626, 57 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_unknown_abort
(hass)
Test imported flow with unknown error abortion.
Test imported flow with unknown error abortion.
async def test_imported_flow_unknown_abort(hass): """Test imported flow with unknown error abortion.""" with patch( "homeassistant.components.panasonic_viera.config_flow.RemoteControl", side_effect=Exception, ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", }, ) assert result["type"] == "abort" assert result["reason"] == "unknown"
[ "async", "def", "test_imported_flow_unknown_abort", "(", "hass", ")", ":", "with", "patch", "(", "\"homeassistant.components.panasonic_viera.config_flow.RemoteControl\"", ",", "side_effect", "=", "Exception", ",", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"unknown\"" ]
[ 629, 0 ]
[ 648, 40 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_non_encrypted_already_configured_abort
(hass)
Test imported flow without encryption and existing config entry abortion.
Test imported flow without encryption and existing config entry abortion.
async def test_imported_flow_non_encrypted_already_configured_abort(hass): """Test imported flow without encryption and existing config entry abortion.""" MockConfigEntry( domain=DOMAIN, unique_id="1.2.3.4", data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", }, ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "abort" assert result["reason"] == "already_configured"
[ "async", "def", "test_imported_flow_non_encrypted_already_configured_abort", "(", "hass", ")", ":", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "unique_id", "=", "\"1.2.3.4\"", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "}", ",", ")", ".", "add_to_hass", "(", "hass", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"already_configured\"" ]
[ 651, 0 ]
[ 672, 51 ]
python
en
['en', 'en', 'en']
True
test_imported_flow_encrypted_already_configured_abort
(hass)
Test imported flow with encryption and existing config entry abortion.
Test imported flow with encryption and existing config entry abortion.
async def test_imported_flow_encrypted_already_configured_abort(hass): """Test imported flow with encryption and existing config entry abortion.""" MockConfigEntry( domain=DOMAIN, unique_id="1.2.3.4", data={ CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME, CONF_PORT: DEFAULT_PORT, CONF_ON_ACTION: "test-on-action", CONF_APP_ID: "test-app-id", CONF_ENCRYPTION_KEY: "test-encryption-key", }, ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME}, ) assert result["type"] == "abort" assert result["reason"] == "already_configured"
[ "async", "def", "test_imported_flow_encrypted_already_configured_abort", "(", "hass", ")", ":", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "unique_id", "=", "\"1.2.3.4\"", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", ",", "CONF_PORT", ":", "DEFAULT_PORT", ",", "CONF_ON_ACTION", ":", "\"test-on-action\"", ",", "CONF_APP_ID", ":", "\"test-app-id\"", ",", "CONF_ENCRYPTION_KEY", ":", "\"test-encryption-key\"", ",", "}", ",", ")", ".", "add_to_hass", "(", "hass", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_IMPORT", "}", ",", "data", "=", "{", "CONF_HOST", ":", "\"1.2.3.4\"", ",", "CONF_NAME", ":", "DEFAULT_NAME", "}", ",", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"already_configured\"" ]
[ 675, 0 ]
[ 698, 51 ]
python
en
['en', 'en', 'en']
True
test_generate_entity_id_requires_hass_or_ids
()
Ensure we require at least hass or current ids.
Ensure we require at least hass or current ids.
def test_generate_entity_id_requires_hass_or_ids(): """Ensure we require at least hass or current ids.""" with pytest.raises(ValueError): entity.generate_entity_id("test.{}", "hello world")
[ "def", "test_generate_entity_id_requires_hass_or_ids", "(", ")", ":", "with", "pytest", ".", "raises", "(", "ValueError", ")", ":", "entity", ".", "generate_entity_id", "(", "\"test.{}\"", ",", "\"hello world\"", ")" ]
[ 22, 0 ]
[ 25, 59 ]
python
en
['en', 'en', 'en']
True
test_generate_entity_id_given_keys
()
Test generating an entity id given current ids.
Test generating an entity id given current ids.
def test_generate_entity_id_given_keys(): """Test generating an entity id given current ids.""" assert ( entity.generate_entity_id( "test.{}", "overwrite hidden true", current_ids=["test.overwrite_hidden_true"], ) == "test.overwrite_hidden_true_2" ) assert ( entity.generate_entity_id( "test.{}", "overwrite hidden true", current_ids=["test.another_entity"] ) == "test.overwrite_hidden_true" )
[ "def", "test_generate_entity_id_given_keys", "(", ")", ":", "assert", "(", "entity", ".", "generate_entity_id", "(", "\"test.{}\"", ",", "\"overwrite hidden true\"", ",", "current_ids", "=", "[", "\"test.overwrite_hidden_true\"", "]", ",", ")", "==", "\"test.overwrite_hidden_true_2\"", ")", "assert", "(", "entity", ".", "generate_entity_id", "(", "\"test.{}\"", ",", "\"overwrite hidden true\"", ",", "current_ids", "=", "[", "\"test.another_entity\"", "]", ")", "==", "\"test.overwrite_hidden_true\"", ")" ]
[ 28, 0 ]
[ 43, 5 ]
python
en
['en', 'en', 'en']
True
test_async_update_support
(hass)
Test async update getting called.
Test async update getting called.
async def test_async_update_support(hass): """Test async update getting called.""" sync_update = [] async_update = [] class AsyncEntity(entity.Entity): """A test entity.""" entity_id = "sensor.test" def update(self): """Update entity.""" sync_update.append([1]) ent = AsyncEntity() ent.hass = hass await ent.async_update_ha_state(True) assert len(sync_update) == 1 assert len(async_update) == 0 async def async_update_func(): """Async update.""" async_update.append(1) ent.async_update = async_update_func await ent.async_update_ha_state(True) assert len(sync_update) == 1 assert len(async_update) == 1
[ "async", "def", "test_async_update_support", "(", "hass", ")", ":", "sync_update", "=", "[", "]", "async_update", "=", "[", "]", "class", "AsyncEntity", "(", "entity", ".", "Entity", ")", ":", "\"\"\"A test entity.\"\"\"", "entity_id", "=", "\"sensor.test\"", "def", "update", "(", "self", ")", ":", "\"\"\"Update entity.\"\"\"", "sync_update", ".", "append", "(", "[", "1", "]", ")", "ent", "=", "AsyncEntity", "(", ")", "ent", ".", "hass", "=", "hass", "await", "ent", ".", "async_update_ha_state", "(", "True", ")", "assert", "len", "(", "sync_update", ")", "==", "1", "assert", "len", "(", "async_update", ")", "==", "0", "async", "def", "async_update_func", "(", ")", ":", "\"\"\"Async update.\"\"\"", "async_update", ".", "append", "(", "1", ")", "ent", ".", "async_update", "=", "async_update_func", "await", "ent", ".", "async_update_ha_state", "(", "True", ")", "assert", "len", "(", "sync_update", ")", "==", "1", "assert", "len", "(", "async_update", ")", "==", "1" ]
[ 46, 0 ]
[ 77, 33 ]
python
en
['nl', 'en', 'en']
True
test_warn_slow_update
(hass, caplog)
Warn we log when entity update takes a long time.
Warn we log when entity update takes a long time.
async def test_warn_slow_update(hass, caplog): """Warn we log when entity update takes a long time.""" update_call = False async def async_update(): """Mock async update.""" nonlocal update_call await asyncio.sleep(0.00001) update_call = True mock_entity = entity.Entity() mock_entity.hass = hass mock_entity.entity_id = "comp_test.test_entity" mock_entity.async_update = async_update fast_update_time = 0.0000001 with patch.object(entity, "SLOW_UPDATE_WARNING", fast_update_time): await mock_entity.async_update_ha_state(True) assert str(fast_update_time) in caplog.text assert mock_entity.entity_id in caplog.text assert update_call
[ "async", "def", "test_warn_slow_update", "(", "hass", ",", "caplog", ")", ":", "update_call", "=", "False", "async", "def", "async_update", "(", ")", ":", "\"\"\"Mock async update.\"\"\"", "nonlocal", "update_call", "await", "asyncio", ".", "sleep", "(", "0.00001", ")", "update_call", "=", "True", "mock_entity", "=", "entity", ".", "Entity", "(", ")", "mock_entity", ".", "hass", "=", "hass", "mock_entity", ".", "entity_id", "=", "\"comp_test.test_entity\"", "mock_entity", ".", "async_update", "=", "async_update", "fast_update_time", "=", "0.0000001", "with", "patch", ".", "object", "(", "entity", ",", "\"SLOW_UPDATE_WARNING\"", ",", "fast_update_time", ")", ":", "await", "mock_entity", ".", "async_update_ha_state", "(", "True", ")", "assert", "str", "(", "fast_update_time", ")", "in", "caplog", ".", "text", "assert", "mock_entity", ".", "entity_id", "in", "caplog", ".", "text", "assert", "update_call" ]
[ 116, 0 ]
[ 137, 26 ]
python
en
['en', 'en', 'en']
True
test_warn_slow_update_with_exception
(hass, caplog)
Warn we log when entity update takes a long time and trow exception.
Warn we log when entity update takes a long time and trow exception.
async def test_warn_slow_update_with_exception(hass, caplog): """Warn we log when entity update takes a long time and trow exception.""" update_call = False async def async_update(): """Mock async update.""" nonlocal update_call update_call = True await asyncio.sleep(0.00001) raise AssertionError("Fake update error") mock_entity = entity.Entity() mock_entity.hass = hass mock_entity.entity_id = "comp_test.test_entity" mock_entity.async_update = async_update fast_update_time = 0.0000001 with patch.object(entity, "SLOW_UPDATE_WARNING", fast_update_time): await mock_entity.async_update_ha_state(True) assert str(fast_update_time) in caplog.text assert mock_entity.entity_id in caplog.text assert update_call
[ "async", "def", "test_warn_slow_update_with_exception", "(", "hass", ",", "caplog", ")", ":", "update_call", "=", "False", "async", "def", "async_update", "(", ")", ":", "\"\"\"Mock async update.\"\"\"", "nonlocal", "update_call", "update_call", "=", "True", "await", "asyncio", ".", "sleep", "(", "0.00001", ")", "raise", "AssertionError", "(", "\"Fake update error\"", ")", "mock_entity", "=", "entity", ".", "Entity", "(", ")", "mock_entity", ".", "hass", "=", "hass", "mock_entity", ".", "entity_id", "=", "\"comp_test.test_entity\"", "mock_entity", ".", "async_update", "=", "async_update", "fast_update_time", "=", "0.0000001", "with", "patch", ".", "object", "(", "entity", ",", "\"SLOW_UPDATE_WARNING\"", ",", "fast_update_time", ")", ":", "await", "mock_entity", ".", "async_update_ha_state", "(", "True", ")", "assert", "str", "(", "fast_update_time", ")", "in", "caplog", ".", "text", "assert", "mock_entity", ".", "entity_id", "in", "caplog", ".", "text", "assert", "update_call" ]
[ 140, 0 ]
[ 162, 26 ]
python
en
['en', 'en', 'en']
True
test_warn_slow_device_update_disabled
(hass, caplog)
Disable slow update warning with async_device_update.
Disable slow update warning with async_device_update.
async def test_warn_slow_device_update_disabled(hass, caplog): """Disable slow update warning with async_device_update.""" update_call = False async def async_update(): """Mock async update.""" nonlocal update_call await asyncio.sleep(0.00001) update_call = True mock_entity = entity.Entity() mock_entity.hass = hass mock_entity.entity_id = "comp_test.test_entity" mock_entity.async_update = async_update fast_update_time = 0.0000001 with patch.object(entity, "SLOW_UPDATE_WARNING", fast_update_time): await mock_entity.async_device_update(warning=False) assert str(fast_update_time) not in caplog.text assert mock_entity.entity_id not in caplog.text assert update_call
[ "async", "def", "test_warn_slow_device_update_disabled", "(", "hass", ",", "caplog", ")", ":", "update_call", "=", "False", "async", "def", "async_update", "(", ")", ":", "\"\"\"Mock async update.\"\"\"", "nonlocal", "update_call", "await", "asyncio", ".", "sleep", "(", "0.00001", ")", "update_call", "=", "True", "mock_entity", "=", "entity", ".", "Entity", "(", ")", "mock_entity", ".", "hass", "=", "hass", "mock_entity", ".", "entity_id", "=", "\"comp_test.test_entity\"", "mock_entity", ".", "async_update", "=", "async_update", "fast_update_time", "=", "0.0000001", "with", "patch", ".", "object", "(", "entity", ",", "\"SLOW_UPDATE_WARNING\"", ",", "fast_update_time", ")", ":", "await", "mock_entity", ".", "async_device_update", "(", "warning", "=", "False", ")", "assert", "str", "(", "fast_update_time", ")", "not", "in", "caplog", ".", "text", "assert", "mock_entity", ".", "entity_id", "not", "in", "caplog", ".", "text", "assert", "update_call" ]
[ 165, 0 ]
[ 186, 26 ]
python
en
['en', 'en', 'en']
True
test_async_schedule_update_ha_state
(hass)
Warn we log when entity update takes a long time and trow exception.
Warn we log when entity update takes a long time and trow exception.
async def test_async_schedule_update_ha_state(hass): """Warn we log when entity update takes a long time and trow exception.""" update_call = False async def async_update(): """Mock async update.""" nonlocal update_call update_call = True mock_entity = entity.Entity() mock_entity.hass = hass mock_entity.entity_id = "comp_test.test_entity" mock_entity.async_update = async_update mock_entity.async_schedule_update_ha_state(True) await hass.async_block_till_done() assert update_call is True
[ "async", "def", "test_async_schedule_update_ha_state", "(", "hass", ")", ":", "update_call", "=", "False", "async", "def", "async_update", "(", ")", ":", "\"\"\"Mock async update.\"\"\"", "nonlocal", "update_call", "update_call", "=", "True", "mock_entity", "=", "entity", ".", "Entity", "(", ")", "mock_entity", ".", "hass", "=", "hass", "mock_entity", ".", "entity_id", "=", "\"comp_test.test_entity\"", "mock_entity", ".", "async_update", "=", "async_update", "mock_entity", ".", "async_schedule_update_ha_state", "(", "True", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "update_call", "is", "True" ]
[ 189, 0 ]
[ 206, 30 ]
python
en
['en', 'en', 'en']
True
test_async_async_request_call_without_lock
(hass)
Test for async_requests_call works without a lock.
Test for async_requests_call works without a lock.
async def test_async_async_request_call_without_lock(hass): """Test for async_requests_call works without a lock.""" updates = [] class AsyncEntity(entity.Entity): """Test entity.""" def __init__(self, entity_id): """Initialize Async test entity.""" self.entity_id = entity_id self.hass = hass async def testhelper(self, count): """Helper function.""" updates.append(count) ent_1 = AsyncEntity("light.test_1") ent_2 = AsyncEntity("light.test_2") try: job1 = ent_1.async_request_call(ent_1.testhelper(1)) job2 = ent_2.async_request_call(ent_2.testhelper(2)) await asyncio.wait([job1, job2]) while True: if len(updates) >= 2: break await asyncio.sleep(0) finally: pass assert len(updates) == 2 updates.sort() assert updates == [1, 2]
[ "async", "def", "test_async_async_request_call_without_lock", "(", "hass", ")", ":", "updates", "=", "[", "]", "class", "AsyncEntity", "(", "entity", ".", "Entity", ")", ":", "\"\"\"Test entity.\"\"\"", "def", "__init__", "(", "self", ",", "entity_id", ")", ":", "\"\"\"Initialize Async test entity.\"\"\"", "self", ".", "entity_id", "=", "entity_id", "self", ".", "hass", "=", "hass", "async", "def", "testhelper", "(", "self", ",", "count", ")", ":", "\"\"\"Helper function.\"\"\"", "updates", ".", "append", "(", "count", ")", "ent_1", "=", "AsyncEntity", "(", "\"light.test_1\"", ")", "ent_2", "=", "AsyncEntity", "(", "\"light.test_2\"", ")", "try", ":", "job1", "=", "ent_1", ".", "async_request_call", "(", "ent_1", ".", "testhelper", "(", "1", ")", ")", "job2", "=", "ent_2", ".", "async_request_call", "(", "ent_2", ".", "testhelper", "(", "2", ")", ")", "await", "asyncio", ".", "wait", "(", "[", "job1", ",", "job2", "]", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "2", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "finally", ":", "pass", "assert", "len", "(", "updates", ")", "==", "2", "updates", ".", "sort", "(", ")", "assert", "updates", "==", "[", "1", ",", "2", "]" ]
[ 209, 0 ]
[ 241, 28 ]
python
en
['en', 'en', 'en']
True
test_async_async_request_call_with_lock
(hass)
Test for async_requests_call works with a semaphore.
Test for async_requests_call works with a semaphore.
async def test_async_async_request_call_with_lock(hass): """Test for async_requests_call works with a semaphore.""" updates = [] test_semaphore = asyncio.Semaphore(1) class AsyncEntity(entity.Entity): """Test entity.""" def __init__(self, entity_id, lock): """Initialize Async test entity.""" self.entity_id = entity_id self.hass = hass self.parallel_updates = lock async def testhelper(self, count): """Helper function.""" updates.append(count) ent_1 = AsyncEntity("light.test_1", test_semaphore) ent_2 = AsyncEntity("light.test_2", test_semaphore) try: assert test_semaphore.locked() is False await test_semaphore.acquire() assert test_semaphore.locked() job1 = ent_1.async_request_call(ent_1.testhelper(1)) job2 = ent_2.async_request_call(ent_2.testhelper(2)) hass.async_create_task(job1) hass.async_create_task(job2) assert len(updates) == 0 assert updates == [] assert test_semaphore._value == 0 test_semaphore.release() while True: if len(updates) >= 2: break await asyncio.sleep(0) finally: test_semaphore.release() assert len(updates) == 2 updates.sort() assert updates == [1, 2]
[ "async", "def", "test_async_async_request_call_with_lock", "(", "hass", ")", ":", "updates", "=", "[", "]", "test_semaphore", "=", "asyncio", ".", "Semaphore", "(", "1", ")", "class", "AsyncEntity", "(", "entity", ".", "Entity", ")", ":", "\"\"\"Test entity.\"\"\"", "def", "__init__", "(", "self", ",", "entity_id", ",", "lock", ")", ":", "\"\"\"Initialize Async test entity.\"\"\"", "self", ".", "entity_id", "=", "entity_id", "self", ".", "hass", "=", "hass", "self", ".", "parallel_updates", "=", "lock", "async", "def", "testhelper", "(", "self", ",", "count", ")", ":", "\"\"\"Helper function.\"\"\"", "updates", ".", "append", "(", "count", ")", "ent_1", "=", "AsyncEntity", "(", "\"light.test_1\"", ",", "test_semaphore", ")", "ent_2", "=", "AsyncEntity", "(", "\"light.test_2\"", ",", "test_semaphore", ")", "try", ":", "assert", "test_semaphore", ".", "locked", "(", ")", "is", "False", "await", "test_semaphore", ".", "acquire", "(", ")", "assert", "test_semaphore", ".", "locked", "(", ")", "job1", "=", "ent_1", ".", "async_request_call", "(", "ent_1", ".", "testhelper", "(", "1", ")", ")", "job2", "=", "ent_2", ".", "async_request_call", "(", "ent_2", ".", "testhelper", "(", "2", ")", ")", "hass", ".", "async_create_task", "(", "job1", ")", "hass", ".", "async_create_task", "(", "job2", ")", "assert", "len", "(", "updates", ")", "==", "0", "assert", "updates", "==", "[", "]", "assert", "test_semaphore", ".", "_value", "==", "0", "test_semaphore", ".", "release", "(", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "2", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "finally", ":", "test_semaphore", ".", "release", "(", ")", "assert", "len", "(", "updates", ")", "==", "2", "updates", ".", "sort", "(", ")", "assert", "updates", "==", "[", "1", ",", "2", "]" ]
[ 244, 0 ]
[ 292, 28 ]
python
en
['en', 'en', 'en']
True
test_async_parallel_updates_with_zero
(hass)
Test parallel updates with 0 (disabled).
Test parallel updates with 0 (disabled).
async def test_async_parallel_updates_with_zero(hass): """Test parallel updates with 0 (disabled).""" updates = [] test_lock = asyncio.Event() class AsyncEntity(entity.Entity): """Test entity.""" def __init__(self, entity_id, count): """Initialize Async test entity.""" self.entity_id = entity_id self.hass = hass self._count = count async def async_update(self): """Test update.""" updates.append(self._count) await test_lock.wait() ent_1 = AsyncEntity("sensor.test_1", 1) ent_2 = AsyncEntity("sensor.test_2", 2) try: ent_1.async_schedule_update_ha_state(True) ent_2.async_schedule_update_ha_state(True) while True: if len(updates) >= 2: break await asyncio.sleep(0) assert len(updates) == 2 assert updates == [1, 2] finally: test_lock.set()
[ "async", "def", "test_async_parallel_updates_with_zero", "(", "hass", ")", ":", "updates", "=", "[", "]", "test_lock", "=", "asyncio", ".", "Event", "(", ")", "class", "AsyncEntity", "(", "entity", ".", "Entity", ")", ":", "\"\"\"Test entity.\"\"\"", "def", "__init__", "(", "self", ",", "entity_id", ",", "count", ")", ":", "\"\"\"Initialize Async test entity.\"\"\"", "self", ".", "entity_id", "=", "entity_id", "self", ".", "hass", "=", "hass", "self", ".", "_count", "=", "count", "async", "def", "async_update", "(", "self", ")", ":", "\"\"\"Test update.\"\"\"", "updates", ".", "append", "(", "self", ".", "_count", ")", "await", "test_lock", ".", "wait", "(", ")", "ent_1", "=", "AsyncEntity", "(", "\"sensor.test_1\"", ",", "1", ")", "ent_2", "=", "AsyncEntity", "(", "\"sensor.test_2\"", ",", "2", ")", "try", ":", "ent_1", ".", "async_schedule_update_ha_state", "(", "True", ")", "ent_2", ".", "async_schedule_update_ha_state", "(", "True", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "2", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "assert", "len", "(", "updates", ")", "==", "2", "assert", "updates", "==", "[", "1", ",", "2", "]", "finally", ":", "test_lock", ".", "set", "(", ")" ]
[ 295, 0 ]
[ 329, 23 ]
python
en
['en', 'en', 'en']
True
test_async_parallel_updates_with_zero_on_sync_update
(hass)
Test parallel updates with 0 (disabled).
Test parallel updates with 0 (disabled).
async def test_async_parallel_updates_with_zero_on_sync_update(hass): """Test parallel updates with 0 (disabled).""" updates = [] test_lock = threading.Event() class AsyncEntity(entity.Entity): """Test entity.""" def __init__(self, entity_id, count): """Initialize Async test entity.""" self.entity_id = entity_id self.hass = hass self._count = count def update(self): """Test update.""" updates.append(self._count) if not test_lock.wait(timeout=1): # if timeout populate more data to fail the test updates.append(self._count) ent_1 = AsyncEntity("sensor.test_1", 1) ent_2 = AsyncEntity("sensor.test_2", 2) try: ent_1.async_schedule_update_ha_state(True) ent_2.async_schedule_update_ha_state(True) while True: if len(updates) >= 2: break await asyncio.sleep(0) assert len(updates) == 2 assert updates == [1, 2] finally: test_lock.set() await asyncio.sleep(0)
[ "async", "def", "test_async_parallel_updates_with_zero_on_sync_update", "(", "hass", ")", ":", "updates", "=", "[", "]", "test_lock", "=", "threading", ".", "Event", "(", ")", "class", "AsyncEntity", "(", "entity", ".", "Entity", ")", ":", "\"\"\"Test entity.\"\"\"", "def", "__init__", "(", "self", ",", "entity_id", ",", "count", ")", ":", "\"\"\"Initialize Async test entity.\"\"\"", "self", ".", "entity_id", "=", "entity_id", "self", ".", "hass", "=", "hass", "self", ".", "_count", "=", "count", "def", "update", "(", "self", ")", ":", "\"\"\"Test update.\"\"\"", "updates", ".", "append", "(", "self", ".", "_count", ")", "if", "not", "test_lock", ".", "wait", "(", "timeout", "=", "1", ")", ":", "# if timeout populate more data to fail the test", "updates", ".", "append", "(", "self", ".", "_count", ")", "ent_1", "=", "AsyncEntity", "(", "\"sensor.test_1\"", ",", "1", ")", "ent_2", "=", "AsyncEntity", "(", "\"sensor.test_2\"", ",", "2", ")", "try", ":", "ent_1", ".", "async_schedule_update_ha_state", "(", "True", ")", "ent_2", ".", "async_schedule_update_ha_state", "(", "True", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "2", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "assert", "len", "(", "updates", ")", "==", "2", "assert", "updates", "==", "[", "1", ",", "2", "]", "finally", ":", "test_lock", ".", "set", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")" ]
[ 332, 0 ]
[ 369, 30 ]
python
en
['en', 'en', 'en']
True
test_async_parallel_updates_with_one
(hass)
Test parallel updates with 1 (sequential).
Test parallel updates with 1 (sequential).
async def test_async_parallel_updates_with_one(hass): """Test parallel updates with 1 (sequential).""" updates = [] test_lock = asyncio.Lock() test_semaphore = asyncio.Semaphore(1) class AsyncEntity(entity.Entity): """Test entity.""" def __init__(self, entity_id, count): """Initialize Async test entity.""" self.entity_id = entity_id self.hass = hass self._count = count self.parallel_updates = test_semaphore async def async_update(self): """Test update.""" updates.append(self._count) await test_lock.acquire() ent_1 = AsyncEntity("sensor.test_1", 1) ent_2 = AsyncEntity("sensor.test_2", 2) ent_3 = AsyncEntity("sensor.test_3", 3) await test_lock.acquire() try: ent_1.async_schedule_update_ha_state(True) ent_2.async_schedule_update_ha_state(True) ent_3.async_schedule_update_ha_state(True) while True: if len(updates) >= 1: break await asyncio.sleep(0) assert len(updates) == 1 assert updates == [1] updates.clear() test_lock.release() await asyncio.sleep(0) while True: if len(updates) >= 1: break await asyncio.sleep(0) assert len(updates) == 1 assert updates == [2] updates.clear() test_lock.release() await asyncio.sleep(0) while True: if len(updates) >= 1: break await asyncio.sleep(0) assert len(updates) == 1 assert updates == [3] updates.clear() test_lock.release() await asyncio.sleep(0) finally: # we may have more than one lock need to release in case test failed for _ in updates: test_lock.release() await asyncio.sleep(0) test_lock.release()
[ "async", "def", "test_async_parallel_updates_with_one", "(", "hass", ")", ":", "updates", "=", "[", "]", "test_lock", "=", "asyncio", ".", "Lock", "(", ")", "test_semaphore", "=", "asyncio", ".", "Semaphore", "(", "1", ")", "class", "AsyncEntity", "(", "entity", ".", "Entity", ")", ":", "\"\"\"Test entity.\"\"\"", "def", "__init__", "(", "self", ",", "entity_id", ",", "count", ")", ":", "\"\"\"Initialize Async test entity.\"\"\"", "self", ".", "entity_id", "=", "entity_id", "self", ".", "hass", "=", "hass", "self", ".", "_count", "=", "count", "self", ".", "parallel_updates", "=", "test_semaphore", "async", "def", "async_update", "(", "self", ")", ":", "\"\"\"Test update.\"\"\"", "updates", ".", "append", "(", "self", ".", "_count", ")", "await", "test_lock", ".", "acquire", "(", ")", "ent_1", "=", "AsyncEntity", "(", "\"sensor.test_1\"", ",", "1", ")", "ent_2", "=", "AsyncEntity", "(", "\"sensor.test_2\"", ",", "2", ")", "ent_3", "=", "AsyncEntity", "(", "\"sensor.test_3\"", ",", "3", ")", "await", "test_lock", ".", "acquire", "(", ")", "try", ":", "ent_1", ".", "async_schedule_update_ha_state", "(", "True", ")", "ent_2", ".", "async_schedule_update_ha_state", "(", "True", ")", "ent_3", ".", "async_schedule_update_ha_state", "(", "True", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "1", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "assert", "len", "(", "updates", ")", "==", "1", "assert", "updates", "==", "[", "1", "]", "updates", ".", "clear", "(", ")", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "1", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "assert", "len", "(", "updates", ")", "==", "1", "assert", "updates", "==", "[", "2", "]", "updates", ".", "clear", "(", ")", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "1", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "assert", "len", "(", "updates", ")", "==", "1", "assert", "updates", "==", "[", "3", "]", "updates", ".", "clear", "(", ")", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "finally", ":", "# we may have more than one lock need to release in case test failed", "for", "_", "in", "updates", ":", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "test_lock", ".", "release", "(", ")" ]
[ 372, 0 ]
[ 445, 27 ]
python
en
['en', 'en', 'en']
True
test_async_parallel_updates_with_two
(hass)
Test parallel updates with 2 (parallel).
Test parallel updates with 2 (parallel).
async def test_async_parallel_updates_with_two(hass): """Test parallel updates with 2 (parallel).""" updates = [] test_lock = asyncio.Lock() test_semaphore = asyncio.Semaphore(2) class AsyncEntity(entity.Entity): """Test entity.""" def __init__(self, entity_id, count): """Initialize Async test entity.""" self.entity_id = entity_id self.hass = hass self._count = count self.parallel_updates = test_semaphore async def async_update(self): """Test update.""" updates.append(self._count) await test_lock.acquire() ent_1 = AsyncEntity("sensor.test_1", 1) ent_2 = AsyncEntity("sensor.test_2", 2) ent_3 = AsyncEntity("sensor.test_3", 3) ent_4 = AsyncEntity("sensor.test_4", 4) await test_lock.acquire() try: ent_1.async_schedule_update_ha_state(True) ent_2.async_schedule_update_ha_state(True) ent_3.async_schedule_update_ha_state(True) ent_4.async_schedule_update_ha_state(True) while True: if len(updates) >= 2: break await asyncio.sleep(0) assert len(updates) == 2 assert updates == [1, 2] updates.clear() test_lock.release() await asyncio.sleep(0) test_lock.release() await asyncio.sleep(0) while True: if len(updates) >= 2: break await asyncio.sleep(0) assert len(updates) == 2 assert updates == [3, 4] updates.clear() test_lock.release() await asyncio.sleep(0) test_lock.release() await asyncio.sleep(0) finally: # we may have more than one lock need to release in case test failed for _ in updates: test_lock.release() await asyncio.sleep(0) test_lock.release()
[ "async", "def", "test_async_parallel_updates_with_two", "(", "hass", ")", ":", "updates", "=", "[", "]", "test_lock", "=", "asyncio", ".", "Lock", "(", ")", "test_semaphore", "=", "asyncio", ".", "Semaphore", "(", "2", ")", "class", "AsyncEntity", "(", "entity", ".", "Entity", ")", ":", "\"\"\"Test entity.\"\"\"", "def", "__init__", "(", "self", ",", "entity_id", ",", "count", ")", ":", "\"\"\"Initialize Async test entity.\"\"\"", "self", ".", "entity_id", "=", "entity_id", "self", ".", "hass", "=", "hass", "self", ".", "_count", "=", "count", "self", ".", "parallel_updates", "=", "test_semaphore", "async", "def", "async_update", "(", "self", ")", ":", "\"\"\"Test update.\"\"\"", "updates", ".", "append", "(", "self", ".", "_count", ")", "await", "test_lock", ".", "acquire", "(", ")", "ent_1", "=", "AsyncEntity", "(", "\"sensor.test_1\"", ",", "1", ")", "ent_2", "=", "AsyncEntity", "(", "\"sensor.test_2\"", ",", "2", ")", "ent_3", "=", "AsyncEntity", "(", "\"sensor.test_3\"", ",", "3", ")", "ent_4", "=", "AsyncEntity", "(", "\"sensor.test_4\"", ",", "4", ")", "await", "test_lock", ".", "acquire", "(", ")", "try", ":", "ent_1", ".", "async_schedule_update_ha_state", "(", "True", ")", "ent_2", ".", "async_schedule_update_ha_state", "(", "True", ")", "ent_3", ".", "async_schedule_update_ha_state", "(", "True", ")", "ent_4", ".", "async_schedule_update_ha_state", "(", "True", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "2", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "assert", "len", "(", "updates", ")", "==", "2", "assert", "updates", "==", "[", "1", ",", "2", "]", "updates", ".", "clear", "(", ")", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "while", "True", ":", "if", "len", "(", "updates", ")", ">=", "2", ":", "break", "await", "asyncio", ".", "sleep", "(", "0", ")", "assert", "len", "(", "updates", ")", "==", "2", "assert", "updates", "==", "[", "3", ",", "4", "]", "updates", ".", "clear", "(", ")", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "finally", ":", "# we may have more than one lock need to release in case test failed", "for", "_", "in", "updates", ":", "test_lock", ".", "release", "(", ")", "await", "asyncio", ".", "sleep", "(", "0", ")", "test_lock", ".", "release", "(", ")" ]
[ 448, 0 ]
[ 515, 27 ]
python
en
['en', 'en', 'en']
True
test_async_remove_no_platform
(hass)
Test async_remove method when no platform set.
Test async_remove method when no platform set.
async def test_async_remove_no_platform(hass): """Test async_remove method when no platform set.""" ent = entity.Entity() ent.hass = hass ent.entity_id = "test.test" await ent.async_update_ha_state() assert len(hass.states.async_entity_ids()) == 1 await ent.async_remove() assert len(hass.states.async_entity_ids()) == 0
[ "async", "def", "test_async_remove_no_platform", "(", "hass", ")", ":", "ent", "=", "entity", ".", "Entity", "(", ")", "ent", ".", "hass", "=", "hass", "ent", ".", "entity_id", "=", "\"test.test\"", "await", "ent", ".", "async_update_ha_state", "(", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_entity_ids", "(", ")", ")", "==", "1", "await", "ent", ".", "async_remove", "(", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_entity_ids", "(", ")", ")", "==", "0" ]
[ 518, 0 ]
[ 526, 51 ]
python
en
['en', 'de', 'en']
True
test_async_remove_runs_callbacks
(hass)
Test async_remove method when no platform set.
Test async_remove method when no platform set.
async def test_async_remove_runs_callbacks(hass): """Test async_remove method when no platform set.""" result = [] ent = entity.Entity() ent.hass = hass ent.entity_id = "test.test" ent.async_on_remove(lambda: result.append(1)) await ent.async_remove() assert len(result) == 1
[ "async", "def", "test_async_remove_runs_callbacks", "(", "hass", ")", ":", "result", "=", "[", "]", "ent", "=", "entity", ".", "Entity", "(", ")", "ent", ".", "hass", "=", "hass", "ent", ".", "entity_id", "=", "\"test.test\"", "ent", ".", "async_on_remove", "(", "lambda", ":", "result", ".", "append", "(", "1", ")", ")", "await", "ent", ".", "async_remove", "(", ")", "assert", "len", "(", "result", ")", "==", "1" ]
[ 529, 0 ]
[ 538, 27 ]
python
en
['en', 'de', 'en']
True
test_set_context
(hass)
Test setting context.
Test setting context.
async def test_set_context(hass): """Test setting context.""" context = Context() ent = entity.Entity() ent.hass = hass ent.entity_id = "hello.world" ent.async_set_context(context) await ent.async_update_ha_state() assert hass.states.get("hello.world").context == context
[ "async", "def", "test_set_context", "(", "hass", ")", ":", "context", "=", "Context", "(", ")", "ent", "=", "entity", ".", "Entity", "(", ")", "ent", ".", "hass", "=", "hass", "ent", ".", "entity_id", "=", "\"hello.world\"", "ent", ".", "async_set_context", "(", "context", ")", "await", "ent", ".", "async_update_ha_state", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"hello.world\"", ")", ".", "context", "==", "context" ]
[ 541, 0 ]
[ 549, 60 ]
python
en
['en', 'en', 'en']
True
test_set_context_expired
(hass)
Test setting context.
Test setting context.
async def test_set_context_expired(hass): """Test setting context.""" context = Context() with patch.object( entity.Entity, "context_recent_time", new_callable=PropertyMock ) as recent: recent.return_value = timedelta(seconds=-5) ent = entity.Entity() ent.hass = hass ent.entity_id = "hello.world" ent.async_set_context(context) await ent.async_update_ha_state() assert hass.states.get("hello.world").context != context assert ent._context is None assert ent._context_set is None
[ "async", "def", "test_set_context_expired", "(", "hass", ")", ":", "context", "=", "Context", "(", ")", "with", "patch", ".", "object", "(", "entity", ".", "Entity", ",", "\"context_recent_time\"", ",", "new_callable", "=", "PropertyMock", ")", "as", "recent", ":", "recent", ".", "return_value", "=", "timedelta", "(", "seconds", "=", "-", "5", ")", "ent", "=", "entity", ".", "Entity", "(", ")", "ent", ".", "hass", "=", "hass", "ent", ".", "entity_id", "=", "\"hello.world\"", "ent", ".", "async_set_context", "(", "context", ")", "await", "ent", ".", "async_update_ha_state", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"hello.world\"", ")", ".", "context", "!=", "context", "assert", "ent", ".", "_context", "is", "None", "assert", "ent", ".", "_context_set", "is", "None" ]
[ 552, 0 ]
[ 568, 35 ]
python
en
['en', 'en', 'en']
True
test_warn_disabled
(hass, caplog)
Test we warn once if we write to a disabled entity.
Test we warn once if we write to a disabled entity.
async def test_warn_disabled(hass, caplog): """Test we warn once if we write to a disabled entity.""" entry = entity_registry.RegistryEntry( entity_id="hello.world", unique_id="test-unique-id", platform="test-platform", disabled_by="user", ) mock_registry(hass, {"hello.world": entry}) ent = entity.Entity() ent.hass = hass ent.entity_id = "hello.world" ent.registry_entry = entry ent.platform = MagicMock(platform_name="test-platform") caplog.clear() ent.async_write_ha_state() assert hass.states.get("hello.world") is None assert "Entity hello.world is incorrectly being triggered" in caplog.text caplog.clear() ent.async_write_ha_state() assert hass.states.get("hello.world") is None assert caplog.text == ""
[ "async", "def", "test_warn_disabled", "(", "hass", ",", "caplog", ")", ":", "entry", "=", "entity_registry", ".", "RegistryEntry", "(", "entity_id", "=", "\"hello.world\"", ",", "unique_id", "=", "\"test-unique-id\"", ",", "platform", "=", "\"test-platform\"", ",", "disabled_by", "=", "\"user\"", ",", ")", "mock_registry", "(", "hass", ",", "{", "\"hello.world\"", ":", "entry", "}", ")", "ent", "=", "entity", ".", "Entity", "(", ")", "ent", ".", "hass", "=", "hass", "ent", ".", "entity_id", "=", "\"hello.world\"", "ent", ".", "registry_entry", "=", "entry", "ent", ".", "platform", "=", "MagicMock", "(", "platform_name", "=", "\"test-platform\"", ")", "caplog", ".", "clear", "(", ")", "ent", ".", "async_write_ha_state", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"hello.world\"", ")", "is", "None", "assert", "\"Entity hello.world is incorrectly being triggered\"", "in", "caplog", ".", "text", "caplog", ".", "clear", "(", ")", "ent", ".", "async_write_ha_state", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"hello.world\"", ")", "is", "None", "assert", "caplog", ".", "text", "==", "\"\"" ]
[ 571, 0 ]
[ 595, 28 ]
python
en
['en', 'en', 'en']
True
test_disabled_in_entity_registry
(hass)
Test entity is removed if we disable entity registry entry.
Test entity is removed if we disable entity registry entry.
async def test_disabled_in_entity_registry(hass): """Test entity is removed if we disable entity registry entry.""" entry = entity_registry.RegistryEntry( entity_id="hello.world", unique_id="test-unique-id", platform="test-platform", disabled_by=None, ) registry = mock_registry(hass, {"hello.world": entry}) ent = entity.Entity() ent.hass = hass ent.entity_id = "hello.world" ent.registry_entry = entry assert ent.enabled is True ent.add_to_platform_start(hass, MagicMock(platform_name="test-platform"), None) await ent.add_to_platform_finish() assert hass.states.get("hello.world") is not None entry2 = registry.async_update_entity("hello.world", disabled_by="user") await hass.async_block_till_done() assert entry2 != entry assert ent.registry_entry == entry2 assert ent.enabled is False assert hass.states.get("hello.world") is None entry3 = registry.async_update_entity("hello.world", disabled_by=None) await hass.async_block_till_done() assert entry3 != entry2 # Entry is no longer updated, entity is no longer tracking changes assert ent.registry_entry == entry2
[ "async", "def", "test_disabled_in_entity_registry", "(", "hass", ")", ":", "entry", "=", "entity_registry", ".", "RegistryEntry", "(", "entity_id", "=", "\"hello.world\"", ",", "unique_id", "=", "\"test-unique-id\"", ",", "platform", "=", "\"test-platform\"", ",", "disabled_by", "=", "None", ",", ")", "registry", "=", "mock_registry", "(", "hass", ",", "{", "\"hello.world\"", ":", "entry", "}", ")", "ent", "=", "entity", ".", "Entity", "(", ")", "ent", ".", "hass", "=", "hass", "ent", ".", "entity_id", "=", "\"hello.world\"", "ent", ".", "registry_entry", "=", "entry", "assert", "ent", ".", "enabled", "is", "True", "ent", ".", "add_to_platform_start", "(", "hass", ",", "MagicMock", "(", "platform_name", "=", "\"test-platform\"", ")", ",", "None", ")", "await", "ent", ".", "add_to_platform_finish", "(", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"hello.world\"", ")", "is", "not", "None", "entry2", "=", "registry", ".", "async_update_entity", "(", "\"hello.world\"", ",", "disabled_by", "=", "\"user\"", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "entry2", "!=", "entry", "assert", "ent", ".", "registry_entry", "==", "entry2", "assert", "ent", ".", "enabled", "is", "False", "assert", "hass", ".", "states", ".", "get", "(", "\"hello.world\"", ")", "is", "None", "entry3", "=", "registry", ".", "async_update_entity", "(", "\"hello.world\"", ",", "disabled_by", "=", "None", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "entry3", "!=", "entry2", "# Entry is no longer updated, entity is no longer tracking changes", "assert", "ent", ".", "registry_entry", "==", "entry2" ]
[ 598, 0 ]
[ 629, 39 ]
python
en
['en', 'en', 'en']
True
test_capability_attrs
(hass)
Test we still include capabilities even when unavailable.
Test we still include capabilities even when unavailable.
async def test_capability_attrs(hass): """Test we still include capabilities even when unavailable.""" with patch.object( entity.Entity, "available", PropertyMock(return_value=False) ), patch.object( entity.Entity, "capability_attributes", PropertyMock(return_value={"always": "there"}), ): ent = entity.Entity() ent.hass = hass ent.entity_id = "hello.world" ent.async_write_ha_state() state = hass.states.get("hello.world") assert state is not None assert state.state == STATE_UNAVAILABLE assert state.attributes["always"] == "there"
[ "async", "def", "test_capability_attrs", "(", "hass", ")", ":", "with", "patch", ".", "object", "(", "entity", ".", "Entity", ",", "\"available\"", ",", "PropertyMock", "(", "return_value", "=", "False", ")", ")", ",", "patch", ".", "object", "(", "entity", ".", "Entity", ",", "\"capability_attributes\"", ",", "PropertyMock", "(", "return_value", "=", "{", "\"always\"", ":", "\"there\"", "}", ")", ",", ")", ":", "ent", "=", "entity", ".", "Entity", "(", ")", "ent", ".", "hass", "=", "hass", "ent", ".", "entity_id", "=", "\"hello.world\"", "ent", ".", "async_write_ha_state", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"hello.world\"", ")", "assert", "state", "is", "not", "None", "assert", "state", ".", "state", "==", "STATE_UNAVAILABLE", "assert", "state", ".", "attributes", "[", "\"always\"", "]", "==", "\"there\"" ]
[ 632, 0 ]
[ 649, 48 ]
python
en
['en', 'en', 'en']
True
test_warn_slow_write_state
(hass, caplog)
Check that we log a warning if reading properties takes too long.
Check that we log a warning if reading properties takes too long.
async def test_warn_slow_write_state(hass, caplog): """Check that we log a warning if reading properties takes too long.""" mock_entity = entity.Entity() mock_entity.hass = hass mock_entity.entity_id = "comp_test.test_entity" mock_entity.platform = MagicMock(platform_name="hue") with patch("homeassistant.helpers.entity.timer", side_effect=[0, 10]): mock_entity.async_write_ha_state() assert ( "Updating state for comp_test.test_entity " "(<class 'homeassistant.helpers.entity.Entity'>) " "took 10.000 seconds. Please create a bug report at " "https://github.com/home-assistant/core/issues?" "q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+hue%22" ) in caplog.text
[ "async", "def", "test_warn_slow_write_state", "(", "hass", ",", "caplog", ")", ":", "mock_entity", "=", "entity", ".", "Entity", "(", ")", "mock_entity", ".", "hass", "=", "hass", "mock_entity", ".", "entity_id", "=", "\"comp_test.test_entity\"", "mock_entity", ".", "platform", "=", "MagicMock", "(", "platform_name", "=", "\"hue\"", ")", "with", "patch", "(", "\"homeassistant.helpers.entity.timer\"", ",", "side_effect", "=", "[", "0", ",", "10", "]", ")", ":", "mock_entity", ".", "async_write_ha_state", "(", ")", "assert", "(", "\"Updating state for comp_test.test_entity \"", "\"(<class 'homeassistant.helpers.entity.Entity'>) \"", "\"took 10.000 seconds. Please create a bug report at \"", "\"https://github.com/home-assistant/core/issues?\"", "\"q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+hue%22\"", ")", "in", "caplog", ".", "text" ]
[ 652, 0 ]
[ 668, 20 ]
python
en
['en', 'en', 'en']
True
test_warn_slow_write_state_custom_component
(hass, caplog)
Check that we log a warning if reading properties takes too long.
Check that we log a warning if reading properties takes too long.
async def test_warn_slow_write_state_custom_component(hass, caplog): """Check that we log a warning if reading properties takes too long.""" class CustomComponentEntity(entity.Entity): """Custom component entity.""" __module__ = "custom_components.bla.sensor" mock_entity = CustomComponentEntity() mock_entity.hass = hass mock_entity.entity_id = "comp_test.test_entity" mock_entity.platform = MagicMock(platform_name="hue") with patch("homeassistant.helpers.entity.timer", side_effect=[0, 10]): mock_entity.async_write_ha_state() assert ( "Updating state for comp_test.test_entity " "(<class 'custom_components.bla.sensor.test_warn_slow_write_state_custom_component.<locals>.CustomComponentEntity'>) " "took 10.000 seconds. Please report it to the custom component author." ) in caplog.text
[ "async", "def", "test_warn_slow_write_state_custom_component", "(", "hass", ",", "caplog", ")", ":", "class", "CustomComponentEntity", "(", "entity", ".", "Entity", ")", ":", "\"\"\"Custom component entity.\"\"\"", "__module__", "=", "\"custom_components.bla.sensor\"", "mock_entity", "=", "CustomComponentEntity", "(", ")", "mock_entity", ".", "hass", "=", "hass", "mock_entity", ".", "entity_id", "=", "\"comp_test.test_entity\"", "mock_entity", ".", "platform", "=", "MagicMock", "(", "platform_name", "=", "\"hue\"", ")", "with", "patch", "(", "\"homeassistant.helpers.entity.timer\"", ",", "side_effect", "=", "[", "0", ",", "10", "]", ")", ":", "mock_entity", ".", "async_write_ha_state", "(", ")", "assert", "(", "\"Updating state for comp_test.test_entity \"", "\"(<class 'custom_components.bla.sensor.test_warn_slow_write_state_custom_component.<locals>.CustomComponentEntity'>) \"", "\"took 10.000 seconds. Please report it to the custom component author.\"", ")", "in", "caplog", ".", "text" ]
[ 671, 0 ]
[ 691, 20 ]
python
en
['en', 'en', 'en']
True
test_setup_source
(hass)
Check that we register sources correctly.
Check that we register sources correctly.
async def test_setup_source(hass): """Check that we register sources correctly.""" platform = MockEntityPlatform(hass) entity_platform = MockEntity(name="Platform Config Source") await platform.async_add_entities([entity_platform]) platform.config_entry = MockConfigEntry() entity_entry = MockEntity(name="Config Entry Source") await platform.async_add_entities([entity_entry]) assert entity.entity_sources(hass) == { "test_domain.platform_config_source": { "source": entity.SOURCE_PLATFORM_CONFIG, "domain": "test_platform", }, "test_domain.config_entry_source": { "source": entity.SOURCE_CONFIG_ENTRY, "config_entry": platform.config_entry.entry_id, "domain": "test_platform", }, } await platform.async_reset() assert entity.entity_sources(hass) == {}
[ "async", "def", "test_setup_source", "(", "hass", ")", ":", "platform", "=", "MockEntityPlatform", "(", "hass", ")", "entity_platform", "=", "MockEntity", "(", "name", "=", "\"Platform Config Source\"", ")", "await", "platform", ".", "async_add_entities", "(", "[", "entity_platform", "]", ")", "platform", ".", "config_entry", "=", "MockConfigEntry", "(", ")", "entity_entry", "=", "MockEntity", "(", "name", "=", "\"Config Entry Source\"", ")", "await", "platform", ".", "async_add_entities", "(", "[", "entity_entry", "]", ")", "assert", "entity", ".", "entity_sources", "(", "hass", ")", "==", "{", "\"test_domain.platform_config_source\"", ":", "{", "\"source\"", ":", "entity", ".", "SOURCE_PLATFORM_CONFIG", ",", "\"domain\"", ":", "\"test_platform\"", ",", "}", ",", "\"test_domain.config_entry_source\"", ":", "{", "\"source\"", ":", "entity", ".", "SOURCE_CONFIG_ENTRY", ",", "\"config_entry\"", ":", "platform", ".", "config_entry", ".", "entry_id", ",", "\"domain\"", ":", "\"test_platform\"", ",", "}", ",", "}", "await", "platform", ".", "async_reset", "(", ")", "assert", "entity", ".", "entity_sources", "(", "hass", ")", "==", "{", "}" ]
[ 694, 0 ]
[ 719, 44 ]
python
en
['en', 'en', 'en']
True
TestHelpersEntity.setup_method
(self, method)
Set up things to be run when tests are started.
Set up things to be run when tests are started.
def setup_method(self, method): """Set up things to be run when tests are started.""" self.entity = entity.Entity() self.entity.entity_id = "test.overwrite_hidden_true" self.hass = self.entity.hass = get_test_home_assistant() self.entity.schedule_update_ha_state() self.hass.block_till_done()
[ "def", "setup_method", "(", "self", ",", "method", ")", ":", "self", ".", "entity", "=", "entity", ".", "Entity", "(", ")", "self", ".", "entity", ".", "entity_id", "=", "\"test.overwrite_hidden_true\"", "self", ".", "hass", "=", "self", ".", "entity", ".", "hass", "=", "get_test_home_assistant", "(", ")", "self", ".", "entity", ".", "schedule_update_ha_state", "(", ")", "self", ".", "hass", ".", "block_till_done", "(", ")" ]
[ 83, 4 ]
[ 89, 35 ]
python
en
['en', 'en', 'en']
True
TestHelpersEntity.teardown_method
(self, method)
Stop everything that was started.
Stop everything that was started.
def teardown_method(self, method): """Stop everything that was started.""" self.hass.stop()
[ "def", "teardown_method", "(", "self", ",", "method", ")", ":", "self", ".", "hass", ".", "stop", "(", ")" ]
[ 91, 4 ]
[ 93, 24 ]
python
en
['en', 'en', 'en']
True
TestHelpersEntity.test_generate_entity_id_given_hass
(self)
Test generating an entity id given hass object.
Test generating an entity id given hass object.
def test_generate_entity_id_given_hass(self): """Test generating an entity id given hass object.""" fmt = "test.{}" assert ( entity.generate_entity_id(fmt, "overwrite hidden true", hass=self.hass) == "test.overwrite_hidden_true_2" )
[ "def", "test_generate_entity_id_given_hass", "(", "self", ")", ":", "fmt", "=", "\"test.{}\"", "assert", "(", "entity", ".", "generate_entity_id", "(", "fmt", ",", "\"overwrite hidden true\"", ",", "hass", "=", "self", ".", "hass", ")", "==", "\"test.overwrite_hidden_true_2\"", ")" ]
[ 95, 4 ]
[ 101, 9 ]
python
en
['en', 'en', 'en']
True
TestHelpersEntity.test_device_class
(self)
Test device class attribute.
Test device class attribute.
def test_device_class(self): """Test device class attribute.""" state = self.hass.states.get(self.entity.entity_id) assert state.attributes.get(ATTR_DEVICE_CLASS) is None with patch( "homeassistant.helpers.entity.Entity.device_class", new="test_class" ): self.entity.schedule_update_ha_state() self.hass.block_till_done() state = self.hass.states.get(self.entity.entity_id) assert state.attributes.get(ATTR_DEVICE_CLASS) == "test_class"
[ "def", "test_device_class", "(", "self", ")", ":", "state", "=", "self", ".", "hass", ".", "states", ".", "get", "(", "self", ".", "entity", ".", "entity_id", ")", "assert", "state", ".", "attributes", ".", "get", "(", "ATTR_DEVICE_CLASS", ")", "is", "None", "with", "patch", "(", "\"homeassistant.helpers.entity.Entity.device_class\"", ",", "new", "=", "\"test_class\"", ")", ":", "self", ".", "entity", ".", "schedule_update_ha_state", "(", ")", "self", ".", "hass", ".", "block_till_done", "(", ")", "state", "=", "self", ".", "hass", ".", "states", ".", "get", "(", "self", ".", "entity", ".", "entity_id", ")", "assert", "state", ".", "attributes", ".", "get", "(", "ATTR_DEVICE_CLASS", ")", "==", "\"test_class\"" ]
[ 103, 4 ]
[ 113, 70 ]
python
en
['fr', 'en', 'en']
True
test_caching_data
(hass)
Test that we cache data.
Test that we cache data.
async def test_caching_data(hass): """Test that we cache data.""" now = dt_util.utcnow() stored_states = [ StoredState(State("input_boolean.b0", "on"), now), StoredState(State("input_boolean.b1", "on"), now), StoredState(State("input_boolean.b2", "on"), now), ] data = await RestoreStateData.async_get_instance(hass) await hass.async_block_till_done() await data.store.async_save([state.as_dict() for state in stored_states]) # Emulate a fresh load hass.data[DATA_RESTORE_STATE_TASK] = None entity = RestoreEntity() entity.hass = hass entity.entity_id = "input_boolean.b1" # Mock that only b1 is present this run with patch( "homeassistant.helpers.restore_state.Store.async_save" ) as mock_write_data: state = await entity.async_get_last_state() await hass.async_block_till_done() assert state is not None assert state.entity_id == "input_boolean.b1" assert state.state == "on" assert mock_write_data.called
[ "async", "def", "test_caching_data", "(", "hass", ")", ":", "now", "=", "dt_util", ".", "utcnow", "(", ")", "stored_states", "=", "[", "StoredState", "(", "State", "(", "\"input_boolean.b0\"", ",", "\"on\"", ")", ",", "now", ")", ",", "StoredState", "(", "State", "(", "\"input_boolean.b1\"", ",", "\"on\"", ")", ",", "now", ")", ",", "StoredState", "(", "State", "(", "\"input_boolean.b2\"", ",", "\"on\"", ")", ",", "now", ")", ",", "]", "data", "=", "await", "RestoreStateData", ".", "async_get_instance", "(", "hass", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "data", ".", "store", ".", "async_save", "(", "[", "state", ".", "as_dict", "(", ")", "for", "state", "in", "stored_states", "]", ")", "# Emulate a fresh load", "hass", ".", "data", "[", "DATA_RESTORE_STATE_TASK", "]", "=", "None", "entity", "=", "RestoreEntity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"input_boolean.b1\"", "# Mock that only b1 is present this run", "with", "patch", "(", "\"homeassistant.helpers.restore_state.Store.async_save\"", ")", "as", "mock_write_data", ":", "state", "=", "await", "entity", ".", "async_get_last_state", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "state", "is", "not", "None", "assert", "state", ".", "entity_id", "==", "\"input_boolean.b1\"", "assert", "state", ".", "state", "==", "\"on\"", "assert", "mock_write_data", ".", "called" ]
[ 19, 0 ]
[ 50, 33 ]
python
en
['en', 'de', 'en']
True
test_hass_starting
(hass)
Test that we cache data.
Test that we cache data.
async def test_hass_starting(hass): """Test that we cache data.""" hass.state = CoreState.starting now = dt_util.utcnow() stored_states = [ StoredState(State("input_boolean.b0", "on"), now), StoredState(State("input_boolean.b1", "on"), now), StoredState(State("input_boolean.b2", "on"), now), ] data = await RestoreStateData.async_get_instance(hass) await hass.async_block_till_done() await data.store.async_save([state.as_dict() for state in stored_states]) # Emulate a fresh load hass.data[DATA_RESTORE_STATE_TASK] = None entity = RestoreEntity() entity.hass = hass entity.entity_id = "input_boolean.b1" # Mock that only b1 is present this run states = [State("input_boolean.b1", "on")] with patch( "homeassistant.helpers.restore_state.Store.async_save" ) as mock_write_data, patch.object(hass.states, "async_all", return_value=states): state = await entity.async_get_last_state() await hass.async_block_till_done() assert state is not None assert state.entity_id == "input_boolean.b1" assert state.state == "on" # Assert that no data was written yet, since hass is still starting. assert not mock_write_data.called # Finish hass startup with patch( "homeassistant.helpers.restore_state.Store.async_save" ) as mock_write_data: hass.bus.async_fire(EVENT_HOMEASSISTANT_START) await hass.async_block_till_done() # Assert that this session states were written assert mock_write_data.called
[ "async", "def", "test_hass_starting", "(", "hass", ")", ":", "hass", ".", "state", "=", "CoreState", ".", "starting", "now", "=", "dt_util", ".", "utcnow", "(", ")", "stored_states", "=", "[", "StoredState", "(", "State", "(", "\"input_boolean.b0\"", ",", "\"on\"", ")", ",", "now", ")", ",", "StoredState", "(", "State", "(", "\"input_boolean.b1\"", ",", "\"on\"", ")", ",", "now", ")", ",", "StoredState", "(", "State", "(", "\"input_boolean.b2\"", ",", "\"on\"", ")", ",", "now", ")", ",", "]", "data", "=", "await", "RestoreStateData", ".", "async_get_instance", "(", "hass", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "data", ".", "store", ".", "async_save", "(", "[", "state", ".", "as_dict", "(", ")", "for", "state", "in", "stored_states", "]", ")", "# Emulate a fresh load", "hass", ".", "data", "[", "DATA_RESTORE_STATE_TASK", "]", "=", "None", "entity", "=", "RestoreEntity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"input_boolean.b1\"", "# Mock that only b1 is present this run", "states", "=", "[", "State", "(", "\"input_boolean.b1\"", ",", "\"on\"", ")", "]", "with", "patch", "(", "\"homeassistant.helpers.restore_state.Store.async_save\"", ")", "as", "mock_write_data", ",", "patch", ".", "object", "(", "hass", ".", "states", ",", "\"async_all\"", ",", "return_value", "=", "states", ")", ":", "state", "=", "await", "entity", ".", "async_get_last_state", "(", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "state", "is", "not", "None", "assert", "state", ".", "entity_id", "==", "\"input_boolean.b1\"", "assert", "state", ".", "state", "==", "\"on\"", "# Assert that no data was written yet, since hass is still starting.", "assert", "not", "mock_write_data", ".", "called", "# Finish hass startup", "with", "patch", "(", "\"homeassistant.helpers.restore_state.Store.async_save\"", ")", "as", "mock_write_data", ":", "hass", ".", "bus", ".", "async_fire", "(", "EVENT_HOMEASSISTANT_START", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "# Assert that this session states were written", "assert", "mock_write_data", ".", "called" ]
[ 53, 0 ]
[ 98, 33 ]
python
en
['en', 'de', 'en']
True
test_dump_data
(hass)
Test that we cache data.
Test that we cache data.
async def test_dump_data(hass): """Test that we cache data.""" states = [ State("input_boolean.b0", "on"), State("input_boolean.b1", "on"), State("input_boolean.b2", "on"), State("input_boolean.b5", "unavailable", {"restored": True}), ] entity = Entity() entity.hass = hass entity.entity_id = "input_boolean.b0" await entity.async_internal_added_to_hass() entity = RestoreEntity() entity.hass = hass entity.entity_id = "input_boolean.b1" await entity.async_internal_added_to_hass() data = await RestoreStateData.async_get_instance(hass) now = dt_util.utcnow() data.last_states = { "input_boolean.b0": StoredState(State("input_boolean.b0", "off"), now), "input_boolean.b1": StoredState(State("input_boolean.b1", "off"), now), "input_boolean.b2": StoredState(State("input_boolean.b2", "off"), now), "input_boolean.b3": StoredState(State("input_boolean.b3", "off"), now), "input_boolean.b4": StoredState( State("input_boolean.b4", "off"), datetime(1985, 10, 26, 1, 22, tzinfo=dt_util.UTC), ), "input_boolean.b5": StoredState(State("input_boolean.b5", "off"), now), } with patch( "homeassistant.helpers.restore_state.Store.async_save" ) as mock_write_data, patch.object(hass.states, "async_all", return_value=states): await data.async_dump_states() assert mock_write_data.called args = mock_write_data.mock_calls[0][1] written_states = args[0] # b0 should not be written, since it didn't extend RestoreEntity # b1 should be written, since it is present in the current run # b2 should not be written, since it is not registered with the helper # b3 should be written, since it is still not expired # b4 should not be written, since it is now expired # b5 should be written, since current state is restored by entity registry assert len(written_states) == 3 assert written_states[0]["state"]["entity_id"] == "input_boolean.b1" assert written_states[0]["state"]["state"] == "on" assert written_states[1]["state"]["entity_id"] == "input_boolean.b3" assert written_states[1]["state"]["state"] == "off" assert written_states[2]["state"]["entity_id"] == "input_boolean.b5" assert written_states[2]["state"]["state"] == "off" # Test that removed entities are not persisted await entity.async_remove() with patch( "homeassistant.helpers.restore_state.Store.async_save" ) as mock_write_data, patch.object(hass.states, "async_all", return_value=states): await data.async_dump_states() assert mock_write_data.called args = mock_write_data.mock_calls[0][1] written_states = args[0] assert len(written_states) == 2 assert written_states[0]["state"]["entity_id"] == "input_boolean.b3" assert written_states[0]["state"]["state"] == "off" assert written_states[1]["state"]["entity_id"] == "input_boolean.b5" assert written_states[1]["state"]["state"] == "off"
[ "async", "def", "test_dump_data", "(", "hass", ")", ":", "states", "=", "[", "State", "(", "\"input_boolean.b0\"", ",", "\"on\"", ")", ",", "State", "(", "\"input_boolean.b1\"", ",", "\"on\"", ")", ",", "State", "(", "\"input_boolean.b2\"", ",", "\"on\"", ")", ",", "State", "(", "\"input_boolean.b5\"", ",", "\"unavailable\"", ",", "{", "\"restored\"", ":", "True", "}", ")", ",", "]", "entity", "=", "Entity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"input_boolean.b0\"", "await", "entity", ".", "async_internal_added_to_hass", "(", ")", "entity", "=", "RestoreEntity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"input_boolean.b1\"", "await", "entity", ".", "async_internal_added_to_hass", "(", ")", "data", "=", "await", "RestoreStateData", ".", "async_get_instance", "(", "hass", ")", "now", "=", "dt_util", ".", "utcnow", "(", ")", "data", ".", "last_states", "=", "{", "\"input_boolean.b0\"", ":", "StoredState", "(", "State", "(", "\"input_boolean.b0\"", ",", "\"off\"", ")", ",", "now", ")", ",", "\"input_boolean.b1\"", ":", "StoredState", "(", "State", "(", "\"input_boolean.b1\"", ",", "\"off\"", ")", ",", "now", ")", ",", "\"input_boolean.b2\"", ":", "StoredState", "(", "State", "(", "\"input_boolean.b2\"", ",", "\"off\"", ")", ",", "now", ")", ",", "\"input_boolean.b3\"", ":", "StoredState", "(", "State", "(", "\"input_boolean.b3\"", ",", "\"off\"", ")", ",", "now", ")", ",", "\"input_boolean.b4\"", ":", "StoredState", "(", "State", "(", "\"input_boolean.b4\"", ",", "\"off\"", ")", ",", "datetime", "(", "1985", ",", "10", ",", "26", ",", "1", ",", "22", ",", "tzinfo", "=", "dt_util", ".", "UTC", ")", ",", ")", ",", "\"input_boolean.b5\"", ":", "StoredState", "(", "State", "(", "\"input_boolean.b5\"", ",", "\"off\"", ")", ",", "now", ")", ",", "}", "with", "patch", "(", "\"homeassistant.helpers.restore_state.Store.async_save\"", ")", "as", "mock_write_data", ",", "patch", ".", "object", "(", "hass", ".", "states", ",", "\"async_all\"", ",", "return_value", "=", "states", ")", ":", "await", "data", ".", "async_dump_states", "(", ")", "assert", "mock_write_data", ".", "called", "args", "=", "mock_write_data", ".", "mock_calls", "[", "0", "]", "[", "1", "]", "written_states", "=", "args", "[", "0", "]", "# b0 should not be written, since it didn't extend RestoreEntity", "# b1 should be written, since it is present in the current run", "# b2 should not be written, since it is not registered with the helper", "# b3 should be written, since it is still not expired", "# b4 should not be written, since it is now expired", "# b5 should be written, since current state is restored by entity registry", "assert", "len", "(", "written_states", ")", "==", "3", "assert", "written_states", "[", "0", "]", "[", "\"state\"", "]", "[", "\"entity_id\"", "]", "==", "\"input_boolean.b1\"", "assert", "written_states", "[", "0", "]", "[", "\"state\"", "]", "[", "\"state\"", "]", "==", "\"on\"", "assert", "written_states", "[", "1", "]", "[", "\"state\"", "]", "[", "\"entity_id\"", "]", "==", "\"input_boolean.b3\"", "assert", "written_states", "[", "1", "]", "[", "\"state\"", "]", "[", "\"state\"", "]", "==", "\"off\"", "assert", "written_states", "[", "2", "]", "[", "\"state\"", "]", "[", "\"entity_id\"", "]", "==", "\"input_boolean.b5\"", "assert", "written_states", "[", "2", "]", "[", "\"state\"", "]", "[", "\"state\"", "]", "==", "\"off\"", "# Test that removed entities are not persisted", "await", "entity", ".", "async_remove", "(", ")", "with", "patch", "(", "\"homeassistant.helpers.restore_state.Store.async_save\"", ")", "as", "mock_write_data", ",", "patch", ".", "object", "(", "hass", ".", "states", ",", "\"async_all\"", ",", "return_value", "=", "states", ")", ":", "await", "data", ".", "async_dump_states", "(", ")", "assert", "mock_write_data", ".", "called", "args", "=", "mock_write_data", ".", "mock_calls", "[", "0", "]", "[", "1", "]", "written_states", "=", "args", "[", "0", "]", "assert", "len", "(", "written_states", ")", "==", "2", "assert", "written_states", "[", "0", "]", "[", "\"state\"", "]", "[", "\"entity_id\"", "]", "==", "\"input_boolean.b3\"", "assert", "written_states", "[", "0", "]", "[", "\"state\"", "]", "[", "\"state\"", "]", "==", "\"off\"", "assert", "written_states", "[", "1", "]", "[", "\"state\"", "]", "[", "\"entity_id\"", "]", "==", "\"input_boolean.b5\"", "assert", "written_states", "[", "1", "]", "[", "\"state\"", "]", "[", "\"state\"", "]", "==", "\"off\"" ]
[ 101, 0 ]
[ 172, 55 ]
python
en
['en', 'de', 'en']
True
test_dump_error
(hass)
Test that we cache data.
Test that we cache data.
async def test_dump_error(hass): """Test that we cache data.""" states = [ State("input_boolean.b0", "on"), State("input_boolean.b1", "on"), State("input_boolean.b2", "on"), ] entity = Entity() entity.hass = hass entity.entity_id = "input_boolean.b0" await entity.async_internal_added_to_hass() entity = RestoreEntity() entity.hass = hass entity.entity_id = "input_boolean.b1" await entity.async_internal_added_to_hass() data = await RestoreStateData.async_get_instance(hass) with patch( "homeassistant.helpers.restore_state.Store.async_save", side_effect=HomeAssistantError, ) as mock_write_data, patch.object(hass.states, "async_all", return_value=states): await data.async_dump_states() assert mock_write_data.called
[ "async", "def", "test_dump_error", "(", "hass", ")", ":", "states", "=", "[", "State", "(", "\"input_boolean.b0\"", ",", "\"on\"", ")", ",", "State", "(", "\"input_boolean.b1\"", ",", "\"on\"", ")", ",", "State", "(", "\"input_boolean.b2\"", ",", "\"on\"", ")", ",", "]", "entity", "=", "Entity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"input_boolean.b0\"", "await", "entity", ".", "async_internal_added_to_hass", "(", ")", "entity", "=", "RestoreEntity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"input_boolean.b1\"", "await", "entity", ".", "async_internal_added_to_hass", "(", ")", "data", "=", "await", "RestoreStateData", ".", "async_get_instance", "(", "hass", ")", "with", "patch", "(", "\"homeassistant.helpers.restore_state.Store.async_save\"", ",", "side_effect", "=", "HomeAssistantError", ",", ")", "as", "mock_write_data", ",", "patch", ".", "object", "(", "hass", ".", "states", ",", "\"async_all\"", ",", "return_value", "=", "states", ")", ":", "await", "data", ".", "async_dump_states", "(", ")", "assert", "mock_write_data", ".", "called" ]
[ 175, 0 ]
[ 201, 33 ]
python
en
['en', 'de', 'en']
True
test_load_error
(hass)
Test that we cache data.
Test that we cache data.
async def test_load_error(hass): """Test that we cache data.""" entity = RestoreEntity() entity.hass = hass entity.entity_id = "input_boolean.b1" with patch( "homeassistant.helpers.storage.Store.async_load", side_effect=HomeAssistantError, ): state = await entity.async_get_last_state() assert state is None
[ "async", "def", "test_load_error", "(", "hass", ")", ":", "entity", "=", "RestoreEntity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"input_boolean.b1\"", "with", "patch", "(", "\"homeassistant.helpers.storage.Store.async_load\"", ",", "side_effect", "=", "HomeAssistantError", ",", ")", ":", "state", "=", "await", "entity", ".", "async_get_last_state", "(", ")", "assert", "state", "is", "None" ]
[ 204, 0 ]
[ 216, 24 ]
python
en
['en', 'de', 'en']
True
test_state_saved_on_remove
(hass)
Test that we save entity state on removal.
Test that we save entity state on removal.
async def test_state_saved_on_remove(hass): """Test that we save entity state on removal.""" entity = RestoreEntity() entity.hass = hass entity.entity_id = "input_boolean.b0" await entity.async_internal_added_to_hass() now = dt_util.utcnow() hass.states.async_set( "input_boolean.b0", "on", {"complicated": {"value": {1, 2, now}}} ) data = await RestoreStateData.async_get_instance(hass) # No last states should currently be saved assert not data.last_states await entity.async_remove() # We should store the input boolean state when it is removed state = data.last_states["input_boolean.b0"].state assert state.state == "on" assert isinstance(state.attributes["complicated"]["value"], list) assert set(state.attributes["complicated"]["value"]) == {1, 2, now.isoformat()}
[ "async", "def", "test_state_saved_on_remove", "(", "hass", ")", ":", "entity", "=", "RestoreEntity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"input_boolean.b0\"", "await", "entity", ".", "async_internal_added_to_hass", "(", ")", "now", "=", "dt_util", ".", "utcnow", "(", ")", "hass", ".", "states", ".", "async_set", "(", "\"input_boolean.b0\"", ",", "\"on\"", ",", "{", "\"complicated\"", ":", "{", "\"value\"", ":", "{", "1", ",", "2", ",", "now", "}", "}", "}", ")", "data", "=", "await", "RestoreStateData", ".", "async_get_instance", "(", "hass", ")", "# No last states should currently be saved", "assert", "not", "data", ".", "last_states", "await", "entity", ".", "async_remove", "(", ")", "# We should store the input boolean state when it is removed", "state", "=", "data", ".", "last_states", "[", "\"input_boolean.b0\"", "]", ".", "state", "assert", "state", ".", "state", "==", "\"on\"", "assert", "isinstance", "(", "state", ".", "attributes", "[", "\"complicated\"", "]", "[", "\"value\"", "]", ",", "list", ")", "assert", "set", "(", "state", ".", "attributes", "[", "\"complicated\"", "]", "[", "\"value\"", "]", ")", "==", "{", "1", ",", "2", ",", "now", ".", "isoformat", "(", ")", "}" ]
[ 219, 0 ]
[ 242, 83 ]
python
en
['en', 'en', 'en']
True
test_restoring_invalid_entity_id
(hass, hass_storage)
Test restoring invalid entity IDs.
Test restoring invalid entity IDs.
async def test_restoring_invalid_entity_id(hass, hass_storage): """Test restoring invalid entity IDs.""" entity = RestoreEntity() entity.hass = hass entity.entity_id = "test.invalid__entity_id" now = dt_util.utcnow().isoformat() hass_storage[STORAGE_KEY] = { "version": 1, "key": STORAGE_KEY, "data": [ { "state": { "entity_id": "test.invalid__entity_id", "state": "off", "attributes": {}, "last_changed": now, "last_updated": now, "context": { "id": "3c2243ff5f30447eb12e7348cfd5b8ff", "user_id": None, }, }, "last_seen": dt_util.utcnow().isoformat(), } ], } state = await entity.async_get_last_state() assert state is None
[ "async", "def", "test_restoring_invalid_entity_id", "(", "hass", ",", "hass_storage", ")", ":", "entity", "=", "RestoreEntity", "(", ")", "entity", ".", "hass", "=", "hass", "entity", ".", "entity_id", "=", "\"test.invalid__entity_id\"", "now", "=", "dt_util", ".", "utcnow", "(", ")", ".", "isoformat", "(", ")", "hass_storage", "[", "STORAGE_KEY", "]", "=", "{", "\"version\"", ":", "1", ",", "\"key\"", ":", "STORAGE_KEY", ",", "\"data\"", ":", "[", "{", "\"state\"", ":", "{", "\"entity_id\"", ":", "\"test.invalid__entity_id\"", ",", "\"state\"", ":", "\"off\"", ",", "\"attributes\"", ":", "{", "}", ",", "\"last_changed\"", ":", "now", ",", "\"last_updated\"", ":", "now", ",", "\"context\"", ":", "{", "\"id\"", ":", "\"3c2243ff5f30447eb12e7348cfd5b8ff\"", ",", "\"user_id\"", ":", "None", ",", "}", ",", "}", ",", "\"last_seen\"", ":", "dt_util", ".", "utcnow", "(", ")", ".", "isoformat", "(", ")", ",", "}", "]", ",", "}", "state", "=", "await", "entity", ".", "async_get_last_state", "(", ")", "assert", "state", "is", "None" ]
[ 245, 0 ]
[ 273, 24 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: Callable )
Set up Guardian switches based on a config entry.
Set up Guardian switches based on a config entry.
async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: Callable ) -> None: """Set up Guardian switches based on a config entry.""" @callback def add_new_paired_sensor(uid: str) -> None: """Add a new paired sensor.""" coordinator = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][ API_SENSOR_PAIRED_SENSOR_STATUS ][uid] entities = [] for kind in PAIRED_SENSOR_SENSORS: name, device_class, icon, unit = SENSOR_ATTRS_MAP[kind] entities.append( PairedSensorSensor( entry, coordinator, kind, name, device_class, icon, unit ) ) async_add_entities(entities, True) # Handle adding paired sensors after HASS startup: hass.data[DOMAIN][DATA_UNSUB_DISPATCHER_CONNECT][entry.entry_id].append( async_dispatcher_connect( hass, SIGNAL_PAIRED_SENSOR_COORDINATOR_ADDED.format(entry.data[CONF_UID]), add_new_paired_sensor, ) ) sensors = [] # Add all valve controller-specific binary sensors: for kind in VALVE_CONTROLLER_SENSORS: name, device_class, icon, unit = SENSOR_ATTRS_MAP[kind] sensors.append( ValveControllerSensor( entry, hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id], kind, name, device_class, icon, unit, ) ) # Add all paired sensor-specific binary sensors: for coordinator in hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][ API_SENSOR_PAIRED_SENSOR_STATUS ].values(): for kind in PAIRED_SENSOR_SENSORS: name, device_class, icon, unit = SENSOR_ATTRS_MAP[kind] sensors.append( PairedSensorSensor( entry, coordinator, kind, name, device_class, icon, unit ) ) async_add_entities(sensors)
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ",", "async_add_entities", ":", "Callable", ")", "->", "None", ":", "@", "callback", "def", "add_new_paired_sensor", "(", "uid", ":", "str", ")", "->", "None", ":", "\"\"\"Add a new paired sensor.\"\"\"", "coordinator", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "DATA_COORDINATOR", "]", "[", "entry", ".", "entry_id", "]", "[", "API_SENSOR_PAIRED_SENSOR_STATUS", "]", "[", "uid", "]", "entities", "=", "[", "]", "for", "kind", "in", "PAIRED_SENSOR_SENSORS", ":", "name", ",", "device_class", ",", "icon", ",", "unit", "=", "SENSOR_ATTRS_MAP", "[", "kind", "]", "entities", ".", "append", "(", "PairedSensorSensor", "(", "entry", ",", "coordinator", ",", "kind", ",", "name", ",", "device_class", ",", "icon", ",", "unit", ")", ")", "async_add_entities", "(", "entities", ",", "True", ")", "# Handle adding paired sensors after HASS startup:", "hass", ".", "data", "[", "DOMAIN", "]", "[", "DATA_UNSUB_DISPATCHER_CONNECT", "]", "[", "entry", ".", "entry_id", "]", ".", "append", "(", "async_dispatcher_connect", "(", "hass", ",", "SIGNAL_PAIRED_SENSOR_COORDINATOR_ADDED", ".", "format", "(", "entry", ".", "data", "[", "CONF_UID", "]", ")", ",", "add_new_paired_sensor", ",", ")", ")", "sensors", "=", "[", "]", "# Add all valve controller-specific binary sensors:", "for", "kind", "in", "VALVE_CONTROLLER_SENSORS", ":", "name", ",", "device_class", ",", "icon", ",", "unit", "=", "SENSOR_ATTRS_MAP", "[", "kind", "]", "sensors", ".", "append", "(", "ValveControllerSensor", "(", "entry", ",", "hass", ".", "data", "[", "DOMAIN", "]", "[", "DATA_COORDINATOR", "]", "[", "entry", ".", "entry_id", "]", ",", "kind", ",", "name", ",", "device_class", ",", "icon", ",", "unit", ",", ")", ")", "# Add all paired sensor-specific binary sensors:", "for", "coordinator", "in", "hass", ".", "data", "[", "DOMAIN", "]", "[", "DATA_COORDINATOR", "]", "[", "entry", ".", "entry_id", "]", "[", "API_SENSOR_PAIRED_SENSOR_STATUS", "]", ".", "values", "(", ")", ":", "for", "kind", "in", "PAIRED_SENSOR_SENSORS", ":", "name", ",", "device_class", ",", "icon", ",", "unit", "=", "SENSOR_ATTRS_MAP", "[", "kind", "]", "sensors", ".", "append", "(", "PairedSensorSensor", "(", "entry", ",", "coordinator", ",", "kind", ",", "name", ",", "device_class", ",", "icon", ",", "unit", ")", ")", "async_add_entities", "(", "sensors", ")" ]
[ 46, 0 ]
[ 107, 31 ]
python
en
['en', 'en', 'en']
True
PairedSensorSensor.__init__
( self, entry: ConfigEntry, coordinator: DataUpdateCoordinator, kind: str, name: str, device_class: Optional[str], icon: Optional[str], unit: Optional[str], )
Initialize.
Initialize.
def __init__( self, entry: ConfigEntry, coordinator: DataUpdateCoordinator, kind: str, name: str, device_class: Optional[str], icon: Optional[str], unit: Optional[str], ) -> None: """Initialize.""" super().__init__(entry, coordinator, kind, name, device_class, icon) self._state = None self._unit = unit
[ "def", "__init__", "(", "self", ",", "entry", ":", "ConfigEntry", ",", "coordinator", ":", "DataUpdateCoordinator", ",", "kind", ":", "str", ",", "name", ":", "str", ",", "device_class", ":", "Optional", "[", "str", "]", ",", "icon", ":", "Optional", "[", "str", "]", ",", "unit", ":", "Optional", "[", "str", "]", ",", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "entry", ",", "coordinator", ",", "kind", ",", "name", ",", "device_class", ",", "icon", ")", "self", ".", "_state", "=", "None", "self", ".", "_unit", "=", "unit" ]
[ 113, 4 ]
[ 127, 25 ]
python
en
['en', 'en', 'it']
False
PairedSensorSensor.available
(self)
Return whether the entity is available.
Return whether the entity is available.
def available(self) -> bool: """Return whether the entity is available.""" return self.coordinator.last_update_success
[ "def", "available", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "coordinator", ".", "last_update_success" ]
[ 130, 4 ]
[ 132, 51 ]
python
en
['en', 'en', 'en']
True
PairedSensorSensor.state
(self)
Return the sensor state.
Return the sensor state.
def state(self) -> str: """Return the sensor state.""" return self._state
[ "def", "state", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_state" ]
[ 135, 4 ]
[ 137, 26 ]
python
en
['en', 'bs', 'en']
True
PairedSensorSensor.unit_of_measurement
(self)
Return the unit of measurement of this entity, if any.
Return the unit of measurement of this entity, if any.
def unit_of_measurement(self) -> str: """Return the unit of measurement of this entity, if any.""" return self._unit
[ "def", "unit_of_measurement", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_unit" ]
[ 140, 4 ]
[ 142, 25 ]
python
en
['en', 'en', 'en']
True
PairedSensorSensor._async_update_from_latest_data
(self)
Update the entity.
Update the entity.
def _async_update_from_latest_data(self) -> None: """Update the entity.""" if self._kind == SENSOR_KIND_BATTERY: self._state = self.coordinator.data["battery"] elif self._kind == SENSOR_KIND_TEMPERATURE: self._state = self.coordinator.data["temperature"]
[ "def", "_async_update_from_latest_data", "(", "self", ")", "->", "None", ":", "if", "self", ".", "_kind", "==", "SENSOR_KIND_BATTERY", ":", "self", ".", "_state", "=", "self", ".", "coordinator", ".", "data", "[", "\"battery\"", "]", "elif", "self", ".", "_kind", "==", "SENSOR_KIND_TEMPERATURE", ":", "self", ".", "_state", "=", "self", ".", "coordinator", ".", "data", "[", "\"temperature\"", "]" ]
[ 145, 4 ]
[ 150, 62 ]
python
en
['en', 'en', 'en']
True
ValveControllerSensor.__init__
( self, entry: ConfigEntry, coordinators: Dict[str, DataUpdateCoordinator], kind: str, name: str, device_class: Optional[str], icon: Optional[str], unit: Optional[str], )
Initialize.
Initialize.
def __init__( self, entry: ConfigEntry, coordinators: Dict[str, DataUpdateCoordinator], kind: str, name: str, device_class: Optional[str], icon: Optional[str], unit: Optional[str], ) -> None: """Initialize.""" super().__init__(entry, coordinators, kind, name, device_class, icon) self._state = None self._unit = unit
[ "def", "__init__", "(", "self", ",", "entry", ":", "ConfigEntry", ",", "coordinators", ":", "Dict", "[", "str", ",", "DataUpdateCoordinator", "]", ",", "kind", ":", "str", ",", "name", ":", "str", ",", "device_class", ":", "Optional", "[", "str", "]", ",", "icon", ":", "Optional", "[", "str", "]", ",", "unit", ":", "Optional", "[", "str", "]", ",", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "entry", ",", "coordinators", ",", "kind", ",", "name", ",", "device_class", ",", "icon", ")", "self", ".", "_state", "=", "None", "self", ".", "_unit", "=", "unit" ]
[ 156, 4 ]
[ 170, 25 ]
python
en
['en', 'en', 'it']
False
ValveControllerSensor.available
(self)
Return whether the entity is available.
Return whether the entity is available.
def available(self) -> bool: """Return whether the entity is available.""" if self._kind == SENSOR_KIND_TEMPERATURE: return self.coordinators[ API_SYSTEM_ONBOARD_SENSOR_STATUS ].last_update_success if self._kind == SENSOR_KIND_UPTIME: return self.coordinators[API_SYSTEM_DIAGNOSTICS].last_update_success return False
[ "def", "available", "(", "self", ")", "->", "bool", ":", "if", "self", ".", "_kind", "==", "SENSOR_KIND_TEMPERATURE", ":", "return", "self", ".", "coordinators", "[", "API_SYSTEM_ONBOARD_SENSOR_STATUS", "]", ".", "last_update_success", "if", "self", ".", "_kind", "==", "SENSOR_KIND_UPTIME", ":", "return", "self", ".", "coordinators", "[", "API_SYSTEM_DIAGNOSTICS", "]", ".", "last_update_success", "return", "False" ]
[ 173, 4 ]
[ 181, 20 ]
python
en
['en', 'en', 'en']
True
ValveControllerSensor.state
(self)
Return the sensor state.
Return the sensor state.
def state(self) -> str: """Return the sensor state.""" return self._state
[ "def", "state", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_state" ]
[ 184, 4 ]
[ 186, 26 ]
python
en
['en', 'bs', 'en']
True
ValveControllerSensor.unit_of_measurement
(self)
Return the unit of measurement of this entity, if any.
Return the unit of measurement of this entity, if any.
def unit_of_measurement(self) -> str: """Return the unit of measurement of this entity, if any.""" return self._unit
[ "def", "unit_of_measurement", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_unit" ]
[ 189, 4 ]
[ 191, 25 ]
python
en
['en', 'en', 'en']
True
ValveControllerSensor._async_continue_entity_setup
(self)
Register API interest (and related tasks) when the entity is added.
Register API interest (and related tasks) when the entity is added.
async def _async_continue_entity_setup(self) -> None: """Register API interest (and related tasks) when the entity is added.""" if self._kind == SENSOR_KIND_TEMPERATURE: self.async_add_coordinator_update_listener(API_SYSTEM_ONBOARD_SENSOR_STATUS)
[ "async", "def", "_async_continue_entity_setup", "(", "self", ")", "->", "None", ":", "if", "self", ".", "_kind", "==", "SENSOR_KIND_TEMPERATURE", ":", "self", ".", "async_add_coordinator_update_listener", "(", "API_SYSTEM_ONBOARD_SENSOR_STATUS", ")" ]
[ 193, 4 ]
[ 196, 88 ]
python
en
['en', 'en', 'en']
True
ValveControllerSensor._async_update_from_latest_data
(self)
Update the entity.
Update the entity.
def _async_update_from_latest_data(self) -> None: """Update the entity.""" if self._kind == SENSOR_KIND_TEMPERATURE: self._state = self.coordinators[API_SYSTEM_ONBOARD_SENSOR_STATUS].data[ "temperature" ] elif self._kind == SENSOR_KIND_UPTIME: self._state = self.coordinators[API_SYSTEM_DIAGNOSTICS].data["uptime"]
[ "def", "_async_update_from_latest_data", "(", "self", ")", "->", "None", ":", "if", "self", ".", "_kind", "==", "SENSOR_KIND_TEMPERATURE", ":", "self", ".", "_state", "=", "self", ".", "coordinators", "[", "API_SYSTEM_ONBOARD_SENSOR_STATUS", "]", ".", "data", "[", "\"temperature\"", "]", "elif", "self", ".", "_kind", "==", "SENSOR_KIND_UPTIME", ":", "self", ".", "_state", "=", "self", ".", "coordinators", "[", "API_SYSTEM_DIAGNOSTICS", "]", ".", "data", "[", "\"uptime\"", "]" ]
[ 199, 4 ]
[ 206, 82 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Dyson Sensors.
Set up the Dyson Sensors.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Dyson Sensors.""" if discovery_info is None: return hass.data.setdefault(DYSON_SENSOR_DEVICES, []) unit = hass.config.units.temperature_unit devices = hass.data[DYSON_SENSOR_DEVICES] # Get Dyson Devices from parent component device_ids = [device.unique_id for device in hass.data[DYSON_SENSOR_DEVICES]] new_entities = [] for device in hass.data[DYSON_DEVICES]: if isinstance(device, DysonPureCool): if f"{device.serial}-temperature" not in device_ids: new_entities.append(DysonTemperatureSensor(device, unit)) if f"{device.serial}-humidity" not in device_ids: new_entities.append(DysonHumiditySensor(device)) # For PureCool+Humidify devices, a single filter exists, called "Combi Filter". # It's reported with the HEPA state, while the Carbon state is set to INValid. if device.state and device.state.carbon_filter_state == "INV": if f"{device.serial}-hepa_filter_state" not in device_ids: new_entities.append(DysonHepaFilterLifeSensor(device, "Combi")) else: if f"{device.serial}-hepa_filter_state" not in device_ids: new_entities.append(DysonHepaFilterLifeSensor(device)) if f"{device.serial}-carbon_filter_state" not in device_ids: new_entities.append(DysonCarbonFilterLifeSensor(device)) elif isinstance(device, DysonPureCoolLink): new_entities.append(DysonFilterLifeSensor(device)) new_entities.append(DysonDustSensor(device)) new_entities.append(DysonHumiditySensor(device)) new_entities.append(DysonTemperatureSensor(device, unit)) new_entities.append(DysonAirQualitySensor(device)) if not new_entities: return devices.extend(new_entities) add_entities(devices)
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "discovery_info", "is", "None", ":", "return", "hass", ".", "data", ".", "setdefault", "(", "DYSON_SENSOR_DEVICES", ",", "[", "]", ")", "unit", "=", "hass", ".", "config", ".", "units", ".", "temperature_unit", "devices", "=", "hass", ".", "data", "[", "DYSON_SENSOR_DEVICES", "]", "# Get Dyson Devices from parent component", "device_ids", "=", "[", "device", ".", "unique_id", "for", "device", "in", "hass", ".", "data", "[", "DYSON_SENSOR_DEVICES", "]", "]", "new_entities", "=", "[", "]", "for", "device", "in", "hass", ".", "data", "[", "DYSON_DEVICES", "]", ":", "if", "isinstance", "(", "device", ",", "DysonPureCool", ")", ":", "if", "f\"{device.serial}-temperature\"", "not", "in", "device_ids", ":", "new_entities", ".", "append", "(", "DysonTemperatureSensor", "(", "device", ",", "unit", ")", ")", "if", "f\"{device.serial}-humidity\"", "not", "in", "device_ids", ":", "new_entities", ".", "append", "(", "DysonHumiditySensor", "(", "device", ")", ")", "# For PureCool+Humidify devices, a single filter exists, called \"Combi Filter\".", "# It's reported with the HEPA state, while the Carbon state is set to INValid.", "if", "device", ".", "state", "and", "device", ".", "state", ".", "carbon_filter_state", "==", "\"INV\"", ":", "if", "f\"{device.serial}-hepa_filter_state\"", "not", "in", "device_ids", ":", "new_entities", ".", "append", "(", "DysonHepaFilterLifeSensor", "(", "device", ",", "\"Combi\"", ")", ")", "else", ":", "if", "f\"{device.serial}-hepa_filter_state\"", "not", "in", "device_ids", ":", "new_entities", ".", "append", "(", "DysonHepaFilterLifeSensor", "(", "device", ")", ")", "if", "f\"{device.serial}-carbon_filter_state\"", "not", "in", "device_ids", ":", "new_entities", ".", "append", "(", "DysonCarbonFilterLifeSensor", "(", "device", ")", ")", "elif", "isinstance", "(", "device", ",", "DysonPureCoolLink", ")", ":", "new_entities", ".", "append", "(", "DysonFilterLifeSensor", "(", "device", ")", ")", "new_entities", ".", "append", "(", "DysonDustSensor", "(", "device", ")", ")", "new_entities", ".", "append", "(", "DysonHumiditySensor", "(", "device", ")", ")", "new_entities", ".", "append", "(", "DysonTemperatureSensor", "(", "device", ",", "unit", ")", ")", "new_entities", ".", "append", "(", "DysonAirQualitySensor", "(", "device", ")", ")", "if", "not", "new_entities", ":", "return", "devices", ".", "extend", "(", "new_entities", ")", "add_entities", "(", "devices", ")" ]
[ 35, 0 ]
[ 76, 25 ]
python
en
['en', 'sq', 'en']
True
DysonSensor.__init__
(self, device, sensor_type)
Create a new generic Dyson sensor.
Create a new generic Dyson sensor.
def __init__(self, device, sensor_type): """Create a new generic Dyson sensor.""" self._device = device self._old_value = None self._name = None self._sensor_type = sensor_type
[ "def", "__init__", "(", "self", ",", "device", ",", "sensor_type", ")", ":", "self", ".", "_device", "=", "device", "self", ".", "_old_value", "=", "None", "self", ".", "_name", "=", "None", "self", ".", "_sensor_type", "=", "sensor_type" ]
[ 82, 4 ]
[ 87, 39 ]
python
en
['en', 'ga', 'en']
True
DysonSensor.async_added_to_hass
(self)
Call when entity is added to hass.
Call when entity is added to hass.
async def async_added_to_hass(self): """Call when entity is added to hass.""" self._device.add_message_listener(self.on_message)
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "self", ".", "_device", ".", "add_message_listener", "(", "self", ".", "on_message", ")" ]
[ 89, 4 ]
[ 91, 58 ]
python
en
['en', 'en', 'en']
True
DysonSensor.on_message
(self, message)
Handle new messages which are received from the fan.
Handle new messages which are received from the fan.
def on_message(self, message): """Handle new messages which are received from the fan.""" # Prevent refreshing if not needed if self._old_value is None or self._old_value != self.state: _LOGGER.debug("Message received for %s device: %s", self.name, message) self._old_value = self.state self.schedule_update_ha_state()
[ "def", "on_message", "(", "self", ",", "message", ")", ":", "# Prevent refreshing if not needed", "if", "self", ".", "_old_value", "is", "None", "or", "self", ".", "_old_value", "!=", "self", ".", "state", ":", "_LOGGER", ".", "debug", "(", "\"Message received for %s device: %s\"", ",", "self", ".", "name", ",", "message", ")", "self", ".", "_old_value", "=", "self", ".", "state", "self", ".", "schedule_update_ha_state", "(", ")" ]
[ 93, 4 ]
[ 99, 43 ]
python
en
['en', 'en', 'en']
True
DysonSensor.should_poll
(self)
No polling needed.
No polling needed.
def should_poll(self): """No polling needed.""" return False
[ "def", "should_poll", "(", "self", ")", ":", "return", "False" ]
[ 102, 4 ]
[ 104, 20 ]
python
en
['en', 'en', 'en']
True
DysonSensor.name
(self)
Return the name of the Dyson sensor name.
Return the name of the Dyson sensor name.
def name(self): """Return the name of the Dyson sensor name.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 107, 4 ]
[ 109, 25 ]
python
en
['en', 'sq', 'en']
True
DysonSensor.unit_of_measurement
(self)
Return the unit the value is expressed in.
Return the unit the value is expressed in.
def unit_of_measurement(self): """Return the unit the value is expressed in.""" return SENSOR_UNITS[self._sensor_type]
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "SENSOR_UNITS", "[", "self", ".", "_sensor_type", "]" ]
[ 112, 4 ]
[ 114, 46 ]
python
en
['en', 'en', 'en']
True
DysonSensor.icon
(self)
Return the icon for this sensor.
Return the icon for this sensor.
def icon(self): """Return the icon for this sensor.""" return SENSOR_ICONS[self._sensor_type]
[ "def", "icon", "(", "self", ")", ":", "return", "SENSOR_ICONS", "[", "self", ".", "_sensor_type", "]" ]
[ 117, 4 ]
[ 119, 46 ]
python
en
['en', 'en', 'en']
True
DysonSensor.unique_id
(self)
Return the sensor's unique id.
Return the sensor's unique id.
def unique_id(self): """Return the sensor's unique id.""" return f"{self._device.serial}-{self._sensor_type}"
[ "def", "unique_id", "(", "self", ")", ":", "return", "f\"{self._device.serial}-{self._sensor_type}\"" ]
[ 122, 4 ]
[ 124, 59 ]
python
en
['en', 'ca', 'en']
True
DysonFilterLifeSensor.__init__
(self, device)
Create a new Dyson Filter Life sensor.
Create a new Dyson Filter Life sensor.
def __init__(self, device): """Create a new Dyson Filter Life sensor.""" super().__init__(device, "filter_life") self._name = f"{self._device.name} Filter Life"
[ "def", "__init__", "(", "self", ",", "device", ")", ":", "super", "(", ")", ".", "__init__", "(", "device", ",", "\"filter_life\"", ")", "self", ".", "_name", "=", "f\"{self._device.name} Filter Life\"" ]
[ 130, 4 ]
[ 133, 55 ]
python
en
['en', 'gl', 'en']
True