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
SpcBinarySensor.device_class
(self)
Return the device class.
Return the device class.
def device_class(self): """Return the device class.""" return _get_device_class(self._zone.type)
[ "def", "device_class", "(", "self", ")", ":", "return", "_get_device_class", "(", "self", ".", "_zone", ".", "type", ")" ]
[ 76, 4 ]
[ 78, 49 ]
python
en
['en', 'en', 'en']
True
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up the LG webOS Smart TV platform.
Set up the LG webOS Smart TV platform.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the LG webOS Smart TV platform.""" if discovery_info is None: return host = discovery_info[CONF_HOST] name = discovery_info[CONF_NAME] customize = discovery_info[CONF_CUSTOMIZE] turn_on_action = discovery_info.get(CONF_ON_ACTION) client = hass.data[DOMAIN][host]["client"] on_script = Script(hass, turn_on_action, name, DOMAIN) if turn_on_action else None entity = LgWebOSMediaPlayerEntity(client, name, customize, on_script) async_add_entities([entity], update_before_add=False)
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "discovery_info", "is", "None", ":", "return", "host", "=", "discovery_info", "[", "CONF_HOST", "]", "name", "=", "discovery_info", "[", "CONF_NAME", "]", "customize", "=", "discovery_info", "[", "CONF_CUSTOMIZE", "]", "turn_on_action", "=", "discovery_info", ".", "get", "(", "CONF_ON_ACTION", ")", "client", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "host", "]", "[", "\"client\"", "]", "on_script", "=", "Script", "(", "hass", ",", "turn_on_action", ",", "name", ",", "DOMAIN", ")", "if", "turn_on_action", "else", "None", "entity", "=", "LgWebOSMediaPlayerEntity", "(", "client", ",", "name", ",", "customize", ",", "on_script", ")", "async_add_entities", "(", "[", "entity", "]", ",", "update_before_add", "=", "False", ")" ]
[ 65, 0 ]
[ 81, 57 ]
python
en
['en', 'da', 'en']
True
cmd
(func)
Catch command exceptions.
Catch command exceptions.
def cmd(func): """Catch command exceptions.""" @wraps(func) async def wrapper(obj, *args, **kwargs): """Wrap all command methods.""" try: await func(obj, *args, **kwargs) except ( asyncio.TimeoutError, asyncio.CancelledError, PyLGTVCmdException, ) as exc: # If TV is off, we expect calls to fail. if obj.state == STATE_OFF: level = logging.INFO else: level = logging.ERROR _LOGGER.log( level, "Error calling %s on entity %s: %r", func.__name__, obj.entity_id, exc, ) return wrapper
[ "def", "cmd", "(", "func", ")", ":", "@", "wraps", "(", "func", ")", "async", "def", "wrapper", "(", "obj", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "\"\"\"Wrap all command methods.\"\"\"", "try", ":", "await", "func", "(", "obj", ",", "*", "args", ",", "*", "*", "kwargs", ")", "except", "(", "asyncio", ".", "TimeoutError", ",", "asyncio", ".", "CancelledError", ",", "PyLGTVCmdException", ",", ")", "as", "exc", ":", "# If TV is off, we expect calls to fail.", "if", "obj", ".", "state", "==", "STATE_OFF", ":", "level", "=", "logging", ".", "INFO", "else", ":", "level", "=", "logging", ".", "ERROR", "_LOGGER", ".", "log", "(", "level", ",", "\"Error calling %s on entity %s: %r\"", ",", "func", ".", "__name__", ",", "obj", ".", "entity_id", ",", "exc", ",", ")", "return", "wrapper" ]
[ 84, 0 ]
[ 110, 18 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.__init__
(self, client: WebOsClient, name: str, customize, on_script=None)
Initialize the webos device.
Initialize the webos device.
def __init__(self, client: WebOsClient, name: str, customize, on_script=None): """Initialize the webos device.""" self._client = client self._name = name self._unique_id = client.client_key self._customize = customize self._on_script = on_script # Assume that the TV is not paused self._paused = False self._current_source = None self._source_list = {}
[ "def", "__init__", "(", "self", ",", "client", ":", "WebOsClient", ",", "name", ":", "str", ",", "customize", ",", "on_script", "=", "None", ")", ":", "self", ".", "_client", "=", "client", "self", ".", "_name", "=", "name", "self", ".", "_unique_id", "=", "client", ".", "client_key", "self", ".", "_customize", "=", "customize", "self", ".", "_on_script", "=", "on_script", "# Assume that the TV is not paused", "self", ".", "_paused", "=", "False", "self", ".", "_current_source", "=", "None", "self", ".", "_source_list", "=", "{", "}" ]
[ 116, 4 ]
[ 128, 30 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_added_to_hass
(self)
Connect and subscribe to dispatcher signals and state updates.
Connect and subscribe to dispatcher signals and state updates.
async def async_added_to_hass(self): """Connect and subscribe to dispatcher signals and state updates.""" async_dispatcher_connect(self.hass, DOMAIN, self.async_signal_handler) await self._client.register_state_update_callback( self.async_handle_state_update )
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "DOMAIN", ",", "self", ".", "async_signal_handler", ")", "await", "self", ".", "_client", ".", "register_state_update_callback", "(", "self", ".", "async_handle_state_update", ")" ]
[ 130, 4 ]
[ 136, 9 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_will_remove_from_hass
(self)
Call disconnect on removal.
Call disconnect on removal.
async def async_will_remove_from_hass(self): """Call disconnect on removal.""" self._client.unregister_state_update_callback(self.async_handle_state_update)
[ "async", "def", "async_will_remove_from_hass", "(", "self", ")", ":", "self", ".", "_client", ".", "unregister_state_update_callback", "(", "self", ".", "async_handle_state_update", ")" ]
[ 138, 4 ]
[ 140, 85 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_signal_handler
(self, data)
Handle domain-specific signal by calling appropriate method.
Handle domain-specific signal by calling appropriate method.
async def async_signal_handler(self, data): """Handle domain-specific signal by calling appropriate method.""" entity_ids = data[ATTR_ENTITY_ID] if entity_ids == ENTITY_MATCH_NONE: return if entity_ids == ENTITY_MATCH_ALL or self.entity_id in entity_ids: params = { key: value for key, value in data.items() if key not in ["entity_id", "method"] } await getattr(self, data["method"])(**params)
[ "async", "def", "async_signal_handler", "(", "self", ",", "data", ")", ":", "entity_ids", "=", "data", "[", "ATTR_ENTITY_ID", "]", "if", "entity_ids", "==", "ENTITY_MATCH_NONE", ":", "return", "if", "entity_ids", "==", "ENTITY_MATCH_ALL", "or", "self", ".", "entity_id", "in", "entity_ids", ":", "params", "=", "{", "key", ":", "value", "for", "key", ",", "value", "in", "data", ".", "items", "(", ")", "if", "key", "not", "in", "[", "\"entity_id\"", ",", "\"method\"", "]", "}", "await", "getattr", "(", "self", ",", "data", "[", "\"method\"", "]", ")", "(", "*", "*", "params", ")" ]
[ 142, 4 ]
[ 154, 57 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_handle_state_update
(self)
Update state from WebOsClient.
Update state from WebOsClient.
async def async_handle_state_update(self): """Update state from WebOsClient.""" self.update_sources() self.async_write_ha_state()
[ "async", "def", "async_handle_state_update", "(", "self", ")", ":", "self", ".", "update_sources", "(", ")", "self", ".", "async_write_ha_state", "(", ")" ]
[ 156, 4 ]
[ 160, 35 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.update_sources
(self)
Update list of sources from current source, apps, inputs and configured list.
Update list of sources from current source, apps, inputs and configured list.
def update_sources(self): """Update list of sources from current source, apps, inputs and configured list.""" source_list = self._source_list self._source_list = {} conf_sources = self._customize[CONF_SOURCES] found_live_tv = False for app in self._client.apps.values(): if app["id"] == LIVE_TV_APP_ID: found_live_tv = True if app["id"] == self._client.current_appId: self._current_source = app["title"] self._source_list[app["title"]] = app elif ( not conf_sources or app["id"] in conf_sources or any(word in app["title"] for word in conf_sources) or any(word in app["id"] for word in conf_sources) ): self._source_list[app["title"]] = app for source in self._client.inputs.values(): if source["appId"] == LIVE_TV_APP_ID: found_live_tv = True if source["appId"] == self._client.current_appId: self._current_source = source["label"] self._source_list[source["label"]] = source elif ( not conf_sources or source["label"] in conf_sources or any(source["label"].find(word) != -1 for word in conf_sources) ): self._source_list[source["label"]] = source # special handling of live tv since this might not appear in the app or input lists in some cases if not found_live_tv: app = {"id": LIVE_TV_APP_ID, "title": "Live TV"} if LIVE_TV_APP_ID == self._client.current_appId: self._current_source = app["title"] self._source_list["Live TV"] = app elif ( not conf_sources or app["id"] in conf_sources or any(word in app["title"] for word in conf_sources) or any(word in app["id"] for word in conf_sources) ): self._source_list["Live TV"] = app if not self._source_list and source_list: self._source_list = source_list
[ "def", "update_sources", "(", "self", ")", ":", "source_list", "=", "self", ".", "_source_list", "self", ".", "_source_list", "=", "{", "}", "conf_sources", "=", "self", ".", "_customize", "[", "CONF_SOURCES", "]", "found_live_tv", "=", "False", "for", "app", "in", "self", ".", "_client", ".", "apps", ".", "values", "(", ")", ":", "if", "app", "[", "\"id\"", "]", "==", "LIVE_TV_APP_ID", ":", "found_live_tv", "=", "True", "if", "app", "[", "\"id\"", "]", "==", "self", ".", "_client", ".", "current_appId", ":", "self", ".", "_current_source", "=", "app", "[", "\"title\"", "]", "self", ".", "_source_list", "[", "app", "[", "\"title\"", "]", "]", "=", "app", "elif", "(", "not", "conf_sources", "or", "app", "[", "\"id\"", "]", "in", "conf_sources", "or", "any", "(", "word", "in", "app", "[", "\"title\"", "]", "for", "word", "in", "conf_sources", ")", "or", "any", "(", "word", "in", "app", "[", "\"id\"", "]", "for", "word", "in", "conf_sources", ")", ")", ":", "self", ".", "_source_list", "[", "app", "[", "\"title\"", "]", "]", "=", "app", "for", "source", "in", "self", ".", "_client", ".", "inputs", ".", "values", "(", ")", ":", "if", "source", "[", "\"appId\"", "]", "==", "LIVE_TV_APP_ID", ":", "found_live_tv", "=", "True", "if", "source", "[", "\"appId\"", "]", "==", "self", ".", "_client", ".", "current_appId", ":", "self", ".", "_current_source", "=", "source", "[", "\"label\"", "]", "self", ".", "_source_list", "[", "source", "[", "\"label\"", "]", "]", "=", "source", "elif", "(", "not", "conf_sources", "or", "source", "[", "\"label\"", "]", "in", "conf_sources", "or", "any", "(", "source", "[", "\"label\"", "]", ".", "find", "(", "word", ")", "!=", "-", "1", "for", "word", "in", "conf_sources", ")", ")", ":", "self", ".", "_source_list", "[", "source", "[", "\"label\"", "]", "]", "=", "source", "# special handling of live tv since this might not appear in the app or input lists in some cases", "if", "not", "found_live_tv", ":", "app", "=", "{", "\"id\"", ":", "LIVE_TV_APP_ID", ",", "\"title\"", ":", "\"Live TV\"", "}", "if", "LIVE_TV_APP_ID", "==", "self", ".", "_client", ".", "current_appId", ":", "self", ".", "_current_source", "=", "app", "[", "\"title\"", "]", "self", ".", "_source_list", "[", "\"Live TV\"", "]", "=", "app", "elif", "(", "not", "conf_sources", "or", "app", "[", "\"id\"", "]", "in", "conf_sources", "or", "any", "(", "word", "in", "app", "[", "\"title\"", "]", "for", "word", "in", "conf_sources", ")", "or", "any", "(", "word", "in", "app", "[", "\"id\"", "]", "for", "word", "in", "conf_sources", ")", ")", ":", "self", ".", "_source_list", "[", "\"Live TV\"", "]", "=", "app", "if", "not", "self", ".", "_source_list", "and", "source_list", ":", "self", ".", "_source_list", "=", "source_list" ]
[ 162, 4 ]
[ 210, 43 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.unique_id
(self)
Return the unique id of the device.
Return the unique id of the device.
def unique_id(self): """Return the unique id of the device.""" return self._unique_id
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_unique_id" ]
[ 230, 4 ]
[ 232, 30 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.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" ]
[ 235, 4 ]
[ 237, 25 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.device_class
(self)
Return the device class of the device.
Return the device class of the device.
def device_class(self): """Return the device class of the device.""" return DEVICE_CLASS_TV
[ "def", "device_class", "(", "self", ")", ":", "return", "DEVICE_CLASS_TV" ]
[ 240, 4 ]
[ 242, 30 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.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._client.is_on: return STATE_ON return STATE_OFF
[ "def", "state", "(", "self", ")", ":", "if", "self", ".", "_client", ".", "is_on", ":", "return", "STATE_ON", "return", "STATE_OFF" ]
[ 245, 4 ]
[ 250, 24 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.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._client.muted
[ "def", "is_volume_muted", "(", "self", ")", ":", "return", "self", ".", "_client", ".", "muted" ]
[ 253, 4 ]
[ 255, 33 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.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).""" if self._client.volume is not None: return self._client.volume / 100.0 return None
[ "def", "volume_level", "(", "self", ")", ":", "if", "self", ".", "_client", ".", "volume", "is", "not", "None", ":", "return", "self", ".", "_client", ".", "volume", "/", "100.0", "return", "None" ]
[ 258, 4 ]
[ 263, 19 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.source
(self)
Return the current input source.
Return the current input source.
def source(self): """Return the current input source.""" return self._current_source
[ "def", "source", "(", "self", ")", ":", "return", "self", ".", "_current_source" ]
[ 266, 4 ]
[ 268, 35 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.source_list
(self)
List of available input sources.
List of available input sources.
def source_list(self): """List of available input sources.""" return sorted(list(self._source_list))
[ "def", "source_list", "(", "self", ")", ":", "return", "sorted", "(", "list", "(", "self", ".", "_source_list", ")", ")" ]
[ 271, 4 ]
[ 273, 46 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.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.""" if self._client.current_appId == LIVE_TV_APP_ID: return MEDIA_TYPE_CHANNEL return None
[ "def", "media_content_type", "(", "self", ")", ":", "if", "self", ".", "_client", ".", "current_appId", "==", "LIVE_TV_APP_ID", ":", "return", "MEDIA_TYPE_CHANNEL", "return", "None" ]
[ 276, 4 ]
[ 281, 19 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.media_title
(self)
Title of current playing media.
Title of current playing media.
def media_title(self): """Title of current playing media.""" if (self._client.current_appId == LIVE_TV_APP_ID) and ( self._client.current_channel is not None ): return self._client.current_channel.get("channelName") return None
[ "def", "media_title", "(", "self", ")", ":", "if", "(", "self", ".", "_client", ".", "current_appId", "==", "LIVE_TV_APP_ID", ")", "and", "(", "self", ".", "_client", ".", "current_channel", "is", "not", "None", ")", ":", "return", "self", ".", "_client", ".", "current_channel", ".", "get", "(", "\"channelName\"", ")", "return", "None" ]
[ 284, 4 ]
[ 290, 19 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.media_image_url
(self)
Image url of current playing media.
Image url of current playing media.
def media_image_url(self): """Image url of current playing media.""" if self._client.current_appId in self._client.apps: icon = self._client.apps[self._client.current_appId]["largeIcon"] if not icon.startswith("http"): icon = self._client.apps[self._client.current_appId]["icon"] return icon return None
[ "def", "media_image_url", "(", "self", ")", ":", "if", "self", ".", "_client", ".", "current_appId", "in", "self", ".", "_client", ".", "apps", ":", "icon", "=", "self", ".", "_client", ".", "apps", "[", "self", ".", "_client", ".", "current_appId", "]", "[", "\"largeIcon\"", "]", "if", "not", "icon", ".", "startswith", "(", "\"http\"", ")", ":", "icon", "=", "self", ".", "_client", ".", "apps", "[", "self", ".", "_client", ".", "current_appId", "]", "[", "\"icon\"", "]", "return", "icon", "return", "None" ]
[ 293, 4 ]
[ 300, 19 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.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.""" supported = SUPPORT_WEBOSTV if (self._client.sound_output == "external_arc") or ( self._client.sound_output == "external_speaker" ): supported = supported | SUPPORT_WEBOSTV_VOLUME elif self._client.sound_output != "lineout": supported = supported | SUPPORT_WEBOSTV_VOLUME | SUPPORT_VOLUME_SET if self._on_script: supported = supported | SUPPORT_TURN_ON return supported
[ "def", "supported_features", "(", "self", ")", ":", "supported", "=", "SUPPORT_WEBOSTV", "if", "(", "self", ".", "_client", ".", "sound_output", "==", "\"external_arc\"", ")", "or", "(", "self", ".", "_client", ".", "sound_output", "==", "\"external_speaker\"", ")", ":", "supported", "=", "supported", "|", "SUPPORT_WEBOSTV_VOLUME", "elif", "self", ".", "_client", ".", "sound_output", "!=", "\"lineout\"", ":", "supported", "=", "supported", "|", "SUPPORT_WEBOSTV_VOLUME", "|", "SUPPORT_VOLUME_SET", "if", "self", ".", "_on_script", ":", "supported", "=", "supported", "|", "SUPPORT_TURN_ON", "return", "supported" ]
[ 303, 4 ]
[ 317, 24 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.device_state_attributes
(self)
Return device specific state attributes.
Return device specific state attributes.
def device_state_attributes(self): """Return device specific state attributes.""" if self._client.sound_output is None and self.state == STATE_OFF: return {} return {ATTR_SOUND_OUTPUT: self._client.sound_output}
[ "def", "device_state_attributes", "(", "self", ")", ":", "if", "self", ".", "_client", ".", "sound_output", "is", "None", "and", "self", ".", "state", "==", "STATE_OFF", ":", "return", "{", "}", "return", "{", "ATTR_SOUND_OUTPUT", ":", "self", ".", "_client", ".", "sound_output", "}" ]
[ 320, 4 ]
[ 324, 61 ]
python
en
['fr', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_turn_off
(self)
Turn off media player.
Turn off media player.
async def async_turn_off(self): """Turn off media player.""" await self._client.power_off()
[ "async", "def", "async_turn_off", "(", "self", ")", ":", "await", "self", ".", "_client", ".", "power_off", "(", ")" ]
[ 327, 4 ]
[ 329, 38 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_turn_on
(self)
Turn on the media player.
Turn on the media player.
async def async_turn_on(self): """Turn on the media player.""" if self._on_script: await self._on_script.async_run(context=self._context)
[ "async", "def", "async_turn_on", "(", "self", ")", ":", "if", "self", ".", "_on_script", ":", "await", "self", ".", "_on_script", ".", "async_run", "(", "context", "=", "self", ".", "_context", ")" ]
[ 331, 4 ]
[ 334, 66 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_volume_up
(self)
Volume up the media player.
Volume up the media player.
async def async_volume_up(self): """Volume up the media player.""" await self._client.volume_up()
[ "async", "def", "async_volume_up", "(", "self", ")", ":", "await", "self", ".", "_client", ".", "volume_up", "(", ")" ]
[ 337, 4 ]
[ 339, 38 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_volume_down
(self)
Volume down media player.
Volume down media player.
async def async_volume_down(self): """Volume down media player.""" await self._client.volume_down()
[ "async", "def", "async_volume_down", "(", "self", ")", ":", "await", "self", ".", "_client", ".", "volume_down", "(", ")" ]
[ 342, 4 ]
[ 344, 40 ]
python
en
['en', 'sl', 'en']
True
LgWebOSMediaPlayerEntity.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.""" tv_volume = int(round(volume * 100)) await self._client.set_volume(tv_volume)
[ "async", "def", "async_set_volume_level", "(", "self", ",", "volume", ")", ":", "tv_volume", "=", "int", "(", "round", "(", "volume", "*", "100", ")", ")", "await", "self", ".", "_client", ".", "set_volume", "(", "tv_volume", ")" ]
[ 347, 4 ]
[ 350, 48 ]
python
en
['fr', 'zu', 'en']
False
LgWebOSMediaPlayerEntity.async_mute_volume
(self, mute)
Send mute command.
Send mute command.
async def async_mute_volume(self, mute): """Send mute command.""" await self._client.set_mute(mute)
[ "async", "def", "async_mute_volume", "(", "self", ",", "mute", ")", ":", "await", "self", ".", "_client", ".", "set_mute", "(", "mute", ")" ]
[ 353, 4 ]
[ 355, 41 ]
python
en
['en', 'co', 'en']
True
LgWebOSMediaPlayerEntity.async_select_sound_output
(self, sound_output)
Select the sound output.
Select the sound output.
async def async_select_sound_output(self, sound_output): """Select the sound output.""" await self._client.change_sound_output(sound_output)
[ "async", "def", "async_select_sound_output", "(", "self", ",", "sound_output", ")", ":", "await", "self", ".", "_client", ".", "change_sound_output", "(", "sound_output", ")" ]
[ 358, 4 ]
[ 360, 60 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_media_play_pause
(self)
Simulate play pause media player.
Simulate play pause media player.
async def async_media_play_pause(self): """Simulate play pause media player.""" if self._paused: await self.async_media_play() else: await self.async_media_pause()
[ "async", "def", "async_media_play_pause", "(", "self", ")", ":", "if", "self", ".", "_paused", ":", "await", "self", ".", "async_media_play", "(", ")", "else", ":", "await", "self", ".", "async_media_pause", "(", ")" ]
[ 363, 4 ]
[ 368, 42 ]
python
en
['en', 'en', 'it']
True
LgWebOSMediaPlayerEntity.async_select_source
(self, source)
Select input source.
Select input source.
async def async_select_source(self, source): """Select input source.""" source_dict = self._source_list.get(source) if source_dict is None: _LOGGER.warning("Source %s not found for %s", source, self.name) return if source_dict.get("title"): await self._client.launch_app(source_dict["id"]) elif source_dict.get("label"): await self._client.set_input(source_dict["id"])
[ "async", "def", "async_select_source", "(", "self", ",", "source", ")", ":", "source_dict", "=", "self", ".", "_source_list", ".", "get", "(", "source", ")", "if", "source_dict", "is", "None", ":", "_LOGGER", ".", "warning", "(", "\"Source %s not found for %s\"", ",", "source", ",", "self", ".", "name", ")", "return", "if", "source_dict", ".", "get", "(", "\"title\"", ")", ":", "await", "self", ".", "_client", ".", "launch_app", "(", "source_dict", "[", "\"id\"", "]", ")", "elif", "source_dict", ".", "get", "(", "\"label\"", ")", ":", "await", "self", ".", "_client", ".", "set_input", "(", "source_dict", "[", "\"id\"", "]", ")" ]
[ 371, 4 ]
[ 380, 59 ]
python
en
['fr', 'su', 'en']
False
LgWebOSMediaPlayerEntity.async_play_media
(self, media_type, media_id, **kwargs)
Play a piece of media.
Play a piece of media.
async def async_play_media(self, media_type, media_id, **kwargs): """Play a piece of media.""" _LOGGER.debug("Call play media type <%s>, Id <%s>", media_type, media_id) if media_type == MEDIA_TYPE_CHANNEL: _LOGGER.debug("Searching channel...") partial_match_channel_id = None perfect_match_channel_id = None for channel in self._client.channels: if media_id == channel["channelNumber"]: perfect_match_channel_id = channel["channelId"] continue if media_id.lower() == channel["channelName"].lower(): perfect_match_channel_id = channel["channelId"] continue if media_id.lower() in channel["channelName"].lower(): partial_match_channel_id = channel["channelId"] if perfect_match_channel_id is not None: _LOGGER.info( "Switching to channel <%s> with perfect match", perfect_match_channel_id, ) await self._client.set_channel(perfect_match_channel_id) elif partial_match_channel_id is not None: _LOGGER.info( "Switching to channel <%s> with partial match", partial_match_channel_id, ) await self._client.set_channel(partial_match_channel_id)
[ "async", "def", "async_play_media", "(", "self", ",", "media_type", ",", "media_id", ",", "*", "*", "kwargs", ")", ":", "_LOGGER", ".", "debug", "(", "\"Call play media type <%s>, Id <%s>\"", ",", "media_type", ",", "media_id", ")", "if", "media_type", "==", "MEDIA_TYPE_CHANNEL", ":", "_LOGGER", ".", "debug", "(", "\"Searching channel...\"", ")", "partial_match_channel_id", "=", "None", "perfect_match_channel_id", "=", "None", "for", "channel", "in", "self", ".", "_client", ".", "channels", ":", "if", "media_id", "==", "channel", "[", "\"channelNumber\"", "]", ":", "perfect_match_channel_id", "=", "channel", "[", "\"channelId\"", "]", "continue", "if", "media_id", ".", "lower", "(", ")", "==", "channel", "[", "\"channelName\"", "]", ".", "lower", "(", ")", ":", "perfect_match_channel_id", "=", "channel", "[", "\"channelId\"", "]", "continue", "if", "media_id", ".", "lower", "(", ")", "in", "channel", "[", "\"channelName\"", "]", ".", "lower", "(", ")", ":", "partial_match_channel_id", "=", "channel", "[", "\"channelId\"", "]", "if", "perfect_match_channel_id", "is", "not", "None", ":", "_LOGGER", ".", "info", "(", "\"Switching to channel <%s> with perfect match\"", ",", "perfect_match_channel_id", ",", ")", "await", "self", ".", "_client", ".", "set_channel", "(", "perfect_match_channel_id", ")", "elif", "partial_match_channel_id", "is", "not", "None", ":", "_LOGGER", ".", "info", "(", "\"Switching to channel <%s> with partial match\"", ",", "partial_match_channel_id", ",", ")", "await", "self", ".", "_client", ".", "set_channel", "(", "partial_match_channel_id", ")" ]
[ 383, 4 ]
[ 415, 72 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_media_play
(self)
Send play command.
Send play command.
async def async_media_play(self): """Send play command.""" self._paused = False await self._client.play()
[ "async", "def", "async_media_play", "(", "self", ")", ":", "self", ".", "_paused", "=", "False", "await", "self", ".", "_client", ".", "play", "(", ")" ]
[ 418, 4 ]
[ 421, 33 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_media_pause
(self)
Send media pause command to media player.
Send media pause command to media player.
async def async_media_pause(self): """Send media pause command to media player.""" self._paused = True await self._client.pause()
[ "async", "def", "async_media_pause", "(", "self", ")", ":", "self", ".", "_paused", "=", "True", "await", "self", ".", "_client", ".", "pause", "(", ")" ]
[ 424, 4 ]
[ 427, 34 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_media_stop
(self)
Send stop command to media player.
Send stop command to media player.
async def async_media_stop(self): """Send stop command to media player.""" await self._client.stop()
[ "async", "def", "async_media_stop", "(", "self", ")", ":", "await", "self", ".", "_client", ".", "stop", "(", ")" ]
[ 430, 4 ]
[ 432, 33 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_media_next_track
(self)
Send next track command.
Send next track command.
async def async_media_next_track(self): """Send next track command.""" current_input = self._client.get_input() if current_input == LIVE_TV_APP_ID: await self._client.channel_up() else: await self._client.fast_forward()
[ "async", "def", "async_media_next_track", "(", "self", ")", ":", "current_input", "=", "self", ".", "_client", ".", "get_input", "(", ")", "if", "current_input", "==", "LIVE_TV_APP_ID", ":", "await", "self", ".", "_client", ".", "channel_up", "(", ")", "else", ":", "await", "self", ".", "_client", ".", "fast_forward", "(", ")" ]
[ 435, 4 ]
[ 441, 45 ]
python
en
['en', 'pt', 'en']
True
LgWebOSMediaPlayerEntity.async_media_previous_track
(self)
Send the previous track command.
Send the previous track command.
async def async_media_previous_track(self): """Send the previous track command.""" current_input = self._client.get_input() if current_input == LIVE_TV_APP_ID: await self._client.channel_down() else: await self._client.rewind()
[ "async", "def", "async_media_previous_track", "(", "self", ")", ":", "current_input", "=", "self", ".", "_client", ".", "get_input", "(", ")", "if", "current_input", "==", "LIVE_TV_APP_ID", ":", "await", "self", ".", "_client", ".", "channel_down", "(", ")", "else", ":", "await", "self", ".", "_client", ".", "rewind", "(", ")" ]
[ 444, 4 ]
[ 450, 39 ]
python
en
['en', 'en', 'en']
True
LgWebOSMediaPlayerEntity.async_button
(self, button)
Send a button press.
Send a button press.
async def async_button(self, button): """Send a button press.""" await self._client.button(button)
[ "async", "def", "async_button", "(", "self", ",", "button", ")", ":", "await", "self", ".", "_client", ".", "button", "(", "button", ")" ]
[ 453, 4 ]
[ 455, 41 ]
python
en
['en', 'ht', 'en']
True
LgWebOSMediaPlayerEntity.async_command
(self, command, **kwargs)
Send a command.
Send a command.
async def async_command(self, command, **kwargs): """Send a command.""" await self._client.request(command, payload=kwargs.get(ATTR_PAYLOAD))
[ "async", "def", "async_command", "(", "self", ",", "command", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "_client", ".", "request", "(", "command", ",", "payload", "=", "kwargs", ".", "get", "(", "ATTR_PAYLOAD", ")", ")" ]
[ 458, 4 ]
[ 460, 77 ]
python
en
['en', 'en', 'en']
True
GumbelVectorQuantizer.__init__
(self, dim, num_vars, min_temperature, max_temperature, temperature_decay, num_groups, vq_dim)
Vector quantization using gumbel softmax Args: dim: input dimension (channels) num_vars: number of quantized vectors per group temperature: temperature for training. this should be a tuple of 3 elements: (start, stop, decay factor) groups: number of groups for vector quantization vq_dim: dimensionality of the resulting quantized vector
Vector quantization using gumbel softmax
def __init__(self, dim, num_vars, min_temperature, max_temperature, temperature_decay, num_groups, vq_dim): """Vector quantization using gumbel softmax Args: dim: input dimension (channels) num_vars: number of quantized vectors per group temperature: temperature for training. this should be a tuple of 3 elements: (start, stop, decay factor) groups: number of groups for vector quantization vq_dim: dimensionality of the resulting quantized vector """ super().__init__() self.num_groups = num_groups self.input_dim = dim self.num_vars = num_vars assert vq_dim % num_groups == 0, f"dim {vq_dim} must be divisible by groups {num_groups} for concatenation" # per var var_dim = vq_dim // num_groups # vars count is the groups by the number of vars per group self.vars = nn.Parameter(torch.FloatTensor(1, num_groups * num_vars, var_dim)) nn.init.uniform_(self.vars) # projection self.weight_proj = nn.Linear(self.input_dim, num_groups * num_vars) nn.init.normal_(self.weight_proj.weight, mean=0, std=1) nn.init.zeros_(self.weight_proj.bias) self.max_temperature = max_temperature self.min_temperature = min_temperature self.temperature_decay = temperature_decay self.curr_temperature = self.max_temperature self.codebook_indices = None
[ "def", "__init__", "(", "self", ",", "dim", ",", "num_vars", ",", "min_temperature", ",", "max_temperature", ",", "temperature_decay", ",", "num_groups", ",", "vq_dim", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "num_groups", "=", "num_groups", "self", ".", "input_dim", "=", "dim", "self", ".", "num_vars", "=", "num_vars", "assert", "vq_dim", "%", "num_groups", "==", "0", ",", "f\"dim {vq_dim} must be divisible by groups {num_groups} for concatenation\"", "# per var", "var_dim", "=", "vq_dim", "//", "num_groups", "# vars count is the groups by the number of vars per group", "self", ".", "vars", "=", "nn", ".", "Parameter", "(", "torch", ".", "FloatTensor", "(", "1", ",", "num_groups", "*", "num_vars", ",", "var_dim", ")", ")", "nn", ".", "init", ".", "uniform_", "(", "self", ".", "vars", ")", "# projection", "self", ".", "weight_proj", "=", "nn", ".", "Linear", "(", "self", ".", "input_dim", ",", "num_groups", "*", "num_vars", ")", "nn", ".", "init", ".", "normal_", "(", "self", ".", "weight_proj", ".", "weight", ",", "mean", "=", "0", ",", "std", "=", "1", ")", "nn", ".", "init", ".", "zeros_", "(", "self", ".", "weight_proj", ".", "bias", ")", "self", ".", "max_temperature", "=", "max_temperature", "self", ".", "min_temperature", "=", "min_temperature", "self", ".", "temperature_decay", "=", "temperature_decay", "self", ".", "curr_temperature", "=", "self", ".", "max_temperature", "self", ".", "codebook_indices", "=", "None" ]
[ 459, 4 ]
[ 492, 36 ]
python
en
['es', 'la', 'en']
False
GumbelVectorQuantizer.targets_for
(self, x)
Get the output of the gumbel softmax or hard estimator and convert to one-hots :param x: [B, T, GxV] :return: y [B, T, G]
Get the output of the gumbel softmax or hard estimator and convert to one-hots
def targets_for(self, x): """Get the output of the gumbel softmax or hard estimator and convert to one-hots :param x: [B, T, GxV] :return: y [B, T, G] """ bsz = x.shape[0] tsz = x.shape[1] x = x.view(bsz * tsz, -1) targets = x.view(bsz * tsz * self.num_groups, -1).argmax(dim=-1).view(bsz, tsz, self.groups).detach() return targets
[ "def", "targets_for", "(", "self", ",", "x", ")", ":", "bsz", "=", "x", ".", "shape", "[", "0", "]", "tsz", "=", "x", ".", "shape", "[", "1", "]", "x", "=", "x", ".", "view", "(", "bsz", "*", "tsz", ",", "-", "1", ")", "targets", "=", "x", ".", "view", "(", "bsz", "*", "tsz", "*", "self", ".", "num_groups", ",", "-", "1", ")", ".", "argmax", "(", "dim", "=", "-", "1", ")", ".", "view", "(", "bsz", ",", "tsz", ",", "self", ".", "groups", ")", ".", "detach", "(", ")", "return", "targets" ]
[ 534, 4 ]
[ 544, 22 ]
python
en
['en', 'en', 'en']
True
Wav2Vec2PooledEncoder._reduction_1
(self, encoded, pad_mask)
Do a reduction using just the lengths and input
Do a reduction using just the lengths and input
def _reduction_1(self, encoded, pad_mask): """Do a reduction using just the lengths and input""" lengths = pad_mask.sum(-1) return self.reduction_layer((encoded, lengths))
[ "def", "_reduction_1", "(", "self", ",", "encoded", ",", "pad_mask", ")", ":", "lengths", "=", "pad_mask", ".", "sum", "(", "-", "1", ")", "return", "self", ".", "reduction_layer", "(", "(", "encoded", ",", "lengths", ")", ")" ]
[ 847, 4 ]
[ 850, 55 ]
python
en
['en', 'en', 'en']
True
Wav2Vec2PooledEncoder._reduction_3
(self, encoded, pad_mask)
Do a reduction using an attention layer with encoder as KQ and V
Do a reduction using an attention layer with encoder as KQ and V
def _reduction_3(self, encoded, pad_mask): """Do a reduction using an attention layer with encoder as KQ and V""" encoded_query = self.reduction_layer((encoded, encoded, encoded, pad_mask.unsqueeze(1).unsqueeze(1))) return encoded_query
[ "def", "_reduction_3", "(", "self", ",", "encoded", ",", "pad_mask", ")", ":", "encoded_query", "=", "self", ".", "reduction_layer", "(", "(", "encoded", ",", "encoded", ",", "encoded", ",", "pad_mask", ".", "unsqueeze", "(", "1", ")", ".", "unsqueeze", "(", "1", ")", ")", ")", "return", "encoded_query" ]
[ 852, 4 ]
[ 855, 28 ]
python
en
['en', 'en', 'en']
True
Wav2Vec2PooledEncoder._no_reduction_mask
(self, encoded, pad_mask)
Do no reduction and return the tensor and the pad vector
Do no reduction and return the tensor and the pad vector
def _no_reduction_mask(self, encoded, pad_mask): """Do no reduction and return the tensor and the pad vector""" return (encoded, pad_mask.unsqueeze(1).unsqueeze(1),)
[ "def", "_no_reduction_mask", "(", "self", ",", "encoded", ",", "pad_mask", ")", ":", "return", "(", "encoded", ",", "pad_mask", ".", "unsqueeze", "(", "1", ")", ".", "unsqueeze", "(", "1", ")", ",", ")" ]
[ 857, 4 ]
[ 859, 61 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up the Home Connect binary sensor.
Set up the Home Connect binary sensor.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Home Connect binary sensor.""" def get_entities(): entities = [] hc_api = hass.data[DOMAIN][config_entry.entry_id] for device_dict in hc_api.devices: entity_dicts = device_dict.get("entities", {}).get("binary_sensor", []) entities += [HomeConnectBinarySensor(**d) for d in entity_dicts] return entities async_add_entities(await hass.async_add_executor_job(get_entities), True)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "def", "get_entities", "(", ")", ":", "entities", "=", "[", "]", "hc_api", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "config_entry", ".", "entry_id", "]", "for", "device_dict", "in", "hc_api", ".", "devices", ":", "entity_dicts", "=", "device_dict", ".", "get", "(", "\"entities\"", ",", "{", "}", ")", ".", "get", "(", "\"binary_sensor\"", ",", "[", "]", ")", "entities", "+=", "[", "HomeConnectBinarySensor", "(", "*", "*", "d", ")", "for", "d", "in", "entity_dicts", "]", "return", "entities", "async_add_entities", "(", "await", "hass", ".", "async_add_executor_job", "(", "get_entities", ")", ",", "True", ")" ]
[ 11, 0 ]
[ 22, 77 ]
python
en
['en', 'en', 'en']
True
HomeConnectBinarySensor.__init__
(self, device, desc, device_class)
Initialize the entity.
Initialize the entity.
def __init__(self, device, desc, device_class): """Initialize the entity.""" super().__init__(device, desc) self._device_class = device_class self._state = None
[ "def", "__init__", "(", "self", ",", "device", ",", "desc", ",", "device_class", ")", ":", "super", "(", ")", ".", "__init__", "(", "device", ",", "desc", ")", "self", ".", "_device_class", "=", "device_class", "self", ".", "_state", "=", "None" ]
[ 28, 4 ]
[ 32, 26 ]
python
en
['en', 'en', 'en']
True
HomeConnectBinarySensor.is_on
(self)
Return true if the binary sensor is on.
Return true if the binary sensor is on.
def is_on(self): """Return true if the binary sensor is on.""" return bool(self._state)
[ "def", "is_on", "(", "self", ")", ":", "return", "bool", "(", "self", ".", "_state", ")" ]
[ 35, 4 ]
[ 37, 32 ]
python
en
['en', 'fy', 'en']
True
HomeConnectBinarySensor.available
(self)
Return true if the binary sensor is available.
Return true if the binary sensor is available.
def available(self): """Return true if the binary sensor is available.""" return self._state is not None
[ "def", "available", "(", "self", ")", ":", "return", "self", ".", "_state", "is", "not", "None" ]
[ 40, 4 ]
[ 42, 38 ]
python
en
['en', 'en', 'en']
True
HomeConnectBinarySensor.async_update
(self)
Update the binary sensor's status.
Update the binary sensor's status.
async def async_update(self): """Update the binary sensor's status.""" state = self.device.appliance.status.get(BSH_DOOR_STATE, {}) if not state: self._state = None elif state.get("value") in [ "BSH.Common.EnumType.DoorState.Closed", "BSH.Common.EnumType.DoorState.Locked", ]: self._state = False elif state.get("value") == "BSH.Common.EnumType.DoorState.Open": self._state = True else: _LOGGER.warning("Unexpected value for HomeConnect door state: %s", state) self._state = None _LOGGER.debug("Updated, new state: %s", self._state)
[ "async", "def", "async_update", "(", "self", ")", ":", "state", "=", "self", ".", "device", ".", "appliance", ".", "status", ".", "get", "(", "BSH_DOOR_STATE", ",", "{", "}", ")", "if", "not", "state", ":", "self", ".", "_state", "=", "None", "elif", "state", ".", "get", "(", "\"value\"", ")", "in", "[", "\"BSH.Common.EnumType.DoorState.Closed\"", ",", "\"BSH.Common.EnumType.DoorState.Locked\"", ",", "]", ":", "self", ".", "_state", "=", "False", "elif", "state", ".", "get", "(", "\"value\"", ")", "==", "\"BSH.Common.EnumType.DoorState.Open\"", ":", "self", ".", "_state", "=", "True", "else", ":", "_LOGGER", ".", "warning", "(", "\"Unexpected value for HomeConnect door state: %s\"", ",", "state", ")", "self", ".", "_state", "=", "None", "_LOGGER", ".", "debug", "(", "\"Updated, new state: %s\"", ",", "self", ".", "_state", ")" ]
[ 44, 4 ]
[ 59, 60 ]
python
en
['en', 'sn', 'en']
True
HomeConnectBinarySensor.device_class
(self)
Return the device class.
Return the device class.
def device_class(self): """Return the device class.""" return self._device_class
[ "def", "device_class", "(", "self", ")", ":", "return", "self", ".", "_device_class" ]
[ 62, 4 ]
[ 64, 33 ]
python
en
['en', 'en', 'en']
True
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up the Channels platform.
Set up the Channels platform.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Channels platform.""" device = ChannelsPlayer(config[CONF_NAME], config[CONF_HOST], config[CONF_PORT]) async_add_entities([device], True) platform = entity_platform.current_platform.get() platform.async_register_entity_service( SERVICE_SEEK_FORWARD, {}, "seek_forward", ) platform.async_register_entity_service( SERVICE_SEEK_BACKWARD, {}, "seek_backward", ) platform.async_register_entity_service( SERVICE_SEEK_BY, {vol.Required(ATTR_SECONDS): vol.Coerce(int)}, "seek_by", )
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "device", "=", "ChannelsPlayer", "(", "config", "[", "CONF_NAME", "]", ",", "config", "[", "CONF_HOST", "]", ",", "config", "[", "CONF_PORT", "]", ")", "async_add_entities", "(", "[", "device", "]", ",", "True", ")", "platform", "=", "entity_platform", ".", "current_platform", ".", "get", "(", ")", "platform", ".", "async_register_entity_service", "(", "SERVICE_SEEK_FORWARD", ",", "{", "}", ",", "\"seek_forward\"", ",", ")", "platform", ".", "async_register_entity_service", "(", "SERVICE_SEEK_BACKWARD", ",", "{", "}", ",", "\"seek_backward\"", ",", ")", "platform", ".", "async_register_entity_service", "(", "SERVICE_SEEK_BY", ",", "{", "vol", ".", "Required", "(", "ATTR_SECONDS", ")", ":", "vol", ".", "Coerce", "(", "int", ")", "}", ",", "\"seek_by\"", ",", ")" ]
[ 59, 0 ]
[ 80, 5 ]
python
en
['en', 'da', 'en']
True
ChannelsPlayer.__init__
(self, name, host, port)
Initialize the Channels app.
Initialize the Channels app.
def __init__(self, name, host, port): """Initialize the Channels app.""" self._name = name self._host = host self._port = port self.client = Channels(self._host, self._port) self.status = None self.muted = None self.channel_number = None self.channel_name = None self.channel_image_url = None self.now_playing_title = None self.now_playing_episode_title = None self.now_playing_season_number = None self.now_playing_episode_number = None self.now_playing_summary = None self.now_playing_image_url = None self.favorite_channels = []
[ "def", "__init__", "(", "self", ",", "name", ",", "host", ",", "port", ")", ":", "self", ".", "_name", "=", "name", "self", ".", "_host", "=", "host", "self", ".", "_port", "=", "port", "self", ".", "client", "=", "Channels", "(", "self", ".", "_host", ",", "self", ".", "_port", ")", "self", ".", "status", "=", "None", "self", ".", "muted", "=", "None", "self", ".", "channel_number", "=", "None", "self", ".", "channel_name", "=", "None", "self", ".", "channel_image_url", "=", "None", "self", ".", "now_playing_title", "=", "None", "self", ".", "now_playing_episode_title", "=", "None", "self", ".", "now_playing_season_number", "=", "None", "self", ".", "now_playing_episode_number", "=", "None", "self", ".", "now_playing_summary", "=", "None", "self", ".", "now_playing_image_url", "=", "None", "self", ".", "favorite_channels", "=", "[", "]" ]
[ 86, 4 ]
[ 109, 35 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.update_favorite_channels
(self)
Update the favorite channels from the client.
Update the favorite channels from the client.
def update_favorite_channels(self): """Update the favorite channels from the client.""" self.favorite_channels = self.client.favorite_channels()
[ "def", "update_favorite_channels", "(", "self", ")", ":", "self", ".", "favorite_channels", "=", "self", ".", "client", ".", "favorite_channels", "(", ")" ]
[ 111, 4 ]
[ 113, 64 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.update_state
(self, state_hash)
Update all the state properties with the passed in dictionary.
Update all the state properties with the passed in dictionary.
def update_state(self, state_hash): """Update all the state properties with the passed in dictionary.""" self.status = state_hash.get("status", "stopped") self.muted = state_hash.get("muted", False) channel_hash = state_hash.get("channel") np_hash = state_hash.get("now_playing") if channel_hash: self.channel_number = channel_hash.get("channel_number") self.channel_name = channel_hash.get("channel_name") self.channel_image_url = channel_hash.get("channel_image_url") else: self.channel_number = None self.channel_name = None self.channel_image_url = None if np_hash: self.now_playing_title = np_hash.get("title") self.now_playing_episode_title = np_hash.get("episode_title") self.now_playing_season_number = np_hash.get("season_number") self.now_playing_episode_number = np_hash.get("episode_number") self.now_playing_summary = np_hash.get("summary") self.now_playing_image_url = np_hash.get("image_url") else: self.now_playing_title = None self.now_playing_episode_title = None self.now_playing_season_number = None self.now_playing_episode_number = None self.now_playing_summary = None self.now_playing_image_url = None
[ "def", "update_state", "(", "self", ",", "state_hash", ")", ":", "self", ".", "status", "=", "state_hash", ".", "get", "(", "\"status\"", ",", "\"stopped\"", ")", "self", ".", "muted", "=", "state_hash", ".", "get", "(", "\"muted\"", ",", "False", ")", "channel_hash", "=", "state_hash", ".", "get", "(", "\"channel\"", ")", "np_hash", "=", "state_hash", ".", "get", "(", "\"now_playing\"", ")", "if", "channel_hash", ":", "self", ".", "channel_number", "=", "channel_hash", ".", "get", "(", "\"channel_number\"", ")", "self", ".", "channel_name", "=", "channel_hash", ".", "get", "(", "\"channel_name\"", ")", "self", ".", "channel_image_url", "=", "channel_hash", ".", "get", "(", "\"channel_image_url\"", ")", "else", ":", "self", ".", "channel_number", "=", "None", "self", ".", "channel_name", "=", "None", "self", ".", "channel_image_url", "=", "None", "if", "np_hash", ":", "self", ".", "now_playing_title", "=", "np_hash", ".", "get", "(", "\"title\"", ")", "self", ".", "now_playing_episode_title", "=", "np_hash", ".", "get", "(", "\"episode_title\"", ")", "self", ".", "now_playing_season_number", "=", "np_hash", ".", "get", "(", "\"season_number\"", ")", "self", ".", "now_playing_episode_number", "=", "np_hash", ".", "get", "(", "\"episode_number\"", ")", "self", ".", "now_playing_summary", "=", "np_hash", ".", "get", "(", "\"summary\"", ")", "self", ".", "now_playing_image_url", "=", "np_hash", ".", "get", "(", "\"image_url\"", ")", "else", ":", "self", ".", "now_playing_title", "=", "None", "self", ".", "now_playing_episode_title", "=", "None", "self", ".", "now_playing_season_number", "=", "None", "self", ".", "now_playing_episode_number", "=", "None", "self", ".", "now_playing_summary", "=", "None", "self", ".", "now_playing_image_url", "=", "None" ]
[ 115, 4 ]
[ 145, 45 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.name
(self)
Return the name of the player.
Return the name of the player.
def name(self): """Return the name of the player.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 148, 4 ]
[ 150, 25 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.state
(self)
Return the state of the player.
Return the state of the player.
def state(self): """Return the state of the player.""" if self.status == "stopped": return STATE_IDLE if self.status == "paused": return STATE_PAUSED if self.status == "playing": return STATE_PLAYING return None
[ "def", "state", "(", "self", ")", ":", "if", "self", ".", "status", "==", "\"stopped\"", ":", "return", "STATE_IDLE", "if", "self", ".", "status", "==", "\"paused\"", ":", "return", "STATE_PAUSED", "if", "self", ".", "status", "==", "\"playing\"", ":", "return", "STATE_PLAYING", "return", "None" ]
[ 153, 4 ]
[ 164, 19 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.update
(self)
Retrieve latest state.
Retrieve latest state.
def update(self): """Retrieve latest state.""" self.update_favorite_channels() self.update_state(self.client.status())
[ "def", "update", "(", "self", ")", ":", "self", ".", "update_favorite_channels", "(", ")", "self", ".", "update_state", "(", "self", ".", "client", ".", "status", "(", ")", ")" ]
[ 166, 4 ]
[ 169, 47 ]
python
en
['es', 'sk', 'en']
False
ChannelsPlayer.source_list
(self)
List of favorite channels.
List of favorite channels.
def source_list(self): """List of favorite channels.""" sources = [channel["name"] for channel in self.favorite_channels] return sources
[ "def", "source_list", "(", "self", ")", ":", "sources", "=", "[", "channel", "[", "\"name\"", "]", "for", "channel", "in", "self", ".", "favorite_channels", "]", "return", "sources" ]
[ 172, 4 ]
[ 175, 22 ]
python
en
['en', 'fy', 'en']
True
ChannelsPlayer.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" ]
[ 178, 4 ]
[ 180, 25 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.media_content_id
(self)
Content ID of current playing channel.
Content ID of current playing channel.
def media_content_id(self): """Content ID of current playing channel.""" return self.channel_number
[ "def", "media_content_id", "(", "self", ")", ":", "return", "self", ".", "channel_number" ]
[ 183, 4 ]
[ 185, 34 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.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_CHANNEL
[ "def", "media_content_type", "(", "self", ")", ":", "return", "MEDIA_TYPE_CHANNEL" ]
[ 188, 4 ]
[ 190, 33 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.media_image_url
(self)
Image url of current playing media.
Image url of current playing media.
def media_image_url(self): """Image url of current playing media.""" if self.now_playing_image_url: return self.now_playing_image_url if self.channel_image_url: return self.channel_image_url return "https://getchannels.com/assets/img/icon-1024.png"
[ "def", "media_image_url", "(", "self", ")", ":", "if", "self", ".", "now_playing_image_url", ":", "return", "self", ".", "now_playing_image_url", "if", "self", ".", "channel_image_url", ":", "return", "self", ".", "channel_image_url", "return", "\"https://getchannels.com/assets/img/icon-1024.png\"" ]
[ 193, 4 ]
[ 200, 65 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.media_title
(self)
Title of current playing media.
Title of current playing media.
def media_title(self): """Title of current playing media.""" if self.state: return self.now_playing_title return None
[ "def", "media_title", "(", "self", ")", ":", "if", "self", ".", "state", ":", "return", "self", ".", "now_playing_title", "return", "None" ]
[ 203, 4 ]
[ 208, 19 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.supported_features
(self)
Flag of media commands that are supported.
Flag of media commands that are supported.
def supported_features(self): """Flag of media commands that are supported.""" return FEATURE_SUPPORT
[ "def", "supported_features", "(", "self", ")", ":", "return", "FEATURE_SUPPORT" ]
[ 211, 4 ]
[ 213, 30 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.mute_volume
(self, mute)
Mute (true) or unmute (false) player.
Mute (true) or unmute (false) player.
def mute_volume(self, mute): """Mute (true) or unmute (false) player.""" if mute != self.muted: response = self.client.toggle_muted() self.update_state(response)
[ "def", "mute_volume", "(", "self", ",", "mute", ")", ":", "if", "mute", "!=", "self", ".", "muted", ":", "response", "=", "self", ".", "client", ".", "toggle_muted", "(", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 215, 4 ]
[ 219, 39 ]
python
en
['en', 'la', 'it']
False
ChannelsPlayer.media_stop
(self)
Send media_stop command to player.
Send media_stop command to player.
def media_stop(self): """Send media_stop command to player.""" self.status = "stopped" response = self.client.stop() self.update_state(response)
[ "def", "media_stop", "(", "self", ")", ":", "self", ".", "status", "=", "\"stopped\"", "response", "=", "self", ".", "client", ".", "stop", "(", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 221, 4 ]
[ 225, 35 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.media_play
(self)
Send media_play command to player.
Send media_play command to player.
def media_play(self): """Send media_play command to player.""" response = self.client.resume() self.update_state(response)
[ "def", "media_play", "(", "self", ")", ":", "response", "=", "self", ".", "client", ".", "resume", "(", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 227, 4 ]
[ 230, 35 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.media_pause
(self)
Send media_pause command to player.
Send media_pause command to player.
def media_pause(self): """Send media_pause command to player.""" response = self.client.pause() self.update_state(response)
[ "def", "media_pause", "(", "self", ")", ":", "response", "=", "self", ".", "client", ".", "pause", "(", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 232, 4 ]
[ 235, 35 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.media_next_track
(self)
Seek ahead.
Seek ahead.
def media_next_track(self): """Seek ahead.""" response = self.client.skip_forward() self.update_state(response)
[ "def", "media_next_track", "(", "self", ")", ":", "response", "=", "self", ".", "client", ".", "skip_forward", "(", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 237, 4 ]
[ 240, 35 ]
python
af
['et', 'af', 'en']
False
ChannelsPlayer.select_source
(self, source)
Select a channel to tune to.
Select a channel to tune to.
def select_source(self, source): """Select a channel to tune to.""" for channel in self.favorite_channels: if channel["name"] == source: response = self.client.play_channel(channel["number"]) self.update_state(response) break
[ "def", "select_source", "(", "self", ",", "source", ")", ":", "for", "channel", "in", "self", ".", "favorite_channels", ":", "if", "channel", "[", "\"name\"", "]", "==", "source", ":", "response", "=", "self", ".", "client", ".", "play_channel", "(", "channel", "[", "\"number\"", "]", ")", "self", ".", "update_state", "(", "response", ")", "break" ]
[ 247, 4 ]
[ 253, 21 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.play_media
(self, media_type, media_id, **kwargs)
Send the play_media command to the player.
Send the play_media command to the player.
def play_media(self, media_type, media_id, **kwargs): """Send the play_media command to the player.""" if media_type == MEDIA_TYPE_CHANNEL: response = self.client.play_channel(media_id) self.update_state(response) elif media_type in [MEDIA_TYPE_MOVIE, MEDIA_TYPE_EPISODE, MEDIA_TYPE_TVSHOW]: response = self.client.play_recording(media_id) self.update_state(response)
[ "def", "play_media", "(", "self", ",", "media_type", ",", "media_id", ",", "*", "*", "kwargs", ")", ":", "if", "media_type", "==", "MEDIA_TYPE_CHANNEL", ":", "response", "=", "self", ".", "client", ".", "play_channel", "(", "media_id", ")", "self", ".", "update_state", "(", "response", ")", "elif", "media_type", "in", "[", "MEDIA_TYPE_MOVIE", ",", "MEDIA_TYPE_EPISODE", ",", "MEDIA_TYPE_TVSHOW", "]", ":", "response", "=", "self", ".", "client", ".", "play_recording", "(", "media_id", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 255, 4 ]
[ 262, 39 ]
python
en
['en', 'en', 'en']
True
ChannelsPlayer.seek_forward
(self)
Seek forward in the timeline.
Seek forward in the timeline.
def seek_forward(self): """Seek forward in the timeline.""" response = self.client.seek_forward() self.update_state(response)
[ "def", "seek_forward", "(", "self", ")", ":", "response", "=", "self", ".", "client", ".", "seek_forward", "(", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 264, 4 ]
[ 267, 35 ]
python
en
['en', 'af', 'en']
True
ChannelsPlayer.seek_backward
(self)
Seek backward in the timeline.
Seek backward in the timeline.
def seek_backward(self): """Seek backward in the timeline.""" response = self.client.seek_backward() self.update_state(response)
[ "def", "seek_backward", "(", "self", ")", ":", "response", "=", "self", ".", "client", ".", "seek_backward", "(", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 269, 4 ]
[ 272, 35 ]
python
en
['en', 'fy', 'en']
True
ChannelsPlayer.seek_by
(self, seconds)
Seek backward in the timeline.
Seek backward in the timeline.
def seek_by(self, seconds): """Seek backward in the timeline.""" response = self.client.seek(seconds) self.update_state(response)
[ "def", "seek_by", "(", "self", ",", "seconds", ")", ":", "response", "=", "self", ".", "client", ".", "seek", "(", "seconds", ")", "self", ".", "update_state", "(", "response", ")" ]
[ 274, 4 ]
[ 277, 35 ]
python
en
['en', 'fy', 'en']
True
get_device_platforms
(device)
Return the HA platforms for a device type.
Return the HA platforms for a device type.
def get_device_platforms(device): """Return the HA platforms for a device type.""" return DEVICE_PLATFORM.get(type(device), {}).keys()
[ "def", "get_device_platforms", "(", "device", ")", ":", "return", "DEVICE_PLATFORM", ".", "get", "(", "type", "(", "device", ")", ",", "{", "}", ")", ".", "keys", "(", ")" ]
[ 105, 0 ]
[ 107, 55 ]
python
en
['en', 'en', 'en']
True
get_platform_groups
(device, domain)
Return the platforms that a device belongs in.
Return the platforms that a device belongs in.
def get_platform_groups(device, domain) -> dict: """Return the platforms that a device belongs in.""" return DEVICE_PLATFORM.get(type(device), {}).get(domain, {})
[ "def", "get_platform_groups", "(", "device", ",", "domain", ")", "->", "dict", ":", "return", "DEVICE_PLATFORM", ".", "get", "(", "type", "(", "device", ")", ",", "{", "}", ")", ".", "get", "(", "domain", ",", "{", "}", ")" ]
[ 110, 0 ]
[ 112, 64 ]
python
en
['en', 'en', 'en']
True
DevoloMultiLevelSwitchDeviceEntity.__init__
(self, homecontrol, device_instance, element_uid)
Initialize a multi level switch within devolo Home Control.
Initialize a multi level switch within devolo Home Control.
def __init__(self, homecontrol, device_instance, element_uid): """Initialize a multi level switch within devolo Home Control.""" super().__init__( homecontrol=homecontrol, device_instance=device_instance, element_uid=element_uid, ) self._multi_level_switch_property = device_instance.multi_level_switch_property[ element_uid ] self._value = self._multi_level_switch_property.value
[ "def", "__init__", "(", "self", ",", "homecontrol", ",", "device_instance", ",", "element_uid", ")", ":", "super", "(", ")", ".", "__init__", "(", "homecontrol", "=", "homecontrol", ",", "device_instance", "=", "device_instance", ",", "element_uid", "=", "element_uid", ",", ")", "self", ".", "_multi_level_switch_property", "=", "device_instance", ".", "multi_level_switch_property", "[", "element_uid", "]", "self", ".", "_value", "=", "self", ".", "_multi_level_switch_property", ".", "value" ]
[ 7, 4 ]
[ 18, 61 ]
python
en
['en', 'en', 'en']
True
validate_input
(hass: core.HomeAssistant, data)
Validate the user input allows us to connect.
Validate the user input allows us to connect.
async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect.""" for entry in hass.config_entries.async_entries(DOMAIN): if entry.data[CONF_HOST] == data[CONF_HOST]: raise AlreadyConfigured if data[CONF_VERSION] not in SUPPORTED_VERSIONS: raise WrongVersion try: api = get_api(hass, data) await api.get_data() except glances_api.exceptions.GlancesApiConnectionError as err: raise CannotConnect from err
[ "async", "def", "validate_input", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "data", ")", ":", "for", "entry", "in", "hass", ".", "config_entries", ".", "async_entries", "(", "DOMAIN", ")", ":", "if", "entry", ".", "data", "[", "CONF_HOST", "]", "==", "data", "[", "CONF_HOST", "]", ":", "raise", "AlreadyConfigured", "if", "data", "[", "CONF_VERSION", "]", "not", "in", "SUPPORTED_VERSIONS", ":", "raise", "WrongVersion", "try", ":", "api", "=", "get_api", "(", "hass", ",", "data", ")", "await", "api", ".", "get_data", "(", ")", "except", "glances_api", ".", "exceptions", ".", "GlancesApiConnectionError", "as", "err", ":", "raise", "CannotConnect", "from", "err" ]
[ 43, 0 ]
[ 55, 36 ]
python
en
['en', 'en', 'en']
True
GlancesFlowHandler.async_get_options_flow
(config_entry)
Get the options flow for this handler.
Get the options flow for this handler.
def async_get_options_flow(config_entry): """Get the options flow for this handler.""" return GlancesOptionsFlowHandler(config_entry)
[ "def", "async_get_options_flow", "(", "config_entry", ")", ":", "return", "GlancesOptionsFlowHandler", "(", "config_entry", ")" ]
[ 66, 4 ]
[ 68, 54 ]
python
en
['en', 'en', 'en']
True
GlancesFlowHandler.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: try: await validate_input(self.hass, user_input) return self.async_create_entry( title=user_input[CONF_NAME], data=user_input ) except AlreadyConfigured: return self.async_abort(reason="already_configured") except CannotConnect: errors["base"] = "cannot_connect" except WrongVersion: errors[CONF_VERSION] = "wrong_version" return self.async_show_form( step_id="user", data_schema=DATA_SCHEMA, errors=errors )
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "try", ":", "await", "validate_input", "(", "self", ".", "hass", ",", "user_input", ")", "return", "self", ".", "async_create_entry", "(", "title", "=", "user_input", "[", "CONF_NAME", "]", ",", "data", "=", "user_input", ")", "except", "AlreadyConfigured", ":", "return", "self", ".", "async_abort", "(", "reason", "=", "\"already_configured\"", ")", "except", "CannotConnect", ":", "errors", "[", "\"base\"", "]", "=", "\"cannot_connect\"", "except", "WrongVersion", ":", "errors", "[", "CONF_VERSION", "]", "=", "\"wrong_version\"", "return", "self", ".", "async_show_form", "(", "step_id", "=", "\"user\"", ",", "data_schema", "=", "DATA_SCHEMA", ",", "errors", "=", "errors", ")" ]
[ 70, 4 ]
[ 88, 9 ]
python
en
['en', 'en', 'en']
True
GlancesFlowHandler.async_step_import
(self, import_config)
Import from Glances sensor config.
Import from Glances sensor config.
async def async_step_import(self, import_config): """Import from Glances sensor config.""" return await self.async_step_user(user_input=import_config)
[ "async", "def", "async_step_import", "(", "self", ",", "import_config", ")", ":", "return", "await", "self", ".", "async_step_user", "(", "user_input", "=", "import_config", ")" ]
[ 90, 4 ]
[ 93, 67 ]
python
en
['en', 'pt', 'en']
True
GlancesOptionsFlowHandler.__init__
(self, config_entry)
Initialize Glances options flow.
Initialize Glances options flow.
def __init__(self, config_entry): """Initialize Glances options flow.""" self.config_entry = config_entry
[ "def", "__init__", "(", "self", ",", "config_entry", ")", ":", "self", ".", "config_entry", "=", "config_entry" ]
[ 99, 4 ]
[ 101, 40 ]
python
en
['en', 'fr', 'en']
True
GlancesOptionsFlowHandler.async_step_init
(self, user_input=None)
Manage the Glances options.
Manage the Glances options.
async def async_step_init(self, user_input=None): """Manage the Glances options.""" if user_input is not None: return self.async_create_entry(title="", data=user_input) options = { vol.Optional( CONF_SCAN_INTERVAL, default=self.config_entry.options.get( CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL ), ): int } return self.async_show_form(step_id="init", data_schema=vol.Schema(options))
[ "async", "def", "async_step_init", "(", "self", ",", "user_input", "=", "None", ")", ":", "if", "user_input", "is", "not", "None", ":", "return", "self", ".", "async_create_entry", "(", "title", "=", "\"\"", ",", "data", "=", "user_input", ")", "options", "=", "{", "vol", ".", "Optional", "(", "CONF_SCAN_INTERVAL", ",", "default", "=", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_SCAN_INTERVAL", ",", "DEFAULT_SCAN_INTERVAL", ")", ",", ")", ":", "int", "}", "return", "self", ".", "async_show_form", "(", "step_id", "=", "\"init\"", ",", "data_schema", "=", "vol", ".", "Schema", "(", "options", ")", ")" ]
[ 103, 4 ]
[ 117, 84 ]
python
en
['en', 'en', 'en']
True
Blueprint.__init__
( self, data: dict, *, path: Optional[str] = None, expected_domain: Optional[str] = None, )
Initialize a blueprint.
Initialize a blueprint.
def __init__( self, data: dict, *, path: Optional[str] = None, expected_domain: Optional[str] = None, ) -> None: """Initialize a blueprint.""" try: data = self.data = BLUEPRINT_SCHEMA(data) except vol.Invalid as err: raise InvalidBlueprint(expected_domain, path, data, err) from err self.placeholders = placeholder.extract_placeholders(data) # In future, we will treat this as "incorrect" and allow to recover from this data_domain = data[CONF_BLUEPRINT][CONF_DOMAIN] if expected_domain is not None and data_domain != expected_domain: raise InvalidBlueprint( expected_domain, path or self.name, data, f"Found incorrect blueprint type {data_domain}, expected {expected_domain}", ) self.domain = data_domain missing = self.placeholders - set(data[CONF_BLUEPRINT][CONF_INPUT]) if missing: raise InvalidBlueprint( data_domain, path or self.name, data, f"Missing input definition for {', '.join(missing)}", )
[ "def", "__init__", "(", "self", ",", "data", ":", "dict", ",", "*", ",", "path", ":", "Optional", "[", "str", "]", "=", "None", ",", "expected_domain", ":", "Optional", "[", "str", "]", "=", "None", ",", ")", "->", "None", ":", "try", ":", "data", "=", "self", ".", "data", "=", "BLUEPRINT_SCHEMA", "(", "data", ")", "except", "vol", ".", "Invalid", "as", "err", ":", "raise", "InvalidBlueprint", "(", "expected_domain", ",", "path", ",", "data", ",", "err", ")", "from", "err", "self", ".", "placeholders", "=", "placeholder", ".", "extract_placeholders", "(", "data", ")", "# In future, we will treat this as \"incorrect\" and allow to recover from this", "data_domain", "=", "data", "[", "CONF_BLUEPRINT", "]", "[", "CONF_DOMAIN", "]", "if", "expected_domain", "is", "not", "None", "and", "data_domain", "!=", "expected_domain", ":", "raise", "InvalidBlueprint", "(", "expected_domain", ",", "path", "or", "self", ".", "name", ",", "data", ",", "f\"Found incorrect blueprint type {data_domain}, expected {expected_domain}\"", ",", ")", "self", ".", "domain", "=", "data_domain", "missing", "=", "self", ".", "placeholders", "-", "set", "(", "data", "[", "CONF_BLUEPRINT", "]", "[", "CONF_INPUT", "]", ")", "if", "missing", ":", "raise", "InvalidBlueprint", "(", "data_domain", ",", "path", "or", "self", ".", "name", ",", "data", ",", "f\"Missing input definition for {', '.join(missing)}\"", ",", ")" ]
[ 40, 4 ]
[ 75, 13 ]
python
en
['en', 'fr', 'en']
True
Blueprint.name
(self)
Return blueprint name.
Return blueprint name.
def name(self) -> str: """Return blueprint name.""" return self.data[CONF_BLUEPRINT][CONF_NAME]
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "self", ".", "data", "[", "CONF_BLUEPRINT", "]", "[", "CONF_NAME", "]" ]
[ 78, 4 ]
[ 80, 51 ]
python
en
['fr', 'no', 'en']
False
Blueprint.metadata
(self)
Return blueprint metadata.
Return blueprint metadata.
def metadata(self) -> dict: """Return blueprint metadata.""" return self.data[CONF_BLUEPRINT]
[ "def", "metadata", "(", "self", ")", "->", "dict", ":", "return", "self", ".", "data", "[", "CONF_BLUEPRINT", "]" ]
[ 83, 4 ]
[ 85, 40 ]
python
en
['fr', 'is', 'en']
False
Blueprint.update_metadata
(self, *, source_url: Optional[str] = None)
Update metadata.
Update metadata.
def update_metadata(self, *, source_url: Optional[str] = None) -> None: """Update metadata.""" if source_url is not None: self.data[CONF_BLUEPRINT][CONF_SOURCE_URL] = source_url
[ "def", "update_metadata", "(", "self", ",", "*", ",", "source_url", ":", "Optional", "[", "str", "]", "=", "None", ")", "->", "None", ":", "if", "source_url", "is", "not", "None", ":", "self", ".", "data", "[", "CONF_BLUEPRINT", "]", "[", "CONF_SOURCE_URL", "]", "=", "source_url" ]
[ 87, 4 ]
[ 90, 67 ]
python
en
['en', 'la', 'it']
False
Blueprint.yaml
(self)
Dump blueprint as YAML.
Dump blueprint as YAML.
def yaml(self) -> str: """Dump blueprint as YAML.""" return yaml.dump(self.data)
[ "def", "yaml", "(", "self", ")", "->", "str", ":", "return", "yaml", ".", "dump", "(", "self", ".", "data", ")" ]
[ 92, 4 ]
[ 94, 35 ]
python
en
['en', 'ga', 'en']
True
Blueprint.validate
(self)
Test if the Home Assistant installation supports this blueprint. Return list of errors if not valid.
Test if the Home Assistant installation supports this blueprint.
def validate(self) -> Optional[List[str]]: """Test if the Home Assistant installation supports this blueprint. Return list of errors if not valid. """ errors = [] metadata = self.metadata min_version = metadata.get(CONF_HOMEASSISTANT, {}).get(CONF_MIN_VERSION) if min_version is not None and parse_version(__version__) < parse_version( min_version ): errors.append(f"Requires at least Home Assistant {min_version}") return errors or None
[ "def", "validate", "(", "self", ")", "->", "Optional", "[", "List", "[", "str", "]", "]", ":", "errors", "=", "[", "]", "metadata", "=", "self", ".", "metadata", "min_version", "=", "metadata", ".", "get", "(", "CONF_HOMEASSISTANT", ",", "{", "}", ")", ".", "get", "(", "CONF_MIN_VERSION", ")", "if", "min_version", "is", "not", "None", "and", "parse_version", "(", "__version__", ")", "<", "parse_version", "(", "min_version", ")", ":", "errors", ".", "append", "(", "f\"Requires at least Home Assistant {min_version}\"", ")", "return", "errors", "or", "None" ]
[ 97, 4 ]
[ 111, 29 ]
python
en
['en', 'en', 'en']
True
BlueprintInputs.__init__
( self, blueprint: Blueprint, config_with_inputs: Dict[str, Any] )
Instantiate a blueprint inputs object.
Instantiate a blueprint inputs object.
def __init__( self, blueprint: Blueprint, config_with_inputs: Dict[str, Any] ) -> None: """Instantiate a blueprint inputs object.""" self.blueprint = blueprint self.config_with_inputs = config_with_inputs
[ "def", "__init__", "(", "self", ",", "blueprint", ":", "Blueprint", ",", "config_with_inputs", ":", "Dict", "[", "str", ",", "Any", "]", ")", "->", "None", ":", "self", ".", "blueprint", "=", "blueprint", "self", ".", "config_with_inputs", "=", "config_with_inputs" ]
[ 117, 4 ]
[ 122, 52 ]
python
en
['en', 'lb', 'en']
True
BlueprintInputs.inputs
(self)
Return the inputs.
Return the inputs.
def inputs(self): """Return the inputs.""" return self.config_with_inputs[CONF_USE_BLUEPRINT][CONF_INPUT]
[ "def", "inputs", "(", "self", ")", ":", "return", "self", ".", "config_with_inputs", "[", "CONF_USE_BLUEPRINT", "]", "[", "CONF_INPUT", "]" ]
[ 125, 4 ]
[ 127, 70 ]
python
en
['en', 'mt', 'en']
True
BlueprintInputs.validate
(self)
Validate the inputs.
Validate the inputs.
def validate(self) -> None: """Validate the inputs.""" missing = self.blueprint.placeholders - set(self.inputs) if missing: raise MissingPlaceholder( self.blueprint.domain, self.blueprint.name, missing )
[ "def", "validate", "(", "self", ")", "->", "None", ":", "missing", "=", "self", ".", "blueprint", ".", "placeholders", "-", "set", "(", "self", ".", "inputs", ")", "if", "missing", ":", "raise", "MissingPlaceholder", "(", "self", ".", "blueprint", ".", "domain", ",", "self", ".", "blueprint", ".", "name", ",", "missing", ")" ]
[ 129, 4 ]
[ 136, 13 ]
python
en
['en', 'en', 'en']
True
BlueprintInputs.async_substitute
(self)
Get the blueprint value with the inputs substituted.
Get the blueprint value with the inputs substituted.
def async_substitute(self) -> dict: """Get the blueprint value with the inputs substituted.""" processed = placeholder.substitute(self.blueprint.data, self.inputs) combined = {**self.config_with_inputs, **processed} # From config_with_inputs combined.pop(CONF_USE_BLUEPRINT) # From blueprint combined.pop(CONF_BLUEPRINT) return combined
[ "def", "async_substitute", "(", "self", ")", "->", "dict", ":", "processed", "=", "placeholder", ".", "substitute", "(", "self", ".", "blueprint", ".", "data", ",", "self", ".", "inputs", ")", "combined", "=", "{", "*", "*", "self", ".", "config_with_inputs", ",", "*", "*", "processed", "}", "# From config_with_inputs", "combined", ".", "pop", "(", "CONF_USE_BLUEPRINT", ")", "# From blueprint", "combined", ".", "pop", "(", "CONF_BLUEPRINT", ")", "return", "combined" ]
[ 142, 4 ]
[ 150, 23 ]
python
en
['en', 'en', 'en']
True
DomainBlueprints.__init__
( self, hass: HomeAssistant, domain: str, logger: logging.Logger, )
Initialize a domain blueprints instance.
Initialize a domain blueprints instance.
def __init__( self, hass: HomeAssistant, domain: str, logger: logging.Logger, ) -> None: """Initialize a domain blueprints instance.""" self.hass = hass self.domain = domain self.logger = logger self._blueprints = {} self._load_lock = asyncio.Lock() hass.data.setdefault(DOMAIN, {})[domain] = self
[ "def", "__init__", "(", "self", ",", "hass", ":", "HomeAssistant", ",", "domain", ":", "str", ",", "logger", ":", "logging", ".", "Logger", ",", ")", "->", "None", ":", "self", ".", "hass", "=", "hass", "self", ".", "domain", "=", "domain", "self", ".", "logger", "=", "logger", "self", ".", "_blueprints", "=", "{", "}", "self", ".", "_load_lock", "=", "asyncio", ".", "Lock", "(", ")", "hass", ".", "data", ".", "setdefault", "(", "DOMAIN", ",", "{", "}", ")", "[", "domain", "]", "=", "self" ]
[ 156, 4 ]
[ 169, 55 ]
python
en
['en', 'fr', 'en']
True
DomainBlueprints.async_reset_cache
(self)
Reset the blueprint cache.
Reset the blueprint cache.
def async_reset_cache(self) -> None: """Reset the blueprint cache.""" self._blueprints = {}
[ "def", "async_reset_cache", "(", "self", ")", "->", "None", ":", "self", ".", "_blueprints", "=", "{", "}" ]
[ 172, 4 ]
[ 174, 29 ]
python
en
['en', 'fr', 'en']
True
DomainBlueprints._load_blueprint
(self, blueprint_path)
Load a blueprint.
Load a blueprint.
def _load_blueprint(self, blueprint_path) -> Blueprint: """Load a blueprint.""" try: blueprint_data = yaml.load_yaml( self.hass.config.path(BLUEPRINT_FOLDER, self.domain, blueprint_path) ) except (HomeAssistantError, FileNotFoundError) as err: raise FailedToLoad(self.domain, blueprint_path, err) from err return Blueprint( blueprint_data, expected_domain=self.domain, path=blueprint_path )
[ "def", "_load_blueprint", "(", "self", ",", "blueprint_path", ")", "->", "Blueprint", ":", "try", ":", "blueprint_data", "=", "yaml", ".", "load_yaml", "(", "self", ".", "hass", ".", "config", ".", "path", "(", "BLUEPRINT_FOLDER", ",", "self", ".", "domain", ",", "blueprint_path", ")", ")", "except", "(", "HomeAssistantError", ",", "FileNotFoundError", ")", "as", "err", ":", "raise", "FailedToLoad", "(", "self", ".", "domain", ",", "blueprint_path", ",", "err", ")", "from", "err", "return", "Blueprint", "(", "blueprint_data", ",", "expected_domain", "=", "self", ".", "domain", ",", "path", "=", "blueprint_path", ")" ]
[ 176, 4 ]
[ 187, 9 ]
python
en
['en', 'ca', 'en']
True
DomainBlueprints._load_blueprints
(self)
Load all the blueprints.
Load all the blueprints.
def _load_blueprints(self) -> Dict[str, Union[Blueprint, BlueprintException]]: """Load all the blueprints.""" blueprint_folder = pathlib.Path( self.hass.config.path(BLUEPRINT_FOLDER, self.domain) ) results = {} for blueprint_path in blueprint_folder.glob("**/*.yaml"): blueprint_path = str(blueprint_path.relative_to(blueprint_folder)) if self._blueprints.get(blueprint_path) is None: try: self._blueprints[blueprint_path] = self._load_blueprint( blueprint_path ) except BlueprintException as err: self._blueprints[blueprint_path] = None results[blueprint_path] = err continue results[blueprint_path] = self._blueprints[blueprint_path] return results
[ "def", "_load_blueprints", "(", "self", ")", "->", "Dict", "[", "str", ",", "Union", "[", "Blueprint", ",", "BlueprintException", "]", "]", ":", "blueprint_folder", "=", "pathlib", ".", "Path", "(", "self", ".", "hass", ".", "config", ".", "path", "(", "BLUEPRINT_FOLDER", ",", "self", ".", "domain", ")", ")", "results", "=", "{", "}", "for", "blueprint_path", "in", "blueprint_folder", ".", "glob", "(", "\"**/*.yaml\"", ")", ":", "blueprint_path", "=", "str", "(", "blueprint_path", ".", "relative_to", "(", "blueprint_folder", ")", ")", "if", "self", ".", "_blueprints", ".", "get", "(", "blueprint_path", ")", "is", "None", ":", "try", ":", "self", ".", "_blueprints", "[", "blueprint_path", "]", "=", "self", ".", "_load_blueprint", "(", "blueprint_path", ")", "except", "BlueprintException", "as", "err", ":", "self", ".", "_blueprints", "[", "blueprint_path", "]", "=", "None", "results", "[", "blueprint_path", "]", "=", "err", "continue", "results", "[", "blueprint_path", "]", "=", "self", ".", "_blueprints", "[", "blueprint_path", "]", "return", "results" ]
[ 189, 4 ]
[ 210, 22 ]
python
en
['en', 'en', 'en']
True
DomainBlueprints.async_get_blueprints
( self, )
Get all the blueprints.
Get all the blueprints.
async def async_get_blueprints( self, ) -> Dict[str, Union[Blueprint, BlueprintException]]: """Get all the blueprints.""" async with self._load_lock: return await self.hass.async_add_executor_job(self._load_blueprints)
[ "async", "def", "async_get_blueprints", "(", "self", ",", ")", "->", "Dict", "[", "str", ",", "Union", "[", "Blueprint", ",", "BlueprintException", "]", "]", ":", "async", "with", "self", ".", "_load_lock", ":", "return", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "self", ".", "_load_blueprints", ")" ]
[ 212, 4 ]
[ 217, 80 ]
python
en
['en', 'en', 'en']
True
DomainBlueprints.async_get_blueprint
(self, blueprint_path: str)
Get a blueprint.
Get a blueprint.
async def async_get_blueprint(self, blueprint_path: str) -> Blueprint: """Get a blueprint.""" if blueprint_path in self._blueprints: return self._blueprints[blueprint_path] async with self._load_lock: # Check it again if blueprint_path in self._blueprints: return self._blueprints[blueprint_path] try: blueprint = await self.hass.async_add_executor_job( self._load_blueprint, blueprint_path ) except Exception: self._blueprints[blueprint_path] = None raise self._blueprints[blueprint_path] = blueprint return blueprint
[ "async", "def", "async_get_blueprint", "(", "self", ",", "blueprint_path", ":", "str", ")", "->", "Blueprint", ":", "if", "blueprint_path", "in", "self", ".", "_blueprints", ":", "return", "self", ".", "_blueprints", "[", "blueprint_path", "]", "async", "with", "self", ".", "_load_lock", ":", "# Check it again", "if", "blueprint_path", "in", "self", ".", "_blueprints", ":", "return", "self", ".", "_blueprints", "[", "blueprint_path", "]", "try", ":", "blueprint", "=", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "self", ".", "_load_blueprint", ",", "blueprint_path", ")", "except", "Exception", ":", "self", ".", "_blueprints", "[", "blueprint_path", "]", "=", "None", "raise", "self", ".", "_blueprints", "[", "blueprint_path", "]", "=", "blueprint", "return", "blueprint" ]
[ 219, 4 ]
[ 238, 28 ]
python
en
['en', 'lb', 'en']
True
DomainBlueprints.async_inputs_from_config
( self, config_with_blueprint: dict )
Process a blueprint config.
Process a blueprint config.
async def async_inputs_from_config( self, config_with_blueprint: dict ) -> BlueprintInputs: """Process a blueprint config.""" try: config_with_blueprint = BLUEPRINT_INSTANCE_FIELDS(config_with_blueprint) except vol.Invalid as err: raise InvalidBlueprintInputs( self.domain, humanize_error(config_with_blueprint, err) ) from err bp_conf = config_with_blueprint[CONF_USE_BLUEPRINT] blueprint = await self.async_get_blueprint(bp_conf[CONF_PATH]) inputs = BlueprintInputs(blueprint, config_with_blueprint) inputs.validate() return inputs
[ "async", "def", "async_inputs_from_config", "(", "self", ",", "config_with_blueprint", ":", "dict", ")", "->", "BlueprintInputs", ":", "try", ":", "config_with_blueprint", "=", "BLUEPRINT_INSTANCE_FIELDS", "(", "config_with_blueprint", ")", "except", "vol", ".", "Invalid", "as", "err", ":", "raise", "InvalidBlueprintInputs", "(", "self", ".", "domain", ",", "humanize_error", "(", "config_with_blueprint", ",", "err", ")", ")", "from", "err", "bp_conf", "=", "config_with_blueprint", "[", "CONF_USE_BLUEPRINT", "]", "blueprint", "=", "await", "self", ".", "async_get_blueprint", "(", "bp_conf", "[", "CONF_PATH", "]", ")", "inputs", "=", "BlueprintInputs", "(", "blueprint", ",", "config_with_blueprint", ")", "inputs", ".", "validate", "(", ")", "return", "inputs" ]
[ 240, 4 ]
[ 255, 21 ]
python
en
['en', 'ca', 'en']
True