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 |
---|---|---|---|---|---|---|---|---|---|---|---|
VlcDevice.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
144,
4
] | [
146,
25
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
149,
4
] | [
151,
26
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self) -> bool:
"""Return True if entity is available."""
return self._available | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_available"
] | [
154,
4
] | [
156,
30
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.volume_level | (self) | Volume level of the media player (0..1). | Volume level of the media player (0..1). | def volume_level(self):
"""Volume level of the media player (0..1)."""
return self._volume | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"self",
".",
"_volume"
] | [
159,
4
] | [
161,
27
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.is_volume_muted | (self) | Boolean if volume is currently muted. | Boolean if volume is currently muted. | def is_volume_muted(self):
"""Boolean if volume is currently muted."""
return self._muted | [
"def",
"is_volume_muted",
"(",
"self",
")",
":",
"return",
"self",
".",
"_muted"
] | [
164,
4
] | [
166,
26
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.supported_features | (self) | Flag media player features that are supported. | Flag media player features that are supported. | def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_VLC | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_VLC"
] | [
169,
4
] | [
171,
26
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.media_content_type | (self) | Content type of current playing media. | Content type of current playing media. | def media_content_type(self):
"""Content type of current playing media."""
return MEDIA_TYPE_MUSIC | [
"def",
"media_content_type",
"(",
"self",
")",
":",
"return",
"MEDIA_TYPE_MUSIC"
] | [
174,
4
] | [
176,
31
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.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."""
return self._media_duration | [
"def",
"media_duration",
"(",
"self",
")",
":",
"return",
"self",
".",
"_media_duration"
] | [
179,
4
] | [
181,
35
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.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."""
return self._media_position | [
"def",
"media_position",
"(",
"self",
")",
":",
"return",
"self",
".",
"_media_position"
] | [
184,
4
] | [
186,
35
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.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."""
return self._media_position_updated_at | [
"def",
"media_position_updated_at",
"(",
"self",
")",
":",
"return",
"self",
".",
"_media_position_updated_at"
] | [
189,
4
] | [
191,
46
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.media_title | (self) | Title of current playing media. | Title of current playing media. | def media_title(self):
"""Title of current playing media."""
return self._media_title | [
"def",
"media_title",
"(",
"self",
")",
":",
"return",
"self",
".",
"_media_title"
] | [
194,
4
] | [
196,
32
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.media_artist | (self) | Artist of current playing media, music track only. | Artist of current playing media, music track only. | def media_artist(self):
"""Artist of current playing media, music track only."""
return self._media_artist | [
"def",
"media_artist",
"(",
"self",
")",
":",
"return",
"self",
".",
"_media_artist"
] | [
199,
4
] | [
201,
33
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.media_seek | (self, position) | Seek the media to a specific location. | Seek the media to a specific location. | def media_seek(self, position):
"""Seek the media to a specific location."""
track_length = self._vlc.get_length() / 1000
self._vlc.seek(position / track_length) | [
"def",
"media_seek",
"(",
"self",
",",
"position",
")",
":",
"track_length",
"=",
"self",
".",
"_vlc",
".",
"get_length",
"(",
")",
"/",
"1000",
"self",
".",
"_vlc",
".",
"seek",
"(",
"position",
"/",
"track_length",
")"
] | [
203,
4
] | [
206,
47
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.mute_volume | (self, mute) | Mute the volume. | Mute the volume. | def mute_volume(self, mute):
"""Mute the volume."""
if mute:
self._volume_bkp = self._volume
self._volume = 0
self._vlc.set_volume("0")
else:
self._vlc.set_volume(str(self._volume_bkp))
self._volume = self._volume_bkp
self._muted = mute | [
"def",
"mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"if",
"mute",
":",
"self",
".",
"_volume_bkp",
"=",
"self",
".",
"_volume",
"self",
".",
"_volume",
"=",
"0",
"self",
".",
"_vlc",
".",
"set_volume",
"(",
"\"0\"",
")",
"else",
":",
"self",
".",
"_vlc",
".",
"set_volume",
"(",
"str",
"(",
"self",
".",
"_volume_bkp",
")",
")",
"self",
".",
"_volume",
"=",
"self",
".",
"_volume_bkp",
"self",
".",
"_muted",
"=",
"mute"
] | [
208,
4
] | [
218,
26
] | python | en | ['en', 'sn', 'en'] | True |
VlcDevice.set_volume_level | (self, volume) | Set volume level, range 0..1. | Set volume level, range 0..1. | def set_volume_level(self, volume):
"""Set volume level, range 0..1."""
self._vlc.set_volume(str(volume * 500))
self._volume = volume | [
"def",
"set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"self",
".",
"_vlc",
".",
"set_volume",
"(",
"str",
"(",
"volume",
"*",
"500",
")",
")",
"self",
".",
"_volume",
"=",
"volume"
] | [
220,
4
] | [
223,
29
] | python | en | ['fr', 'zu', 'en'] | False |
VlcDevice.media_play | (self) | Send play command. | Send play command. | def media_play(self):
"""Send play command."""
self._vlc.play()
self._state = STATE_PLAYING | [
"def",
"media_play",
"(",
"self",
")",
":",
"self",
".",
"_vlc",
".",
"play",
"(",
")",
"self",
".",
"_state",
"=",
"STATE_PLAYING"
] | [
225,
4
] | [
228,
35
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.media_pause | (self) | Send pause command. | Send pause command. | def media_pause(self):
"""Send pause command."""
self._vlc.pause()
self._state = STATE_PAUSED | [
"def",
"media_pause",
"(",
"self",
")",
":",
"self",
".",
"_vlc",
".",
"pause",
"(",
")",
"self",
".",
"_state",
"=",
"STATE_PAUSED"
] | [
230,
4
] | [
233,
34
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.media_stop | (self) | Send stop command. | Send stop command. | def media_stop(self):
"""Send stop command."""
self._vlc.stop()
self._state = STATE_IDLE | [
"def",
"media_stop",
"(",
"self",
")",
":",
"self",
".",
"_vlc",
".",
"stop",
"(",
")",
"self",
".",
"_state",
"=",
"STATE_IDLE"
] | [
235,
4
] | [
238,
32
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.play_media | (self, media_type, media_id, **kwargs) | Play media from a URL or file. | Play media from a URL or file. | def play_media(self, media_type, media_id, **kwargs):
"""Play media from a URL or file."""
if media_type != MEDIA_TYPE_MUSIC:
_LOGGER.error(
"Invalid media type %s. Only %s is supported",
media_type,
MEDIA_TYPE_MUSIC,
)
return
self._vlc.add(media_id)
self._state = STATE_PLAYING | [
"def",
"play_media",
"(",
"self",
",",
"media_type",
",",
"media_id",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"media_type",
"!=",
"MEDIA_TYPE_MUSIC",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid media type %s. Only %s is supported\"",
",",
"media_type",
",",
"MEDIA_TYPE_MUSIC",
",",
")",
"return",
"self",
".",
"_vlc",
".",
"add",
"(",
"media_id",
")",
"self",
".",
"_state",
"=",
"STATE_PLAYING"
] | [
240,
4
] | [
250,
35
] | python | en | ['en', 'en', 'en'] | True |
VlcDevice.media_previous_track | (self) | Send previous track command. | Send previous track command. | def media_previous_track(self):
"""Send previous track command."""
self._vlc.prev() | [
"def",
"media_previous_track",
"(",
"self",
")",
":",
"self",
".",
"_vlc",
".",
"prev",
"(",
")"
] | [
252,
4
] | [
254,
24
] | python | en | ['en', 'it', 'en'] | True |
VlcDevice.media_next_track | (self) | Send next track command. | Send next track command. | def media_next_track(self):
"""Send next track command."""
self._vlc.next() | [
"def",
"media_next_track",
"(",
"self",
")",
":",
"self",
".",
"_vlc",
".",
"next",
"(",
")"
] | [
256,
4
] | [
258,
24
] | python | en | ['en', 'pt', 'en'] | True |
VlcDevice.clear_playlist | (self) | Clear players playlist. | Clear players playlist. | def clear_playlist(self):
"""Clear players playlist."""
self._vlc.clear() | [
"def",
"clear_playlist",
"(",
"self",
")",
":",
"self",
".",
"_vlc",
".",
"clear",
"(",
")"
] | [
260,
4
] | [
262,
25
] | python | en | ['fr', 'en', 'en'] | True |
VlcDevice.set_shuffle | (self, shuffle) | Enable/disable shuffle mode. | Enable/disable shuffle mode. | def set_shuffle(self, shuffle):
"""Enable/disable shuffle mode."""
self._vlc.random(shuffle) | [
"def",
"set_shuffle",
"(",
"self",
",",
"shuffle",
")",
":",
"self",
".",
"_vlc",
".",
"random",
"(",
"shuffle",
")"
] | [
264,
4
] | [
266,
33
] | python | en | ['en', 'st', 'en'] | True |
host_valid | (host) | Return True if hostname or IP address is valid. | Return True if hostname or IP address is valid. | def host_valid(host):
"""Return True if hostname or IP address is valid."""
try:
if ipaddress.ip_address(host).version == (4 or 6):
return True
except ValueError:
if len(host) > 253:
return False
allowed = re.compile(r"(?!-)[A-Z\d\-\_]{1,63}(?<!-)$", re.IGNORECASE)
return all(allowed.match(x) for x in host.split(".")) | [
"def",
"host_valid",
"(",
"host",
")",
":",
"try",
":",
"if",
"ipaddress",
".",
"ip_address",
"(",
"host",
")",
".",
"version",
"==",
"(",
"4",
"or",
"6",
")",
":",
"return",
"True",
"except",
"ValueError",
":",
"if",
"len",
"(",
"host",
")",
">",
"253",
":",
"return",
"False",
"allowed",
"=",
"re",
".",
"compile",
"(",
"r\"(?!-)[A-Z\\d\\-\\_]{1,63}(?<!-)$\"",
",",
"re",
".",
"IGNORECASE",
")",
"return",
"all",
"(",
"allowed",
".",
"match",
"(",
"x",
")",
"for",
"x",
"in",
"host",
".",
"split",
"(",
"\".\"",
")",
")"
] | [
16,
0
] | [
25,
61
] | python | en | ['en', 'af', 'en'] | True |
DuneHDConfigFlow.__init__ | (self) | Initialize. | Initialize. | def __init__(self):
"""Initialize."""
self.host = None | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"host",
"=",
"None"
] | [
34,
4
] | [
36,
24
] | python | en | ['en', 'en', 'it'] | False |
DuneHDConfigFlow.init_device | (self, host) | Initialize Dune HD player. | Initialize Dune HD player. | async def init_device(self, host):
"""Initialize Dune HD player."""
player = DuneHDPlayer(host)
state = await self.hass.async_add_executor_job(player.update_state)
if not state:
raise CannotConnect() | [
"async",
"def",
"init_device",
"(",
"self",
",",
"host",
")",
":",
"player",
"=",
"DuneHDPlayer",
"(",
"host",
")",
"state",
"=",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"player",
".",
"update_state",
")",
"if",
"not",
"state",
":",
"raise",
"CannotConnect",
"(",
")"
] | [
38,
4
] | [
43,
33
] | python | en | ['fr', 'en', 'it'] | False |
DuneHDConfigFlow.async_step_user | (self, user_input=None) | Handle the initial step. | Handle the initial step. | async def async_step_user(self, user_input=None):
"""Handle the initial step."""
errors = {}
if user_input is not None:
if host_valid(user_input[CONF_HOST]):
self.host = user_input[CONF_HOST]
try:
if self.host_already_configured(self.host):
raise AlreadyConfigured()
await self.init_device(self.host)
except CannotConnect:
errors[CONF_HOST] = "cannot_connect"
except AlreadyConfigured:
errors[CONF_HOST] = "already_configured"
else:
return self.async_create_entry(title=self.host, data=user_input)
else:
errors[CONF_HOST] = "invalid_host"
return self.async_show_form(
step_id="user",
data_schema=vol.Schema({vol.Required(CONF_HOST, default=""): str}),
errors=errors,
) | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"if",
"host_valid",
"(",
"user_input",
"[",
"CONF_HOST",
"]",
")",
":",
"self",
".",
"host",
"=",
"user_input",
"[",
"CONF_HOST",
"]",
"try",
":",
"if",
"self",
".",
"host_already_configured",
"(",
"self",
".",
"host",
")",
":",
"raise",
"AlreadyConfigured",
"(",
")",
"await",
"self",
".",
"init_device",
"(",
"self",
".",
"host",
")",
"except",
"CannotConnect",
":",
"errors",
"[",
"CONF_HOST",
"]",
"=",
"\"cannot_connect\"",
"except",
"AlreadyConfigured",
":",
"errors",
"[",
"CONF_HOST",
"]",
"=",
"\"already_configured\"",
"else",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"self",
".",
"host",
",",
"data",
"=",
"user_input",
")",
"else",
":",
"errors",
"[",
"CONF_HOST",
"]",
"=",
"\"invalid_host\"",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_HOST",
",",
"default",
"=",
"\"\"",
")",
":",
"str",
"}",
")",
",",
"errors",
"=",
"errors",
",",
")"
] | [
45,
4
] | [
70,
9
] | python | en | ['en', 'en', 'en'] | True |
DuneHDConfigFlow.async_step_import | (self, user_input=None) | Handle configuration by yaml file. | Handle configuration by yaml file. | async def async_step_import(self, user_input=None):
"""Handle configuration by yaml file."""
self.host = user_input[CONF_HOST]
if self.host_already_configured(self.host):
return self.async_abort(reason="already_configured")
try:
await self.init_device(self.host)
except CannotConnect:
_LOGGER.error("Import aborted, cannot connect to %s", self.host)
return self.async_abort(reason="cannot_connect")
else:
return self.async_create_entry(title=self.host, data=user_input) | [
"async",
"def",
"async_step_import",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"self",
".",
"host",
"=",
"user_input",
"[",
"CONF_HOST",
"]",
"if",
"self",
".",
"host_already_configured",
"(",
"self",
".",
"host",
")",
":",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"already_configured\"",
")",
"try",
":",
"await",
"self",
".",
"init_device",
"(",
"self",
".",
"host",
")",
"except",
"CannotConnect",
":",
"_LOGGER",
".",
"error",
"(",
"\"Import aborted, cannot connect to %s\"",
",",
"self",
".",
"host",
")",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"cannot_connect\"",
")",
"else",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"self",
".",
"host",
",",
"data",
"=",
"user_input",
")"
] | [
72,
4
] | [
85,
76
] | python | en | ['en', 'en', 'en'] | True |
DuneHDConfigFlow.host_already_configured | (self, host) | See if we already have a dunehd entry matching user input configured. | See if we already have a dunehd entry matching user input configured. | def host_already_configured(self, host):
"""See if we already have a dunehd entry matching user input configured."""
existing_hosts = {
entry.data[CONF_HOST] for entry in self._async_current_entries()
}
return host in existing_hosts | [
"def",
"host_already_configured",
"(",
"self",
",",
"host",
")",
":",
"existing_hosts",
"=",
"{",
"entry",
".",
"data",
"[",
"CONF_HOST",
"]",
"for",
"entry",
"in",
"self",
".",
"_async_current_entries",
"(",
")",
"}",
"return",
"host",
"in",
"existing_hosts"
] | [
87,
4
] | [
92,
37
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (
hass: HomeAssistantType,
config_entry: config_entries.ConfigEntry,
async_add_entities,
) | Set up the configuration entry. | Set up the configuration entry. | async def async_setup_entry(
hass: HomeAssistantType,
config_entry: config_entries.ConfigEntry,
async_add_entities,
):
"""Set up the configuration entry."""
client = get_entry_client(hass, config_entry)
async_add_entities(
[
ArcamFmj(
config_entry.title,
State(client, zone),
config_entry.unique_id or config_entry.entry_id,
)
for zone in [1, 2]
],
True,
)
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config_entry",
":",
"config_entries",
".",
"ConfigEntry",
",",
"async_add_entities",
",",
")",
":",
"client",
"=",
"get_entry_client",
"(",
"hass",
",",
"config_entry",
")",
"async_add_entities",
"(",
"[",
"ArcamFmj",
"(",
"config_entry",
".",
"title",
",",
"State",
"(",
"client",
",",
"zone",
")",
",",
"config_entry",
".",
"unique_id",
"or",
"config_entry",
".",
"entry_id",
",",
")",
"for",
"zone",
"in",
"[",
"1",
",",
"2",
"]",
"]",
",",
"True",
",",
")",
"return",
"True"
] | [
39,
0
] | [
60,
15
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.__init__ | (
self,
device_name,
state: State,
uuid: str,
) | Initialize device. | Initialize device. | def __init__(
self,
device_name,
state: State,
uuid: str,
):
"""Initialize device."""
self._state = state
self._device_name = device_name
self._name = f"{device_name} - Zone: {state.zn}"
self._uuid = uuid
self._support = (
SUPPORT_SELECT_SOURCE
| SUPPORT_PLAY_MEDIA
| SUPPORT_BROWSE_MEDIA
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_MUTE
| SUPPORT_VOLUME_STEP
| SUPPORT_TURN_OFF
| SUPPORT_TURN_ON
)
if state.zn == 1:
self._support |= SUPPORT_SELECT_SOUND_MODE | [
"def",
"__init__",
"(",
"self",
",",
"device_name",
",",
"state",
":",
"State",
",",
"uuid",
":",
"str",
",",
")",
":",
"self",
".",
"_state",
"=",
"state",
"self",
".",
"_device_name",
"=",
"device_name",
"self",
".",
"_name",
"=",
"f\"{device_name} - Zone: {state.zn}\"",
"self",
".",
"_uuid",
"=",
"uuid",
"self",
".",
"_support",
"=",
"(",
"SUPPORT_SELECT_SOURCE",
"|",
"SUPPORT_PLAY_MEDIA",
"|",
"SUPPORT_BROWSE_MEDIA",
"|",
"SUPPORT_VOLUME_SET",
"|",
"SUPPORT_VOLUME_MUTE",
"|",
"SUPPORT_VOLUME_STEP",
"|",
"SUPPORT_TURN_OFF",
"|",
"SUPPORT_TURN_ON",
")",
"if",
"state",
".",
"zn",
"==",
"1",
":",
"self",
".",
"_support",
"|=",
"SUPPORT_SELECT_SOUND_MODE"
] | [
66,
4
] | [
88,
54
] | python | en | ['fr', 'en', 'en'] | False |
ArcamFmj._get_2ch | (self) | Return if source is 2 channel or not. | Return if source is 2 channel or not. | def _get_2ch(self):
"""Return if source is 2 channel or not."""
audio_format, _ = self._state.get_incoming_audio_format()
return bool(
audio_format
in (
IncomingAudioFormat.PCM,
IncomingAudioFormat.ANALOGUE_DIRECT,
IncomingAudioFormat.UNDETECTED,
None,
)
) | [
"def",
"_get_2ch",
"(",
"self",
")",
":",
"audio_format",
",",
"_",
"=",
"self",
".",
"_state",
".",
"get_incoming_audio_format",
"(",
")",
"return",
"bool",
"(",
"audio_format",
"in",
"(",
"IncomingAudioFormat",
".",
"PCM",
",",
"IncomingAudioFormat",
".",
"ANALOGUE_DIRECT",
",",
"IncomingAudioFormat",
".",
"UNDETECTED",
",",
"None",
",",
")",
")"
] | [
90,
4
] | [
101,
9
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.entity_registry_enabled_default | (self) | Return if the entity should be enabled when first added to the entity registry. | Return if the entity should be enabled when first added to the entity registry. | def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return self._state.zn == 1 | [
"def",
"entity_registry_enabled_default",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_state",
".",
"zn",
"==",
"1"
] | [
104,
4
] | [
106,
34
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.unique_id | (self) | Return unique identifier if known. | Return unique identifier if known. | def unique_id(self):
"""Return unique identifier if known."""
return f"{self._uuid}-{self._state.zn}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self._uuid}-{self._state.zn}\""
] | [
109,
4
] | [
111,
47
] | python | de | ['fr', 'de', 'en'] | False |
ArcamFmj.device_info | (self) | Return a device description for device registry. | Return a device description for device registry. | def device_info(self):
"""Return a device description for device registry."""
return {
"name": self._device_name,
"identifiers": {
(DOMAIN, self._uuid),
(DOMAIN, self._state.client.host, self._state.client.port),
},
"model": "Arcam FMJ AVR",
"manufacturer": "Arcam",
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"name\"",
":",
"self",
".",
"_device_name",
",",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"_uuid",
")",
",",
"(",
"DOMAIN",
",",
"self",
".",
"_state",
".",
"client",
".",
"host",
",",
"self",
".",
"_state",
".",
"client",
".",
"port",
")",
",",
"}",
",",
"\"model\"",
":",
"\"Arcam FMJ AVR\"",
",",
"\"manufacturer\"",
":",
"\"Arcam\"",
",",
"}"
] | [
114,
4
] | [
124,
9
] | python | en | ['ro', 'fr', 'en'] | False |
ArcamFmj.should_poll | (self) | No need to poll. | No need to poll. | def should_poll(self) -> bool:
"""No need to poll."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"False"
] | [
127,
4
] | [
129,
20
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.name | (self) | Return the name of the controlled device. | Return the name of the controlled device. | def name(self):
"""Return the name of the controlled device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
132,
4
] | [
134,
25
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
if self._state.get_power():
return STATE_ON
return STATE_OFF | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
".",
"get_power",
"(",
")",
":",
"return",
"STATE_ON",
"return",
"STATE_OFF"
] | [
137,
4
] | [
141,
24
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.supported_features | (self) | Flag media player features that are supported. | Flag media player features that are supported. | def supported_features(self):
"""Flag media player features that are supported."""
return self._support | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"self",
".",
"_support"
] | [
144,
4
] | [
146,
28
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.async_added_to_hass | (self) | Once registered, add listener for events. | Once registered, add listener for events. | async def async_added_to_hass(self):
"""Once registered, add listener for events."""
await self._state.start()
@callback
def _data(host):
if host == self._state.client.host:
self.async_write_ha_state()
@callback
def _started(host):
if host == self._state.client.host:
self.async_schedule_update_ha_state(force_refresh=True)
@callback
def _stopped(host):
if host == self._state.client.host:
self.async_schedule_update_ha_state(force_refresh=True)
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_CLIENT_DATA, _data
)
)
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_CLIENT_STARTED, _started
)
)
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_CLIENT_STOPPED, _stopped
)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"self",
".",
"_state",
".",
"start",
"(",
")",
"@",
"callback",
"def",
"_data",
"(",
"host",
")",
":",
"if",
"host",
"==",
"self",
".",
"_state",
".",
"client",
".",
"host",
":",
"self",
".",
"async_write_ha_state",
"(",
")",
"@",
"callback",
"def",
"_started",
"(",
"host",
")",
":",
"if",
"host",
"==",
"self",
".",
"_state",
".",
"client",
".",
"host",
":",
"self",
".",
"async_schedule_update_ha_state",
"(",
"force_refresh",
"=",
"True",
")",
"@",
"callback",
"def",
"_stopped",
"(",
"host",
")",
":",
"if",
"host",
"==",
"self",
".",
"_state",
".",
"client",
".",
"host",
":",
"self",
".",
"async_schedule_update_ha_state",
"(",
"force_refresh",
"=",
"True",
")",
"self",
".",
"async_on_remove",
"(",
"self",
".",
"hass",
".",
"helpers",
".",
"dispatcher",
".",
"async_dispatcher_connect",
"(",
"SIGNAL_CLIENT_DATA",
",",
"_data",
")",
")",
"self",
".",
"async_on_remove",
"(",
"self",
".",
"hass",
".",
"helpers",
".",
"dispatcher",
".",
"async_dispatcher_connect",
"(",
"SIGNAL_CLIENT_STARTED",
",",
"_started",
")",
")",
"self",
".",
"async_on_remove",
"(",
"self",
".",
"hass",
".",
"helpers",
".",
"dispatcher",
".",
"async_dispatcher_connect",
"(",
"SIGNAL_CLIENT_STOPPED",
",",
"_stopped",
")",
")"
] | [
148,
4
] | [
183,
9
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.async_update | (self) | Force update of state. | Force update of state. | async def async_update(self):
"""Force update of state."""
_LOGGER.debug("Update state %s", self.name)
await self._state.update() | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Update state %s\"",
",",
"self",
".",
"name",
")",
"await",
"self",
".",
"_state",
".",
"update",
"(",
")"
] | [
185,
4
] | [
188,
34
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.async_mute_volume | (self, mute) | Send mute command. | Send mute command. | async def async_mute_volume(self, mute):
"""Send mute command."""
await self._state.set_mute(mute)
self.async_write_ha_state() | [
"async",
"def",
"async_mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"await",
"self",
".",
"_state",
".",
"set_mute",
"(",
"mute",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
190,
4
] | [
193,
35
] | python | en | ['en', 'co', 'en'] | True |
ArcamFmj.async_select_source | (self, source) | Select a specific source. | Select a specific source. | async def async_select_source(self, source):
"""Select a specific source."""
try:
value = SourceCodes[source]
except KeyError:
_LOGGER.error("Unsupported source %s", source)
return
await self._state.set_source(value)
self.async_write_ha_state() | [
"async",
"def",
"async_select_source",
"(",
"self",
",",
"source",
")",
":",
"try",
":",
"value",
"=",
"SourceCodes",
"[",
"source",
"]",
"except",
"KeyError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unsupported source %s\"",
",",
"source",
")",
"return",
"await",
"self",
".",
"_state",
".",
"set_source",
"(",
"value",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
195,
4
] | [
204,
35
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.async_select_sound_mode | (self, sound_mode) | Select a specific source. | Select a specific source. | async def async_select_sound_mode(self, sound_mode):
"""Select a specific source."""
try:
if self._get_2ch():
await self._state.set_decode_mode_2ch(DecodeMode2CH[sound_mode])
else:
await self._state.set_decode_mode_mch(DecodeModeMCH[sound_mode])
except KeyError:
_LOGGER.error("Unsupported sound_mode %s", sound_mode)
return
self.async_write_ha_state() | [
"async",
"def",
"async_select_sound_mode",
"(",
"self",
",",
"sound_mode",
")",
":",
"try",
":",
"if",
"self",
".",
"_get_2ch",
"(",
")",
":",
"await",
"self",
".",
"_state",
".",
"set_decode_mode_2ch",
"(",
"DecodeMode2CH",
"[",
"sound_mode",
"]",
")",
"else",
":",
"await",
"self",
".",
"_state",
".",
"set_decode_mode_mch",
"(",
"DecodeModeMCH",
"[",
"sound_mode",
"]",
")",
"except",
"KeyError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unsupported sound_mode %s\"",
",",
"sound_mode",
")",
"return",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
206,
4
] | [
217,
35
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.async_set_volume_level | (self, volume) | Set volume level, range 0..1. | Set volume level, range 0..1. | async def async_set_volume_level(self, volume):
"""Set volume level, range 0..1."""
await self._state.set_volume(round(volume * 99.0))
self.async_write_ha_state() | [
"async",
"def",
"async_set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"await",
"self",
".",
"_state",
".",
"set_volume",
"(",
"round",
"(",
"volume",
"*",
"99.0",
")",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
219,
4
] | [
222,
35
] | python | en | ['fr', 'zu', 'en'] | False |
ArcamFmj.async_volume_up | (self) | Turn volume up for media player. | Turn volume up for media player. | async def async_volume_up(self):
"""Turn volume up for media player."""
await self._state.inc_volume()
self.async_write_ha_state() | [
"async",
"def",
"async_volume_up",
"(",
"self",
")",
":",
"await",
"self",
".",
"_state",
".",
"inc_volume",
"(",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
224,
4
] | [
227,
35
] | python | en | ['en', 'no', 'en'] | True |
ArcamFmj.async_volume_down | (self) | Turn volume up for media player. | Turn volume up for media player. | async def async_volume_down(self):
"""Turn volume up for media player."""
await self._state.dec_volume()
self.async_write_ha_state() | [
"async",
"def",
"async_volume_down",
"(",
"self",
")",
":",
"await",
"self",
".",
"_state",
".",
"dec_volume",
"(",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
229,
4
] | [
232,
35
] | python | en | ['en', 'no', 'en'] | True |
ArcamFmj.async_turn_on | (self) | Turn the media player on. | Turn the media player on. | async def async_turn_on(self):
"""Turn the media player on."""
if self._state.get_power() is not None:
_LOGGER.debug("Turning on device using connection")
await self._state.set_power(True)
else:
_LOGGER.debug("Firing event to turn on device")
self.hass.bus.async_fire(EVENT_TURN_ON, {ATTR_ENTITY_ID: self.entity_id}) | [
"async",
"def",
"async_turn_on",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
".",
"get_power",
"(",
")",
"is",
"not",
"None",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Turning on device using connection\"",
")",
"await",
"self",
".",
"_state",
".",
"set_power",
"(",
"True",
")",
"else",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Firing event to turn on device\"",
")",
"self",
".",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"self",
".",
"entity_id",
"}",
")"
] | [
234,
4
] | [
241,
85
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.async_turn_off | (self) | Turn the media player off. | Turn the media player off. | async def async_turn_off(self):
"""Turn the media player off."""
await self._state.set_power(False) | [
"async",
"def",
"async_turn_off",
"(",
"self",
")",
":",
"await",
"self",
".",
"_state",
".",
"set_power",
"(",
"False",
")"
] | [
243,
4
] | [
245,
42
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.async_browse_media | (self, media_content_type=None, media_content_id=None) | Implement the websocket media browsing helper. | Implement the websocket media browsing helper. | async def async_browse_media(self, media_content_type=None, media_content_id=None):
"""Implement the websocket media browsing helper."""
if media_content_id not in (None, "root"):
raise BrowseError(
f"Media not found: {media_content_type} / {media_content_id}"
)
presets = self._state.get_preset_details()
radio = [
BrowseMedia(
title=preset.name,
media_class=MEDIA_CLASS_MUSIC,
media_content_id=f"preset:{preset.index}",
media_content_type=MEDIA_TYPE_MUSIC,
can_play=True,
can_expand=False,
)
for preset in presets.values()
]
root = BrowseMedia(
title="Root",
media_class=MEDIA_CLASS_DIRECTORY,
media_content_id="root",
media_content_type="library",
can_play=False,
can_expand=True,
children=radio,
)
return root | [
"async",
"def",
"async_browse_media",
"(",
"self",
",",
"media_content_type",
"=",
"None",
",",
"media_content_id",
"=",
"None",
")",
":",
"if",
"media_content_id",
"not",
"in",
"(",
"None",
",",
"\"root\"",
")",
":",
"raise",
"BrowseError",
"(",
"f\"Media not found: {media_content_type} / {media_content_id}\"",
")",
"presets",
"=",
"self",
".",
"_state",
".",
"get_preset_details",
"(",
")",
"radio",
"=",
"[",
"BrowseMedia",
"(",
"title",
"=",
"preset",
".",
"name",
",",
"media_class",
"=",
"MEDIA_CLASS_MUSIC",
",",
"media_content_id",
"=",
"f\"preset:{preset.index}\"",
",",
"media_content_type",
"=",
"MEDIA_TYPE_MUSIC",
",",
"can_play",
"=",
"True",
",",
"can_expand",
"=",
"False",
",",
")",
"for",
"preset",
"in",
"presets",
".",
"values",
"(",
")",
"]",
"root",
"=",
"BrowseMedia",
"(",
"title",
"=",
"\"Root\"",
",",
"media_class",
"=",
"MEDIA_CLASS_DIRECTORY",
",",
"media_content_id",
"=",
"\"root\"",
",",
"media_content_type",
"=",
"\"library\"",
",",
"can_play",
"=",
"False",
",",
"can_expand",
"=",
"True",
",",
"children",
"=",
"radio",
",",
")",
"return",
"root"
] | [
247,
4
] | [
278,
19
] | python | en | ['en', 'af', 'en'] | True |
ArcamFmj.async_play_media | (self, media_type: str, media_id: str, **kwargs) | Play media. | Play media. | async def async_play_media(self, media_type: str, media_id: str, **kwargs) -> None:
"""Play media."""
if media_id.startswith("preset:"):
preset = int(media_id[7:])
await self._state.set_tuner_preset(preset)
else:
_LOGGER.error("Media %s is not supported", media_id)
return | [
"async",
"def",
"async_play_media",
"(",
"self",
",",
"media_type",
":",
"str",
",",
"media_id",
":",
"str",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"if",
"media_id",
".",
"startswith",
"(",
"\"preset:\"",
")",
":",
"preset",
"=",
"int",
"(",
"media_id",
"[",
"7",
":",
"]",
")",
"await",
"self",
".",
"_state",
".",
"set_tuner_preset",
"(",
"preset",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Media %s is not supported\"",
",",
"media_id",
")",
"return"
] | [
280,
4
] | [
288,
18
] | python | en | ['en', 'sv', 'en'] | False |
ArcamFmj.source | (self) | Return the current input source. | Return the current input source. | def source(self):
"""Return the current input source."""
value = self._state.get_source()
if value is None:
return None
return value.name | [
"def",
"source",
"(",
"self",
")",
":",
"value",
"=",
"self",
".",
"_state",
".",
"get_source",
"(",
")",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"return",
"value",
".",
"name"
] | [
291,
4
] | [
296,
25
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.source_list | (self) | List of available input sources. | List of available input sources. | def source_list(self):
"""List of available input sources."""
return [x.name for x in self._state.get_source_list()] | [
"def",
"source_list",
"(",
"self",
")",
":",
"return",
"[",
"x",
".",
"name",
"for",
"x",
"in",
"self",
".",
"_state",
".",
"get_source_list",
"(",
")",
"]"
] | [
299,
4
] | [
301,
62
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.sound_mode | (self) | Name of the current sound mode. | Name of the current sound mode. | def sound_mode(self):
"""Name of the current sound mode."""
if self._state.zn != 1:
return None
if self._get_2ch():
value = self._state.get_decode_mode_2ch()
else:
value = self._state.get_decode_mode_mch()
if value:
return value.name
return None | [
"def",
"sound_mode",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
".",
"zn",
"!=",
"1",
":",
"return",
"None",
"if",
"self",
".",
"_get_2ch",
"(",
")",
":",
"value",
"=",
"self",
".",
"_state",
".",
"get_decode_mode_2ch",
"(",
")",
"else",
":",
"value",
"=",
"self",
".",
"_state",
".",
"get_decode_mode_mch",
"(",
")",
"if",
"value",
":",
"return",
"value",
".",
"name",
"return",
"None"
] | [
304,
4
] | [
315,
19
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.sound_mode_list | (self) | List of available sound modes. | List of available sound modes. | def sound_mode_list(self):
"""List of available sound modes."""
if self._state.zn != 1:
return None
if self._get_2ch():
return [x.name for x in DecodeMode2CH]
return [x.name for x in DecodeModeMCH] | [
"def",
"sound_mode_list",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
".",
"zn",
"!=",
"1",
":",
"return",
"None",
"if",
"self",
".",
"_get_2ch",
"(",
")",
":",
"return",
"[",
"x",
".",
"name",
"for",
"x",
"in",
"DecodeMode2CH",
"]",
"return",
"[",
"x",
".",
"name",
"for",
"x",
"in",
"DecodeModeMCH",
"]"
] | [
318,
4
] | [
325,
46
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.is_volume_muted | (self) | Boolean if volume is currently muted. | Boolean if volume is currently muted. | def is_volume_muted(self):
"""Boolean if volume is currently muted."""
value = self._state.get_mute()
if value is None:
return None
return value | [
"def",
"is_volume_muted",
"(",
"self",
")",
":",
"value",
"=",
"self",
".",
"_state",
".",
"get_mute",
"(",
")",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"return",
"value"
] | [
328,
4
] | [
333,
20
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.volume_level | (self) | Volume level of device. | Volume level of device. | def volume_level(self):
"""Volume level of device."""
value = self._state.get_volume()
if value is None:
return None
return value / 99.0 | [
"def",
"volume_level",
"(",
"self",
")",
":",
"value",
"=",
"self",
".",
"_state",
".",
"get_volume",
"(",
")",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"return",
"value",
"/",
"99.0"
] | [
336,
4
] | [
341,
27
] | python | en | ['en', 'sr', 'en'] | True |
ArcamFmj.media_content_type | (self) | Content type of current playing media. | Content type of current playing media. | def media_content_type(self):
"""Content type of current playing media."""
source = self._state.get_source()
if source == SourceCodes.DAB:
value = MEDIA_TYPE_MUSIC
elif source == SourceCodes.FM:
value = MEDIA_TYPE_MUSIC
else:
value = None
return value | [
"def",
"media_content_type",
"(",
"self",
")",
":",
"source",
"=",
"self",
".",
"_state",
".",
"get_source",
"(",
")",
"if",
"source",
"==",
"SourceCodes",
".",
"DAB",
":",
"value",
"=",
"MEDIA_TYPE_MUSIC",
"elif",
"source",
"==",
"SourceCodes",
".",
"FM",
":",
"value",
"=",
"MEDIA_TYPE_MUSIC",
"else",
":",
"value",
"=",
"None",
"return",
"value"
] | [
344,
4
] | [
353,
20
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.media_content_id | (self) | Content type of current playing media. | Content type of current playing media. | def media_content_id(self):
"""Content type of current playing media."""
source = self._state.get_source()
if source in (SourceCodes.DAB, SourceCodes.FM):
preset = self._state.get_tuner_preset()
if preset:
value = f"preset:{preset}"
else:
value = None
else:
value = None
return value | [
"def",
"media_content_id",
"(",
"self",
")",
":",
"source",
"=",
"self",
".",
"_state",
".",
"get_source",
"(",
")",
"if",
"source",
"in",
"(",
"SourceCodes",
".",
"DAB",
",",
"SourceCodes",
".",
"FM",
")",
":",
"preset",
"=",
"self",
".",
"_state",
".",
"get_tuner_preset",
"(",
")",
"if",
"preset",
":",
"value",
"=",
"f\"preset:{preset}\"",
"else",
":",
"value",
"=",
"None",
"else",
":",
"value",
"=",
"None",
"return",
"value"
] | [
356,
4
] | [
368,
20
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.media_channel | (self) | Channel currently playing. | Channel currently playing. | def media_channel(self):
"""Channel currently playing."""
source = self._state.get_source()
if source == SourceCodes.DAB:
value = self._state.get_dab_station()
elif source == SourceCodes.FM:
value = self._state.get_rds_information()
else:
value = None
return value | [
"def",
"media_channel",
"(",
"self",
")",
":",
"source",
"=",
"self",
".",
"_state",
".",
"get_source",
"(",
")",
"if",
"source",
"==",
"SourceCodes",
".",
"DAB",
":",
"value",
"=",
"self",
".",
"_state",
".",
"get_dab_station",
"(",
")",
"elif",
"source",
"==",
"SourceCodes",
".",
"FM",
":",
"value",
"=",
"self",
".",
"_state",
".",
"get_rds_information",
"(",
")",
"else",
":",
"value",
"=",
"None",
"return",
"value"
] | [
371,
4
] | [
380,
20
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.media_artist | (self) | Artist of current playing media, music track only. | Artist of current playing media, music track only. | def media_artist(self):
"""Artist of current playing media, music track only."""
source = self._state.get_source()
if source == SourceCodes.DAB:
value = self._state.get_dls_pdt()
else:
value = None
return value | [
"def",
"media_artist",
"(",
"self",
")",
":",
"source",
"=",
"self",
".",
"_state",
".",
"get_source",
"(",
")",
"if",
"source",
"==",
"SourceCodes",
".",
"DAB",
":",
"value",
"=",
"self",
".",
"_state",
".",
"get_dls_pdt",
"(",
")",
"else",
":",
"value",
"=",
"None",
"return",
"value"
] | [
383,
4
] | [
390,
20
] | python | en | ['en', 'en', 'en'] | True |
ArcamFmj.media_title | (self) | Title of current playing media. | Title of current playing media. | def media_title(self):
"""Title of current playing media."""
source = self._state.get_source()
if source is None:
return None
channel = self.media_channel
if channel:
value = f"{source.name} - {channel}"
else:
value = source.name
return value | [
"def",
"media_title",
"(",
"self",
")",
":",
"source",
"=",
"self",
".",
"_state",
".",
"get_source",
"(",
")",
"if",
"source",
"is",
"None",
":",
"return",
"None",
"channel",
"=",
"self",
".",
"media_channel",
"if",
"channel",
":",
"value",
"=",
"f\"{source.name} - {channel}\"",
"else",
":",
"value",
"=",
"source",
".",
"name",
"return",
"value"
] | [
393,
4
] | [
405,
20
] | python | en | ['en', 'en', 'en'] | True |
create_container | () | Create a container, aka 'docker run'.
Returns:
None.
| Create a container, aka 'docker run'. | def create_container():
"""Create a container, aka 'docker run'.
Returns:
None.
"""
try:
create_config = request.json
return DockerController.create_container_with_config(create_config=create_config)
except CommandExecutionError:
abort(400) | [
"def",
"create_container",
"(",
")",
":",
"try",
":",
"create_config",
"=",
"request",
".",
"json",
"return",
"DockerController",
".",
"create_container_with_config",
"(",
"create_config",
"=",
"create_config",
")",
"except",
"CommandExecutionError",
":",
"abort",
"(",
"400",
")"
] | [
18,
0
] | [
29,
18
] | python | en | ['en', 'gd', 'en'] | True |
delete_container | (container_name: str) | Delete a container, aka 'docker rm'.
Args:
container_name (str): Name of the container.
Returns:
None.
| Delete a container, aka 'docker rm'. | def delete_container(container_name: str):
"""Delete a container, aka 'docker rm'.
Args:
container_name (str): Name of the container.
Returns:
None.
"""
try:
DockerController.remove_container(container_name=container_name)
return {}
except CommandExecutionError:
abort(400) | [
"def",
"delete_container",
"(",
"container_name",
":",
"str",
")",
":",
"try",
":",
"DockerController",
".",
"remove_container",
"(",
"container_name",
"=",
"container_name",
")",
"return",
"{",
"}",
"except",
"CommandExecutionError",
":",
"abort",
"(",
"400",
")"
] | [
33,
0
] | [
47,
18
] | python | en | ['en', 'en', 'pt'] | True |
stop_container | (container_name: str) | Stop a container, aka 'docker stop'.
Args:
container_name (str): Name of the container.
Returns:
None.
| Stop a container, aka 'docker stop'. | def stop_container(container_name: str):
"""Stop a container, aka 'docker stop'.
Args:
container_name (str): Name of the container.
Returns:
None.
"""
try:
DockerController.stop_container(container_name=container_name)
return {}
except CommandExecutionError:
abort(400) | [
"def",
"stop_container",
"(",
"container_name",
":",
"str",
")",
":",
"try",
":",
"DockerController",
".",
"stop_container",
"(",
"container_name",
"=",
"container_name",
")",
"return",
"{",
"}",
"except",
"CommandExecutionError",
":",
"abort",
"(",
"400",
")"
] | [
51,
0
] | [
65,
18
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Zigbee Home Automation light from config entry. | Set up the Zigbee Home Automation light from config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Zigbee Home Automation light from config entry."""
entities_to_create = hass.data[DATA_ZHA][light.DOMAIN]
unsub = async_dispatcher_connect(
hass,
SIGNAL_ADD_ENTITIES,
functools.partial(
discovery.async_add_entities, async_add_entities, entities_to_create
),
)
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"entities_to_create",
"=",
"hass",
".",
"data",
"[",
"DATA_ZHA",
"]",
"[",
"light",
".",
"DOMAIN",
"]",
"unsub",
"=",
"async_dispatcher_connect",
"(",
"hass",
",",
"SIGNAL_ADD_ENTITIES",
",",
"functools",
".",
"partial",
"(",
"discovery",
".",
"async_add_entities",
",",
"async_add_entities",
",",
"entities_to_create",
")",
",",
")",
"hass",
".",
"data",
"[",
"DATA_ZHA",
"]",
"[",
"DATA_ZHA_DISPATCHERS",
"]",
".",
"append",
"(",
"unsub",
")"
] | [
90,
0
] | [
101,
59
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.__init__ | (self, *args, **kwargs) | Initialize the light. | Initialize the light. | def __init__(self, *args, **kwargs):
"""Initialize the light."""
super().__init__(*args, **kwargs)
self._available: bool = False
self._brightness: Optional[int] = None
self._off_brightness: Optional[int] = None
self._hs_color: Optional[Tuple[float, float]] = None
self._color_temp: Optional[int] = None
self._min_mireds: Optional[int] = 153
self._max_mireds: Optional[int] = 500
self._white_value: Optional[int] = None
self._effect_list: Optional[List[str]] = None
self._effect: Optional[str] = None
self._supported_features: int = 0
self._state: bool = False
self._on_off_channel = None
self._level_channel = None
self._color_channel = None
self._identify_channel = None | [
"def",
"__init__",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"_available",
":",
"bool",
"=",
"False",
"self",
".",
"_brightness",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
"self",
".",
"_off_brightness",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
"self",
".",
"_hs_color",
":",
"Optional",
"[",
"Tuple",
"[",
"float",
",",
"float",
"]",
"]",
"=",
"None",
"self",
".",
"_color_temp",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
"self",
".",
"_min_mireds",
":",
"Optional",
"[",
"int",
"]",
"=",
"153",
"self",
".",
"_max_mireds",
":",
"Optional",
"[",
"int",
"]",
"=",
"500",
"self",
".",
"_white_value",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
"self",
".",
"_effect_list",
":",
"Optional",
"[",
"List",
"[",
"str",
"]",
"]",
"=",
"None",
"self",
".",
"_effect",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
"self",
".",
"_supported_features",
":",
"int",
"=",
"0",
"self",
".",
"_state",
":",
"bool",
"=",
"False",
"self",
".",
"_on_off_channel",
"=",
"None",
"self",
".",
"_level_channel",
"=",
"None",
"self",
".",
"_color_channel",
"=",
"None",
"self",
".",
"_identify_channel",
"=",
"None"
] | [
107,
4
] | [
125,
37
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.device_state_attributes | (self) | Return state attributes. | Return state attributes. | def device_state_attributes(self) -> Dict[str, Any]:
"""Return state attributes."""
attributes = {"off_brightness": self._off_brightness}
return attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"attributes",
"=",
"{",
"\"off_brightness\"",
":",
"self",
".",
"_off_brightness",
"}",
"return",
"attributes"
] | [
128,
4
] | [
131,
25
] | python | en | ['en', 'co', 'en'] | True |
BaseLight.is_on | (self) | Return true if entity is on. | Return true if entity is on. | def is_on(self) -> bool:
"""Return true if entity is on."""
if self._state is None:
return False
return self._state | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"self",
".",
"_state",
"is",
"None",
":",
"return",
"False",
"return",
"self",
".",
"_state"
] | [
134,
4
] | [
138,
26
] | python | en | ['en', 'cy', 'en'] | True |
BaseLight.brightness | (self) | Return the brightness of this light. | Return the brightness of this light. | def brightness(self):
"""Return the brightness of this light."""
return self._brightness | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_brightness"
] | [
141,
4
] | [
143,
31
] | python | en | ['en', 'sn', 'en'] | True |
BaseLight.min_mireds | (self) | Return the coldest color_temp that this light supports. | Return the coldest color_temp that this light supports. | def min_mireds(self):
"""Return the coldest color_temp that this light supports."""
return self._min_mireds | [
"def",
"min_mireds",
"(",
"self",
")",
":",
"return",
"self",
".",
"_min_mireds"
] | [
146,
4
] | [
148,
31
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.max_mireds | (self) | Return the warmest color_temp that this light supports. | Return the warmest color_temp that this light supports. | def max_mireds(self):
"""Return the warmest color_temp that this light supports."""
return self._max_mireds | [
"def",
"max_mireds",
"(",
"self",
")",
":",
"return",
"self",
".",
"_max_mireds"
] | [
151,
4
] | [
153,
31
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.set_level | (self, value) | Set the brightness of this light between 0..254.
brightness level 255 is a special value instructing the device to come
on at `on_level` Zigbee attribute value, regardless of the last set
level
| Set the brightness of this light between 0..254. | def set_level(self, value):
"""Set the brightness of this light between 0..254.
brightness level 255 is a special value instructing the device to come
on at `on_level` Zigbee attribute value, regardless of the last set
level
"""
value = max(0, min(254, value))
self._brightness = value
self.async_write_ha_state() | [
"def",
"set_level",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"max",
"(",
"0",
",",
"min",
"(",
"254",
",",
"value",
")",
")",
"self",
".",
"_brightness",
"=",
"value",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
155,
4
] | [
164,
35
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.hs_color | (self) | Return the hs color value [int, int]. | Return the hs color value [int, int]. | def hs_color(self):
"""Return the hs color value [int, int]."""
return self._hs_color | [
"def",
"hs_color",
"(",
"self",
")",
":",
"return",
"self",
".",
"_hs_color"
] | [
167,
4
] | [
169,
29
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.color_temp | (self) | Return the CT color value in mireds. | Return the CT color value in mireds. | def color_temp(self):
"""Return the CT color value in mireds."""
return self._color_temp | [
"def",
"color_temp",
"(",
"self",
")",
":",
"return",
"self",
".",
"_color_temp"
] | [
172,
4
] | [
174,
31
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.effect_list | (self) | Return the list of supported effects. | Return the list of supported effects. | def effect_list(self):
"""Return the list of supported effects."""
return self._effect_list | [
"def",
"effect_list",
"(",
"self",
")",
":",
"return",
"self",
".",
"_effect_list"
] | [
177,
4
] | [
179,
32
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.effect | (self) | Return the current effect. | Return the current effect. | def effect(self):
"""Return the current effect."""
return self._effect | [
"def",
"effect",
"(",
"self",
")",
":",
"return",
"self",
".",
"_effect"
] | [
182,
4
] | [
184,
27
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return self._supported_features | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"self",
".",
"_supported_features"
] | [
187,
4
] | [
189,
39
] | python | en | ['da', 'en', 'en'] | True |
BaseLight.async_turn_on | (self, **kwargs) | Turn the entity on. | Turn the entity on. | async def async_turn_on(self, **kwargs):
"""Turn the entity on."""
transition = kwargs.get(light.ATTR_TRANSITION)
duration = transition * 10 if transition else 1
brightness = kwargs.get(light.ATTR_BRIGHTNESS)
effect = kwargs.get(light.ATTR_EFFECT)
flash = kwargs.get(light.ATTR_FLASH)
if brightness is None and self._off_brightness is not None:
brightness = self._off_brightness
t_log = {}
if (
brightness is not None or transition
) and self._supported_features & light.SUPPORT_BRIGHTNESS:
if brightness is not None:
level = min(254, brightness)
else:
level = self._brightness or 254
result = await self._level_channel.move_to_level_with_on_off(
level, duration
)
t_log["move_to_level_with_on_off"] = result
if not isinstance(result, list) or result[1] is not Status.SUCCESS:
self.debug("turned on: %s", t_log)
return
self._state = bool(level)
if level:
self._brightness = level
if brightness is None or brightness:
# since some lights don't always turn on with move_to_level_with_on_off,
# we should call the on command on the on_off cluster if brightness is not 0.
result = await self._on_off_channel.on()
t_log["on_off"] = result
if not isinstance(result, list) or result[1] is not Status.SUCCESS:
self.debug("turned on: %s", t_log)
return
self._state = True
if (
light.ATTR_COLOR_TEMP in kwargs
and self.supported_features & light.SUPPORT_COLOR_TEMP
):
temperature = kwargs[light.ATTR_COLOR_TEMP]
result = await self._color_channel.move_to_color_temp(temperature, duration)
t_log["move_to_color_temp"] = result
if not isinstance(result, list) or result[1] is not Status.SUCCESS:
self.debug("turned on: %s", t_log)
return
self._color_temp = temperature
if (
light.ATTR_HS_COLOR in kwargs
and self.supported_features & light.SUPPORT_COLOR
):
hs_color = kwargs[light.ATTR_HS_COLOR]
xy_color = color_util.color_hs_to_xy(*hs_color)
result = await self._color_channel.move_to_color(
int(xy_color[0] * 65535), int(xy_color[1] * 65535), duration
)
t_log["move_to_color"] = result
if not isinstance(result, list) or result[1] is not Status.SUCCESS:
self.debug("turned on: %s", t_log)
return
self._hs_color = hs_color
if (
effect == light.EFFECT_COLORLOOP
and self.supported_features & light.SUPPORT_EFFECT
):
result = await self._color_channel.color_loop_set(
UPDATE_COLORLOOP_ACTION
| UPDATE_COLORLOOP_DIRECTION
| UPDATE_COLORLOOP_TIME,
0x2, # start from current hue
0x1, # only support up
transition if transition else 7, # transition
0, # no hue
)
t_log["color_loop_set"] = result
self._effect = light.EFFECT_COLORLOOP
elif (
self._effect == light.EFFECT_COLORLOOP
and effect != light.EFFECT_COLORLOOP
and self.supported_features & light.SUPPORT_EFFECT
):
result = await self._color_channel.color_loop_set(
UPDATE_COLORLOOP_ACTION,
0x0,
0x0,
0x0,
0x0, # update action only, action off, no dir,time,hue
)
t_log["color_loop_set"] = result
self._effect = None
if flash is not None and self._supported_features & light.SUPPORT_FLASH:
result = await self._identify_channel.trigger_effect(
FLASH_EFFECTS[flash], EFFECT_DEFAULT_VARIANT
)
t_log["trigger_effect"] = result
self._off_brightness = None
self.debug("turned on: %s", t_log)
self.async_write_ha_state() | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"transition",
"=",
"kwargs",
".",
"get",
"(",
"light",
".",
"ATTR_TRANSITION",
")",
"duration",
"=",
"transition",
"*",
"10",
"if",
"transition",
"else",
"1",
"brightness",
"=",
"kwargs",
".",
"get",
"(",
"light",
".",
"ATTR_BRIGHTNESS",
")",
"effect",
"=",
"kwargs",
".",
"get",
"(",
"light",
".",
"ATTR_EFFECT",
")",
"flash",
"=",
"kwargs",
".",
"get",
"(",
"light",
".",
"ATTR_FLASH",
")",
"if",
"brightness",
"is",
"None",
"and",
"self",
".",
"_off_brightness",
"is",
"not",
"None",
":",
"brightness",
"=",
"self",
".",
"_off_brightness",
"t_log",
"=",
"{",
"}",
"if",
"(",
"brightness",
"is",
"not",
"None",
"or",
"transition",
")",
"and",
"self",
".",
"_supported_features",
"&",
"light",
".",
"SUPPORT_BRIGHTNESS",
":",
"if",
"brightness",
"is",
"not",
"None",
":",
"level",
"=",
"min",
"(",
"254",
",",
"brightness",
")",
"else",
":",
"level",
"=",
"self",
".",
"_brightness",
"or",
"254",
"result",
"=",
"await",
"self",
".",
"_level_channel",
".",
"move_to_level_with_on_off",
"(",
"level",
",",
"duration",
")",
"t_log",
"[",
"\"move_to_level_with_on_off\"",
"]",
"=",
"result",
"if",
"not",
"isinstance",
"(",
"result",
",",
"list",
")",
"or",
"result",
"[",
"1",
"]",
"is",
"not",
"Status",
".",
"SUCCESS",
":",
"self",
".",
"debug",
"(",
"\"turned on: %s\"",
",",
"t_log",
")",
"return",
"self",
".",
"_state",
"=",
"bool",
"(",
"level",
")",
"if",
"level",
":",
"self",
".",
"_brightness",
"=",
"level",
"if",
"brightness",
"is",
"None",
"or",
"brightness",
":",
"# since some lights don't always turn on with move_to_level_with_on_off,",
"# we should call the on command on the on_off cluster if brightness is not 0.",
"result",
"=",
"await",
"self",
".",
"_on_off_channel",
".",
"on",
"(",
")",
"t_log",
"[",
"\"on_off\"",
"]",
"=",
"result",
"if",
"not",
"isinstance",
"(",
"result",
",",
"list",
")",
"or",
"result",
"[",
"1",
"]",
"is",
"not",
"Status",
".",
"SUCCESS",
":",
"self",
".",
"debug",
"(",
"\"turned on: %s\"",
",",
"t_log",
")",
"return",
"self",
".",
"_state",
"=",
"True",
"if",
"(",
"light",
".",
"ATTR_COLOR_TEMP",
"in",
"kwargs",
"and",
"self",
".",
"supported_features",
"&",
"light",
".",
"SUPPORT_COLOR_TEMP",
")",
":",
"temperature",
"=",
"kwargs",
"[",
"light",
".",
"ATTR_COLOR_TEMP",
"]",
"result",
"=",
"await",
"self",
".",
"_color_channel",
".",
"move_to_color_temp",
"(",
"temperature",
",",
"duration",
")",
"t_log",
"[",
"\"move_to_color_temp\"",
"]",
"=",
"result",
"if",
"not",
"isinstance",
"(",
"result",
",",
"list",
")",
"or",
"result",
"[",
"1",
"]",
"is",
"not",
"Status",
".",
"SUCCESS",
":",
"self",
".",
"debug",
"(",
"\"turned on: %s\"",
",",
"t_log",
")",
"return",
"self",
".",
"_color_temp",
"=",
"temperature",
"if",
"(",
"light",
".",
"ATTR_HS_COLOR",
"in",
"kwargs",
"and",
"self",
".",
"supported_features",
"&",
"light",
".",
"SUPPORT_COLOR",
")",
":",
"hs_color",
"=",
"kwargs",
"[",
"light",
".",
"ATTR_HS_COLOR",
"]",
"xy_color",
"=",
"color_util",
".",
"color_hs_to_xy",
"(",
"*",
"hs_color",
")",
"result",
"=",
"await",
"self",
".",
"_color_channel",
".",
"move_to_color",
"(",
"int",
"(",
"xy_color",
"[",
"0",
"]",
"*",
"65535",
")",
",",
"int",
"(",
"xy_color",
"[",
"1",
"]",
"*",
"65535",
")",
",",
"duration",
")",
"t_log",
"[",
"\"move_to_color\"",
"]",
"=",
"result",
"if",
"not",
"isinstance",
"(",
"result",
",",
"list",
")",
"or",
"result",
"[",
"1",
"]",
"is",
"not",
"Status",
".",
"SUCCESS",
":",
"self",
".",
"debug",
"(",
"\"turned on: %s\"",
",",
"t_log",
")",
"return",
"self",
".",
"_hs_color",
"=",
"hs_color",
"if",
"(",
"effect",
"==",
"light",
".",
"EFFECT_COLORLOOP",
"and",
"self",
".",
"supported_features",
"&",
"light",
".",
"SUPPORT_EFFECT",
")",
":",
"result",
"=",
"await",
"self",
".",
"_color_channel",
".",
"color_loop_set",
"(",
"UPDATE_COLORLOOP_ACTION",
"|",
"UPDATE_COLORLOOP_DIRECTION",
"|",
"UPDATE_COLORLOOP_TIME",
",",
"0x2",
",",
"# start from current hue",
"0x1",
",",
"# only support up",
"transition",
"if",
"transition",
"else",
"7",
",",
"# transition",
"0",
",",
"# no hue",
")",
"t_log",
"[",
"\"color_loop_set\"",
"]",
"=",
"result",
"self",
".",
"_effect",
"=",
"light",
".",
"EFFECT_COLORLOOP",
"elif",
"(",
"self",
".",
"_effect",
"==",
"light",
".",
"EFFECT_COLORLOOP",
"and",
"effect",
"!=",
"light",
".",
"EFFECT_COLORLOOP",
"and",
"self",
".",
"supported_features",
"&",
"light",
".",
"SUPPORT_EFFECT",
")",
":",
"result",
"=",
"await",
"self",
".",
"_color_channel",
".",
"color_loop_set",
"(",
"UPDATE_COLORLOOP_ACTION",
",",
"0x0",
",",
"0x0",
",",
"0x0",
",",
"0x0",
",",
"# update action only, action off, no dir,time,hue",
")",
"t_log",
"[",
"\"color_loop_set\"",
"]",
"=",
"result",
"self",
".",
"_effect",
"=",
"None",
"if",
"flash",
"is",
"not",
"None",
"and",
"self",
".",
"_supported_features",
"&",
"light",
".",
"SUPPORT_FLASH",
":",
"result",
"=",
"await",
"self",
".",
"_identify_channel",
".",
"trigger_effect",
"(",
"FLASH_EFFECTS",
"[",
"flash",
"]",
",",
"EFFECT_DEFAULT_VARIANT",
")",
"t_log",
"[",
"\"trigger_effect\"",
"]",
"=",
"result",
"self",
".",
"_off_brightness",
"=",
"None",
"self",
".",
"debug",
"(",
"\"turned on: %s\"",
",",
"t_log",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
191,
4
] | [
295,
35
] | python | en | ['en', 'en', 'en'] | True |
BaseLight.async_turn_off | (self, **kwargs) | Turn the entity off. | Turn the entity off. | async def async_turn_off(self, **kwargs):
"""Turn the entity off."""
duration = kwargs.get(light.ATTR_TRANSITION)
supports_level = self.supported_features & light.SUPPORT_BRIGHTNESS
if duration and supports_level:
result = await self._level_channel.move_to_level_with_on_off(
0, duration * 10
)
else:
result = await self._on_off_channel.off()
self.debug("turned off: %s", result)
if not isinstance(result, list) or result[1] is not Status.SUCCESS:
return
self._state = False
if duration and supports_level:
# store current brightness so that the next turn_on uses it.
self._off_brightness = self._brightness
self.async_write_ha_state() | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"duration",
"=",
"kwargs",
".",
"get",
"(",
"light",
".",
"ATTR_TRANSITION",
")",
"supports_level",
"=",
"self",
".",
"supported_features",
"&",
"light",
".",
"SUPPORT_BRIGHTNESS",
"if",
"duration",
"and",
"supports_level",
":",
"result",
"=",
"await",
"self",
".",
"_level_channel",
".",
"move_to_level_with_on_off",
"(",
"0",
",",
"duration",
"*",
"10",
")",
"else",
":",
"result",
"=",
"await",
"self",
".",
"_on_off_channel",
".",
"off",
"(",
")",
"self",
".",
"debug",
"(",
"\"turned off: %s\"",
",",
"result",
")",
"if",
"not",
"isinstance",
"(",
"result",
",",
"list",
")",
"or",
"result",
"[",
"1",
"]",
"is",
"not",
"Status",
".",
"SUCCESS",
":",
"return",
"self",
".",
"_state",
"=",
"False",
"if",
"duration",
"and",
"supports_level",
":",
"# store current brightness so that the next turn_on uses it.",
"self",
".",
"_off_brightness",
"=",
"self",
".",
"_brightness",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
297,
4
] | [
317,
35
] | python | en | ['en', 'en', 'en'] | True |
get_scanner | (hass, config) | Validate the configuration and return a Linksys AP scanner. | Validate the configuration and return a Linksys AP scanner. | def get_scanner(hass, config):
"""Validate the configuration and return a Linksys AP scanner."""
try:
return LinksysSmartWifiDeviceScanner(config[DOMAIN])
except ConnectionError:
return None | [
"def",
"get_scanner",
"(",
"hass",
",",
"config",
")",
":",
"try",
":",
"return",
"LinksysSmartWifiDeviceScanner",
"(",
"config",
"[",
"DOMAIN",
"]",
")",
"except",
"ConnectionError",
":",
"return",
"None"
] | [
21,
0
] | [
26,
19
] | python | en | ['en', 'en', 'en'] | True |
LinksysSmartWifiDeviceScanner.__init__ | (self, config) | Initialize the scanner. | Initialize the scanner. | def __init__(self, config):
"""Initialize the scanner."""
self.host = config[CONF_HOST]
self.last_results = {}
# Check if the access point is accessible
response = self._make_request()
if not response.status_code == HTTP_OK:
raise ConnectionError("Cannot connect to Linksys Access Point") | [
"def",
"__init__",
"(",
"self",
",",
"config",
")",
":",
"self",
".",
"host",
"=",
"config",
"[",
"CONF_HOST",
"]",
"self",
".",
"last_results",
"=",
"{",
"}",
"# Check if the access point is accessible",
"response",
"=",
"self",
".",
"_make_request",
"(",
")",
"if",
"not",
"response",
".",
"status_code",
"==",
"HTTP_OK",
":",
"raise",
"ConnectionError",
"(",
"\"Cannot connect to Linksys Access Point\"",
")"
] | [
32,
4
] | [
40,
75
] | python | en | ['en', 'en', 'en'] | True |
LinksysSmartWifiDeviceScanner.scan_devices | (self) | Scan for new devices and return a list with device IDs (MACs). | Scan for new devices and return a list with device IDs (MACs). | def scan_devices(self):
"""Scan for new devices and return a list with device IDs (MACs)."""
self._update_info()
return self.last_results.keys() | [
"def",
"scan_devices",
"(",
"self",
")",
":",
"self",
".",
"_update_info",
"(",
")",
"return",
"self",
".",
"last_results",
".",
"keys",
"(",
")"
] | [
42,
4
] | [
46,
39
] | python | en | ['en', 'en', 'en'] | True |
LinksysSmartWifiDeviceScanner.get_device_name | (self, device) | Return the name (if known) of the device. | Return the name (if known) of the device. | def get_device_name(self, device):
"""Return the name (if known) of the device."""
return self.last_results.get(device) | [
"def",
"get_device_name",
"(",
"self",
",",
"device",
")",
":",
"return",
"self",
".",
"last_results",
".",
"get",
"(",
"device",
")"
] | [
48,
4
] | [
50,
44
] | python | en | ['en', 'en', 'en'] | True |
LinksysSmartWifiDeviceScanner._update_info | (self) | Check for connected devices. | Check for connected devices. | def _update_info(self):
"""Check for connected devices."""
_LOGGER.info("Checking Linksys Smart Wifi")
self.last_results = {}
response = self._make_request()
if response.status_code != HTTP_OK:
_LOGGER.error(
"Got HTTP status code %d when getting device list", response.status_code
)
return False
try:
data = response.json()
result = data["responses"][0]
devices = result["output"]["devices"]
for device in devices:
macs = device["knownMACAddresses"]
if not macs:
_LOGGER.warning("Skipping device without known MAC address")
continue
mac = macs[-1]
connections = device["connections"]
if not connections:
_LOGGER.debug("Device %s is not connected", mac)
continue
name = None
for prop in device["properties"]:
if prop["name"] == "userDeviceName":
name = prop["value"]
if not name:
name = device.get("friendlyName", device["deviceID"])
_LOGGER.debug("Device %s is connected", mac)
self.last_results[mac] = name
except (KeyError, IndexError):
_LOGGER.exception("Router returned unexpected response")
return False
return True | [
"def",
"_update_info",
"(",
"self",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Checking Linksys Smart Wifi\"",
")",
"self",
".",
"last_results",
"=",
"{",
"}",
"response",
"=",
"self",
".",
"_make_request",
"(",
")",
"if",
"response",
".",
"status_code",
"!=",
"HTTP_OK",
":",
"_LOGGER",
".",
"error",
"(",
"\"Got HTTP status code %d when getting device list\"",
",",
"response",
".",
"status_code",
")",
"return",
"False",
"try",
":",
"data",
"=",
"response",
".",
"json",
"(",
")",
"result",
"=",
"data",
"[",
"\"responses\"",
"]",
"[",
"0",
"]",
"devices",
"=",
"result",
"[",
"\"output\"",
"]",
"[",
"\"devices\"",
"]",
"for",
"device",
"in",
"devices",
":",
"macs",
"=",
"device",
"[",
"\"knownMACAddresses\"",
"]",
"if",
"not",
"macs",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Skipping device without known MAC address\"",
")",
"continue",
"mac",
"=",
"macs",
"[",
"-",
"1",
"]",
"connections",
"=",
"device",
"[",
"\"connections\"",
"]",
"if",
"not",
"connections",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Device %s is not connected\"",
",",
"mac",
")",
"continue",
"name",
"=",
"None",
"for",
"prop",
"in",
"device",
"[",
"\"properties\"",
"]",
":",
"if",
"prop",
"[",
"\"name\"",
"]",
"==",
"\"userDeviceName\"",
":",
"name",
"=",
"prop",
"[",
"\"value\"",
"]",
"if",
"not",
"name",
":",
"name",
"=",
"device",
".",
"get",
"(",
"\"friendlyName\"",
",",
"device",
"[",
"\"deviceID\"",
"]",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Device %s is connected\"",
",",
"mac",
")",
"self",
".",
"last_results",
"[",
"mac",
"]",
"=",
"name",
"except",
"(",
"KeyError",
",",
"IndexError",
")",
":",
"_LOGGER",
".",
"exception",
"(",
"\"Router returned unexpected response\"",
")",
"return",
"False",
"return",
"True"
] | [
52,
4
] | [
90,
19
] | python | en | ['en', 'en', 'en'] | True |
test_run_camera_setup | (hass, aiohttp_client, mqtt_mock) | Test that it fetches the given payload. | Test that it fetches the given payload. | async def test_run_camera_setup(hass, aiohttp_client, mqtt_mock):
"""Test that it fetches the given payload."""
topic = "test/camera"
await async_setup_component(
hass,
"camera",
{"camera": {"platform": "mqtt", "topic": topic, "name": "Test Camera"}},
)
await hass.async_block_till_done()
url = hass.states.get("camera.test_camera").attributes["entity_picture"]
async_fire_mqtt_message(hass, topic, "beer")
client = await aiohttp_client(hass.http.app)
resp = await client.get(url)
assert resp.status == 200
body = await resp.text()
assert body == "beer" | [
"async",
"def",
"test_run_camera_setup",
"(",
"hass",
",",
"aiohttp_client",
",",
"mqtt_mock",
")",
":",
"topic",
"=",
"\"test/camera\"",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"camera\"",
",",
"{",
"\"camera\"",
":",
"{",
"\"platform\"",
":",
"\"mqtt\"",
",",
"\"topic\"",
":",
"topic",
",",
"\"name\"",
":",
"\"Test Camera\"",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"url",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"camera.test_camera\"",
")",
".",
"attributes",
"[",
"\"entity_picture\"",
"]",
"async_fire_mqtt_message",
"(",
"hass",
",",
"topic",
",",
"\"beer\"",
")",
"client",
"=",
"await",
"aiohttp_client",
"(",
"hass",
".",
"http",
".",
"app",
")",
"resp",
"=",
"await",
"client",
".",
"get",
"(",
"url",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"body",
"=",
"await",
"resp",
".",
"text",
"(",
")",
"assert",
"body",
"==",
"\"beer\""
] | [
40,
0
] | [
58,
25
] | python | en | ['en', 'en', 'en'] | True |
test_availability_when_connection_lost | (hass, mqtt_mock) | Test availability after MQTT disconnection. | Test availability after MQTT disconnection. | async def test_availability_when_connection_lost(hass, mqtt_mock):
"""Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost(
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_availability_when_connection_lost",
"(",
"hass",
",",
"mqtt_mock",
")",
":",
"await",
"help_test_availability_when_connection_lost",
"(",
"hass",
",",
"mqtt_mock",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
61,
0
] | [
65,
5
] | python | en | ['en', 'en', 'en'] | True |
test_availability_without_topic | (hass, mqtt_mock) | Test availability without defined availability topic. | Test availability without defined availability topic. | async def test_availability_without_topic(hass, mqtt_mock):
"""Test availability without defined availability topic."""
await help_test_availability_without_topic(
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_availability_without_topic",
"(",
"hass",
",",
"mqtt_mock",
")",
":",
"await",
"help_test_availability_without_topic",
"(",
"hass",
",",
"mqtt_mock",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
68,
0
] | [
72,
5
] | python | en | ['en', 'en', 'en'] | True |
test_default_availability_payload | (hass, mqtt_mock) | Test availability by default payload with defined topic. | Test availability by default payload with defined topic. | async def test_default_availability_payload(hass, mqtt_mock):
"""Test availability by default payload with defined topic."""
await help_test_default_availability_payload(
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_default_availability_payload",
"(",
"hass",
",",
"mqtt_mock",
")",
":",
"await",
"help_test_default_availability_payload",
"(",
"hass",
",",
"mqtt_mock",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
75,
0
] | [
79,
5
] | python | en | ['en', 'en', 'en'] | True |
test_custom_availability_payload | (hass, mqtt_mock) | Test availability by custom payload with defined topic. | Test availability by custom payload with defined topic. | async def test_custom_availability_payload(hass, mqtt_mock):
"""Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload(
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_custom_availability_payload",
"(",
"hass",
",",
"mqtt_mock",
")",
":",
"await",
"help_test_custom_availability_payload",
"(",
"hass",
",",
"mqtt_mock",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
82,
0
] | [
86,
5
] | python | en | ['en', 'en', 'en'] | True |
test_setting_attribute_via_mqtt_json_message | (hass, mqtt_mock) | Test the setting of attribute via MQTT with JSON payload. | Test the setting of attribute via MQTT with JSON payload. | async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_setting_attribute_via_mqtt_json_message",
"(",
"hass",
",",
"mqtt_mock",
")",
":",
"await",
"help_test_setting_attribute_via_mqtt_json_message",
"(",
"hass",
",",
"mqtt_mock",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
89,
0
] | [
93,
5
] | python | en | ['en', 'en', 'en'] | True |
test_setting_attribute_with_template | (hass, mqtt_mock) | Test the setting of attribute via MQTT with JSON payload. | Test the setting of attribute via MQTT with JSON payload. | async def test_setting_attribute_with_template(hass, mqtt_mock):
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template(
hass, mqtt_mock, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_setting_attribute_with_template",
"(",
"hass",
",",
"mqtt_mock",
")",
":",
"await",
"help_test_setting_attribute_with_template",
"(",
"hass",
",",
"mqtt_mock",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
96,
0
] | [
100,
5
] | python | en | ['en', 'en', 'en'] | True |
test_update_with_json_attrs_not_dict | (hass, mqtt_mock, caplog) | Test attributes get extracted from a JSON result. | Test attributes get extracted from a JSON result. | async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict(
hass, mqtt_mock, caplog, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_update_with_json_attrs_not_dict",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
")",
":",
"await",
"help_test_update_with_json_attrs_not_dict",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
103,
0
] | [
107,
5
] | python | en | ['en', 'en', 'en'] | True |
test_update_with_json_attrs_bad_JSON | (hass, mqtt_mock, caplog) | Test attributes get extracted from a JSON result. | Test attributes get extracted from a JSON result. | async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog):
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON(
hass, mqtt_mock, caplog, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_update_with_json_attrs_bad_JSON",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
")",
":",
"await",
"help_test_update_with_json_attrs_bad_JSON",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
110,
0
] | [
114,
5
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_update_attr | (hass, mqtt_mock, caplog) | Test update of discovered MQTTAttributes. | Test update of discovered MQTTAttributes. | async def test_discovery_update_attr(hass, mqtt_mock, caplog):
"""Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr(
hass, mqtt_mock, caplog, camera.DOMAIN, DEFAULT_CONFIG
) | [
"async",
"def",
"test_discovery_update_attr",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
")",
":",
"await",
"help_test_discovery_update_attr",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
",",
"camera",
".",
"DOMAIN",
",",
"DEFAULT_CONFIG",
")"
] | [
117,
0
] | [
121,
5
] | python | en | ['en', 'en', 'en'] | True |
test_unique_id | (hass, mqtt_mock) | Test unique id option only creates one camera per unique_id. | Test unique id option only creates one camera per unique_id. | async def test_unique_id(hass, mqtt_mock):
"""Test unique id option only creates one camera per unique_id."""
config = {
camera.DOMAIN: [
{
"platform": "mqtt",
"name": "Test 1",
"topic": "test-topic",
"unique_id": "TOTALLY_UNIQUE",
},
{
"platform": "mqtt",
"name": "Test 2",
"topic": "test-topic",
"unique_id": "TOTALLY_UNIQUE",
},
]
}
await help_test_unique_id(hass, mqtt_mock, camera.DOMAIN, config) | [
"async",
"def",
"test_unique_id",
"(",
"hass",
",",
"mqtt_mock",
")",
":",
"config",
"=",
"{",
"camera",
".",
"DOMAIN",
":",
"[",
"{",
"\"platform\"",
":",
"\"mqtt\"",
",",
"\"name\"",
":",
"\"Test 1\"",
",",
"\"topic\"",
":",
"\"test-topic\"",
",",
"\"unique_id\"",
":",
"\"TOTALLY_UNIQUE\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"mqtt\"",
",",
"\"name\"",
":",
"\"Test 2\"",
",",
"\"topic\"",
":",
"\"test-topic\"",
",",
"\"unique_id\"",
":",
"\"TOTALLY_UNIQUE\"",
",",
"}",
",",
"]",
"}",
"await",
"help_test_unique_id",
"(",
"hass",
",",
"mqtt_mock",
",",
"camera",
".",
"DOMAIN",
",",
"config",
")"
] | [
124,
0
] | [
142,
69
] | python | en | ['en', 'it', 'en'] | True |
test_discovery_removal_camera | (hass, mqtt_mock, caplog) | Test removal of discovered camera. | Test removal of discovered camera. | async def test_discovery_removal_camera(hass, mqtt_mock, caplog):
"""Test removal of discovered camera."""
data = json.dumps(DEFAULT_CONFIG[camera.DOMAIN])
await help_test_discovery_removal(hass, mqtt_mock, caplog, camera.DOMAIN, data) | [
"async",
"def",
"test_discovery_removal_camera",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
")",
":",
"data",
"=",
"json",
".",
"dumps",
"(",
"DEFAULT_CONFIG",
"[",
"camera",
".",
"DOMAIN",
"]",
")",
"await",
"help_test_discovery_removal",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
",",
"camera",
".",
"DOMAIN",
",",
"data",
")"
] | [
145,
0
] | [
148,
83
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_update_camera | (hass, mqtt_mock, caplog) | Test update of discovered camera. | Test update of discovered camera. | async def test_discovery_update_camera(hass, mqtt_mock, caplog):
"""Test update of discovered camera."""
data1 = '{ "name": "Beer", "topic": "test_topic"}'
data2 = '{ "name": "Milk", "topic": "test_topic"}'
await help_test_discovery_update(
hass, mqtt_mock, caplog, camera.DOMAIN, data1, data2
) | [
"async",
"def",
"test_discovery_update_camera",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
")",
":",
"data1",
"=",
"'{ \"name\": \"Beer\", \"topic\": \"test_topic\"}'",
"data2",
"=",
"'{ \"name\": \"Milk\", \"topic\": \"test_topic\"}'",
"await",
"help_test_discovery_update",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
",",
"camera",
".",
"DOMAIN",
",",
"data1",
",",
"data2",
")"
] | [
151,
0
] | [
158,
5
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_update_unchanged_camera | (hass, mqtt_mock, caplog) | Test update of discovered camera. | Test update of discovered camera. | async def test_discovery_update_unchanged_camera(hass, mqtt_mock, caplog):
"""Test update of discovered camera."""
data1 = '{ "name": "Beer", "topic": "test_topic"}'
with patch(
"homeassistant.components.mqtt.camera.MqttCamera.discovery_update"
) as discovery_update:
await help_test_discovery_update_unchanged(
hass, mqtt_mock, caplog, camera.DOMAIN, data1, discovery_update
) | [
"async",
"def",
"test_discovery_update_unchanged_camera",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
")",
":",
"data1",
"=",
"'{ \"name\": \"Beer\", \"topic\": \"test_topic\"}'",
"with",
"patch",
"(",
"\"homeassistant.components.mqtt.camera.MqttCamera.discovery_update\"",
")",
"as",
"discovery_update",
":",
"await",
"help_test_discovery_update_unchanged",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
",",
"camera",
".",
"DOMAIN",
",",
"data1",
",",
"discovery_update",
")"
] | [
161,
0
] | [
169,
9
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_broken | (hass, mqtt_mock, caplog) | Test handling of bad discovery message. | Test handling of bad discovery message. | async def test_discovery_broken(hass, mqtt_mock, caplog):
"""Test handling of bad discovery message."""
data1 = '{ "name": "Beer" }'
data2 = '{ "name": "Milk", "topic": "test_topic"}'
await help_test_discovery_broken(
hass, mqtt_mock, caplog, camera.DOMAIN, data1, data2
) | [
"async",
"def",
"test_discovery_broken",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
")",
":",
"data1",
"=",
"'{ \"name\": \"Beer\" }'",
"data2",
"=",
"'{ \"name\": \"Milk\", \"topic\": \"test_topic\"}'",
"await",
"help_test_discovery_broken",
"(",
"hass",
",",
"mqtt_mock",
",",
"caplog",
",",
"camera",
".",
"DOMAIN",
",",
"data1",
",",
"data2",
")"
] | [
173,
0
] | [
180,
5
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.