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 |
---|---|---|---|---|---|---|---|---|---|---|---|
SharpAquosTVDevice.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._supported_features | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"self",
".",
"_supported_features"
] | [
199,
4
] | [
201,
39
] | python | en | ['en', 'en', 'en'] | True |
SharpAquosTVDevice.turn_off | (self) | Turn off tvplayer. | Turn off tvplayer. | def turn_off(self):
"""Turn off tvplayer."""
self._remote.power(0) | [
"def",
"turn_off",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"power",
"(",
"0",
")"
] | [
204,
4
] | [
206,
29
] | python | en | ['en', 'yo', 'en'] | True |
SharpAquosTVDevice.volume_up | (self) | Volume up the media player. | Volume up the media player. | def volume_up(self):
"""Volume up the media player."""
self._remote.volume(int(self._volume * 60) + 2) | [
"def",
"volume_up",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"volume",
"(",
"int",
"(",
"self",
".",
"_volume",
"*",
"60",
")",
"+",
"2",
")"
] | [
209,
4
] | [
211,
55
] | python | en | ['en', 'en', 'en'] | True |
SharpAquosTVDevice.volume_down | (self) | Volume down media player. | Volume down media player. | def volume_down(self):
"""Volume down media player."""
self._remote.volume(int(self._volume * 60) - 2) | [
"def",
"volume_down",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"volume",
"(",
"int",
"(",
"self",
".",
"_volume",
"*",
"60",
")",
"-",
"2",
")"
] | [
214,
4
] | [
216,
55
] | python | en | ['en', 'sl', 'en'] | True |
SharpAquosTVDevice.set_volume_level | (self, volume) | Set Volume media player. | Set Volume media player. | def set_volume_level(self, volume):
"""Set Volume media player."""
self._remote.volume(int(volume * 60)) | [
"def",
"set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"self",
".",
"_remote",
".",
"volume",
"(",
"int",
"(",
"volume",
"*",
"60",
")",
")"
] | [
219,
4
] | [
221,
45
] | python | en | ['fr', 'no', 'en'] | False |
SharpAquosTVDevice.mute_volume | (self, mute) | Send mute command. | Send mute command. | def mute_volume(self, mute):
"""Send mute command."""
self._remote.mute(0) | [
"def",
"mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"self",
".",
"_remote",
".",
"mute",
"(",
"0",
")"
] | [
224,
4
] | [
226,
28
] | python | en | ['en', 'co', 'en'] | True |
SharpAquosTVDevice.turn_on | (self) | Turn the media player on. | Turn the media player on. | def turn_on(self):
"""Turn the media player on."""
self._remote.power(1) | [
"def",
"turn_on",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"power",
"(",
"1",
")"
] | [
229,
4
] | [
231,
29
] | python | en | ['en', 'en', 'en'] | True |
SharpAquosTVDevice.media_play_pause | (self) | Simulate play pause media player. | Simulate play pause media player. | def media_play_pause(self):
"""Simulate play pause media player."""
self._remote.remote_button(40) | [
"def",
"media_play_pause",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"remote_button",
"(",
"40",
")"
] | [
234,
4
] | [
236,
38
] | python | en | ['en', 'en', 'it'] | True |
SharpAquosTVDevice.media_play | (self) | Send play command. | Send play command. | def media_play(self):
"""Send play command."""
self._remote.remote_button(16) | [
"def",
"media_play",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"remote_button",
"(",
"16",
")"
] | [
239,
4
] | [
241,
38
] | python | en | ['en', 'en', 'en'] | True |
SharpAquosTVDevice.media_pause | (self) | Send pause command. | Send pause command. | def media_pause(self):
"""Send pause command."""
self._remote.remote_button(16) | [
"def",
"media_pause",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"remote_button",
"(",
"16",
")"
] | [
244,
4
] | [
246,
38
] | python | en | ['en', 'en', 'en'] | True |
SharpAquosTVDevice.media_next_track | (self) | Send next track command. | Send next track command. | def media_next_track(self):
"""Send next track command."""
self._remote.remote_button(21) | [
"def",
"media_next_track",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"remote_button",
"(",
"21",
")"
] | [
249,
4
] | [
251,
38
] | python | en | ['en', 'pt', 'en'] | True |
SharpAquosTVDevice.media_previous_track | (self) | Send the previous track command. | Send the previous track command. | def media_previous_track(self):
"""Send the previous track command."""
self._remote.remote_button(19) | [
"def",
"media_previous_track",
"(",
"self",
")",
":",
"self",
".",
"_remote",
".",
"remote_button",
"(",
"19",
")"
] | [
254,
4
] | [
256,
38
] | python | en | ['en', 'en', 'en'] | True |
SharpAquosTVDevice.select_source | (self, source) | Set the input source. | Set the input source. | def select_source(self, source):
"""Set the input source."""
for key, value in SOURCES.items():
if source == value:
self._remote.input(key) | [
"def",
"select_source",
"(",
"self",
",",
"source",
")",
":",
"for",
"key",
",",
"value",
"in",
"SOURCES",
".",
"items",
"(",
")",
":",
"if",
"source",
"==",
"value",
":",
"self",
".",
"_remote",
".",
"input",
"(",
"key",
")"
] | [
258,
4
] | [
262,
39
] | python | en | ['en', 'su', 'en'] | True |
get_service | (hass, config, discovery_info=None) | Get the file notification service. | Get the file notification service. | def get_service(hass, config, discovery_info=None):
"""Get the file notification service."""
filename = config[CONF_FILENAME]
timestamp = config[CONF_TIMESTAMP]
return FileNotificationService(hass, filename, timestamp) | [
"def",
"get_service",
"(",
"hass",
",",
"config",
",",
"discovery_info",
"=",
"None",
")",
":",
"filename",
"=",
"config",
"[",
"CONF_FILENAME",
"]",
"timestamp",
"=",
"config",
"[",
"CONF_TIMESTAMP",
"]",
"return",
"FileNotificationService",
"(",
"hass",
",",
"filename",
",",
"timestamp",
")"
] | [
25,
0
] | [
30,
61
] | python | en | ['en', 'en', 'en'] | True |
FileNotificationService.__init__ | (self, hass, filename, add_timestamp) | Initialize the service. | Initialize the service. | def __init__(self, hass, filename, add_timestamp):
"""Initialize the service."""
self.filepath = os.path.join(hass.config.config_dir, filename)
self.add_timestamp = add_timestamp | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"filename",
",",
"add_timestamp",
")",
":",
"self",
".",
"filepath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"hass",
".",
"config",
".",
"config_dir",
",",
"filename",
")",
"self",
".",
"add_timestamp",
"=",
"add_timestamp"
] | [
36,
4
] | [
39,
42
] | python | en | ['en', 'en', 'en'] | True |
FileNotificationService.send_message | (self, message="", **kwargs) | Send a message to a file. | Send a message to a file. | def send_message(self, message="", **kwargs):
"""Send a message to a file."""
with open(self.filepath, "a") as file:
if os.stat(self.filepath).st_size == 0:
title = f"{kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)} notifications (Log started: {dt_util.utcnow().isoformat()})\n{'-' * 80}\n"
file.write(title)
if self.add_timestamp:
text = f"{dt_util.utcnow().isoformat()} {message}\n"
else:
text = f"{message}\n"
file.write(text) | [
"def",
"send_message",
"(",
"self",
",",
"message",
"=",
"\"\"",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"open",
"(",
"self",
".",
"filepath",
",",
"\"a\"",
")",
"as",
"file",
":",
"if",
"os",
".",
"stat",
"(",
"self",
".",
"filepath",
")",
".",
"st_size",
"==",
"0",
":",
"title",
"=",
"f\"{kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)} notifications (Log started: {dt_util.utcnow().isoformat()})\\n{'-' * 80}\\n\"",
"file",
".",
"write",
"(",
"title",
")",
"if",
"self",
".",
"add_timestamp",
":",
"text",
"=",
"f\"{dt_util.utcnow().isoformat()} {message}\\n\"",
"else",
":",
"text",
"=",
"f\"{message}\\n\"",
"file",
".",
"write",
"(",
"text",
")"
] | [
41,
4
] | [
52,
28
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
) | Set up MQTT alarm control panel through configuration.yaml. | Set up MQTT alarm control panel through configuration.yaml. | async def async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
):
"""Set up MQTT alarm control panel through configuration.yaml."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
await _async_setup_entity(hass, config, async_add_entities) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config",
":",
"ConfigType",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"await",
"async_setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"await",
"_async_setup_entity",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
")"
] | [
101,
0
] | [
106,
63
] | python | en | ['en', 'ja', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up MQTT alarm control panel dynamically through MQTT discovery. | Set up MQTT alarm control panel dynamically through MQTT discovery. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up MQTT alarm control panel dynamically through MQTT discovery."""
async def async_discover(discovery_payload):
"""Discover and add an MQTT alarm control panel."""
discovery_data = discovery_payload.discovery_data
try:
config = PLATFORM_SCHEMA(discovery_payload)
await _async_setup_entity(
hass, config, async_add_entities, config_entry, discovery_data
)
except Exception:
clear_discovery_hash(hass, discovery_data[ATTR_DISCOVERY_HASH])
raise
async_dispatcher_connect(
hass, MQTT_DISCOVERY_NEW.format(alarm.DOMAIN, "mqtt"), async_discover
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"async",
"def",
"async_discover",
"(",
"discovery_payload",
")",
":",
"\"\"\"Discover and add an MQTT alarm control panel.\"\"\"",
"discovery_data",
"=",
"discovery_payload",
".",
"discovery_data",
"try",
":",
"config",
"=",
"PLATFORM_SCHEMA",
"(",
"discovery_payload",
")",
"await",
"_async_setup_entity",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"config_entry",
",",
"discovery_data",
")",
"except",
"Exception",
":",
"clear_discovery_hash",
"(",
"hass",
",",
"discovery_data",
"[",
"ATTR_DISCOVERY_HASH",
"]",
")",
"raise",
"async_dispatcher_connect",
"(",
"hass",
",",
"MQTT_DISCOVERY_NEW",
".",
"format",
"(",
"alarm",
".",
"DOMAIN",
",",
"\"mqtt\"",
")",
",",
"async_discover",
")"
] | [
109,
0
] | [
126,
5
] | python | en | ['en', 'en', 'en'] | True |
_async_setup_entity | (
hass, config, async_add_entities, config_entry=None, discovery_data=None
) | Set up the MQTT Alarm Control Panel platform. | Set up the MQTT Alarm Control Panel platform. | async def _async_setup_entity(
hass, config, async_add_entities, config_entry=None, discovery_data=None
):
"""Set up the MQTT Alarm Control Panel platform."""
async_add_entities([MqttAlarm(hass, config, config_entry, discovery_data)]) | [
"async",
"def",
"_async_setup_entity",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"config_entry",
"=",
"None",
",",
"discovery_data",
"=",
"None",
")",
":",
"async_add_entities",
"(",
"[",
"MqttAlarm",
"(",
"hass",
",",
"config",
",",
"config_entry",
",",
"discovery_data",
")",
"]",
")"
] | [
129,
0
] | [
133,
79
] | python | en | ['en', 'ca', 'en'] | True |
MqttAlarm.__init__ | (self, hass, config, config_entry, discovery_data) | Init the MQTT Alarm Control Panel. | Init the MQTT Alarm Control Panel. | def __init__(self, hass, config, config_entry, discovery_data):
"""Init the MQTT Alarm Control Panel."""
self.hass = hass
self._state = None
self._unique_id = config.get(CONF_UNIQUE_ID)
self._sub_state = None
# Load config
self._setup_from_config(config)
device_config = config.get(CONF_DEVICE)
MqttAttributes.__init__(self, config)
MqttAvailability.__init__(self, config)
MqttDiscoveryUpdate.__init__(self, discovery_data, self.discovery_update)
MqttEntityDeviceInfo.__init__(self, device_config, config_entry) | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"config",
",",
"config_entry",
",",
"discovery_data",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_unique_id",
"=",
"config",
".",
"get",
"(",
"CONF_UNIQUE_ID",
")",
"self",
".",
"_sub_state",
"=",
"None",
"# Load config",
"self",
".",
"_setup_from_config",
"(",
"config",
")",
"device_config",
"=",
"config",
".",
"get",
"(",
"CONF_DEVICE",
")",
"MqttAttributes",
".",
"__init__",
"(",
"self",
",",
"config",
")",
"MqttAvailability",
".",
"__init__",
"(",
"self",
",",
"config",
")",
"MqttDiscoveryUpdate",
".",
"__init__",
"(",
"self",
",",
"discovery_data",
",",
"self",
".",
"discovery_update",
")",
"MqttEntityDeviceInfo",
".",
"__init__",
"(",
"self",
",",
"device_config",
",",
"config_entry",
")"
] | [
145,
4
] | [
160,
72
] | python | en | ['en', 'ca', 'en'] | True |
MqttAlarm.async_added_to_hass | (self) | Subscribe mqtt events. | Subscribe mqtt events. | async def async_added_to_hass(self):
"""Subscribe mqtt events."""
await super().async_added_to_hass()
await self._subscribe_topics() | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_added_to_hass",
"(",
")",
"await",
"self",
".",
"_subscribe_topics",
"(",
")"
] | [
162,
4
] | [
165,
38
] | python | en | ['en', 'en', 'it'] | True |
MqttAlarm.discovery_update | (self, discovery_payload) | Handle updated discovery message. | Handle updated discovery message. | async def discovery_update(self, discovery_payload):
"""Handle updated discovery message."""
config = PLATFORM_SCHEMA(discovery_payload)
self._setup_from_config(config)
await self.attributes_discovery_update(config)
await self.availability_discovery_update(config)
await self.device_info_discovery_update(config)
await self._subscribe_topics()
self.async_write_ha_state() | [
"async",
"def",
"discovery_update",
"(",
"self",
",",
"discovery_payload",
")",
":",
"config",
"=",
"PLATFORM_SCHEMA",
"(",
"discovery_payload",
")",
"self",
".",
"_setup_from_config",
"(",
"config",
")",
"await",
"self",
".",
"attributes_discovery_update",
"(",
"config",
")",
"await",
"self",
".",
"availability_discovery_update",
"(",
"config",
")",
"await",
"self",
".",
"device_info_discovery_update",
"(",
"config",
")",
"await",
"self",
".",
"_subscribe_topics",
"(",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
167,
4
] | [
175,
35
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm._subscribe_topics | (self) | (Re)Subscribe to topics. | (Re)Subscribe to topics. | async def _subscribe_topics(self):
"""(Re)Subscribe to topics."""
@callback
@log_messages(self.hass, self.entity_id)
def message_received(msg):
"""Run when new MQTT message has been received."""
payload = msg.payload
value_template = self._config.get(CONF_VALUE_TEMPLATE)
if value_template is not None:
payload = value_template.async_render_with_possible_json_value(
msg.payload, self._state
)
if payload not in (
STATE_ALARM_DISARMED,
STATE_ALARM_ARMED_HOME,
STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_NIGHT,
STATE_ALARM_ARMED_CUSTOM_BYPASS,
STATE_ALARM_PENDING,
STATE_ALARM_ARMING,
STATE_ALARM_DISARMING,
STATE_ALARM_TRIGGERED,
):
_LOGGER.warning("Received unexpected payload: %s", msg.payload)
return
self._state = payload
self.async_write_ha_state()
self._sub_state = await subscription.async_subscribe_topics(
self.hass,
self._sub_state,
{
"state_topic": {
"topic": self._config[CONF_STATE_TOPIC],
"msg_callback": message_received,
"qos": self._config[CONF_QOS],
}
},
) | [
"async",
"def",
"_subscribe_topics",
"(",
"self",
")",
":",
"@",
"callback",
"@",
"log_messages",
"(",
"self",
".",
"hass",
",",
"self",
".",
"entity_id",
")",
"def",
"message_received",
"(",
"msg",
")",
":",
"\"\"\"Run when new MQTT message has been received.\"\"\"",
"payload",
"=",
"msg",
".",
"payload",
"value_template",
"=",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_VALUE_TEMPLATE",
")",
"if",
"value_template",
"is",
"not",
"None",
":",
"payload",
"=",
"value_template",
".",
"async_render_with_possible_json_value",
"(",
"msg",
".",
"payload",
",",
"self",
".",
"_state",
")",
"if",
"payload",
"not",
"in",
"(",
"STATE_ALARM_DISARMED",
",",
"STATE_ALARM_ARMED_HOME",
",",
"STATE_ALARM_ARMED_AWAY",
",",
"STATE_ALARM_ARMED_NIGHT",
",",
"STATE_ALARM_ARMED_CUSTOM_BYPASS",
",",
"STATE_ALARM_PENDING",
",",
"STATE_ALARM_ARMING",
",",
"STATE_ALARM_DISARMING",
",",
"STATE_ALARM_TRIGGERED",
",",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Received unexpected payload: %s\"",
",",
"msg",
".",
"payload",
")",
"return",
"self",
".",
"_state",
"=",
"payload",
"self",
".",
"async_write_ha_state",
"(",
")",
"self",
".",
"_sub_state",
"=",
"await",
"subscription",
".",
"async_subscribe_topics",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_sub_state",
",",
"{",
"\"state_topic\"",
":",
"{",
"\"topic\"",
":",
"self",
".",
"_config",
"[",
"CONF_STATE_TOPIC",
"]",
",",
"\"msg_callback\"",
":",
"message_received",
",",
"\"qos\"",
":",
"self",
".",
"_config",
"[",
"CONF_QOS",
"]",
",",
"}",
"}",
",",
")"
] | [
185,
4
] | [
224,
9
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.async_will_remove_from_hass | (self) | Unsubscribe when removed. | Unsubscribe when removed. | async def async_will_remove_from_hass(self):
"""Unsubscribe when removed."""
self._sub_state = await subscription.async_unsubscribe_topics(
self.hass, self._sub_state
)
await MqttAttributes.async_will_remove_from_hass(self)
await MqttAvailability.async_will_remove_from_hass(self)
await MqttDiscoveryUpdate.async_will_remove_from_hass(self) | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"self",
".",
"_sub_state",
"=",
"await",
"subscription",
".",
"async_unsubscribe_topics",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_sub_state",
")",
"await",
"MqttAttributes",
".",
"async_will_remove_from_hass",
"(",
"self",
")",
"await",
"MqttAvailability",
".",
"async_will_remove_from_hass",
"(",
"self",
")",
"await",
"MqttDiscoveryUpdate",
".",
"async_will_remove_from_hass",
"(",
"self",
")"
] | [
226,
4
] | [
233,
67
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.should_poll | (self) | No polling needed. | No polling needed. | def should_poll(self):
"""No polling needed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
236,
4
] | [
238,
20
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.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._config[CONF_NAME] | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_config",
"[",
"CONF_NAME",
"]"
] | [
241,
4
] | [
243,
38
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self):
"""Return a unique ID."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
246,
4
] | [
248,
30
] | python | ca | ['fr', 'ca', 'en'] | False |
MqttAlarm.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"
] | [
251,
4
] | [
253,
26
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self) -> int:
"""Return the list of supported features."""
return (
SUPPORT_ALARM_ARM_HOME
| SUPPORT_ALARM_ARM_AWAY
| SUPPORT_ALARM_ARM_NIGHT
| SUPPORT_ALARM_ARM_CUSTOM_BYPASS
) | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"(",
"SUPPORT_ALARM_ARM_HOME",
"|",
"SUPPORT_ALARM_ARM_AWAY",
"|",
"SUPPORT_ALARM_ARM_NIGHT",
"|",
"SUPPORT_ALARM_ARM_CUSTOM_BYPASS",
")"
] | [
256,
4
] | [
263,
9
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.code_format | (self) | Return one or more digits/characters. | Return one or more digits/characters. | def code_format(self):
"""Return one or more digits/characters."""
code = self._config.get(CONF_CODE)
if code is None:
return None
if isinstance(code, str) and re.search("^\\d+$", code):
return alarm.FORMAT_NUMBER
return alarm.FORMAT_TEXT | [
"def",
"code_format",
"(",
"self",
")",
":",
"code",
"=",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_CODE",
")",
"if",
"code",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"code",
",",
"str",
")",
"and",
"re",
".",
"search",
"(",
"\"^\\\\d+$\"",
",",
"code",
")",
":",
"return",
"alarm",
".",
"FORMAT_NUMBER",
"return",
"alarm",
".",
"FORMAT_TEXT"
] | [
266,
4
] | [
273,
32
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.code_arm_required | (self) | Whether the code is required for arm actions. | Whether the code is required for arm actions. | def code_arm_required(self):
"""Whether the code is required for arm actions."""
code_required = self._config.get(CONF_CODE_ARM_REQUIRED)
return code_required | [
"def",
"code_arm_required",
"(",
"self",
")",
":",
"code_required",
"=",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_CODE_ARM_REQUIRED",
")",
"return",
"code_required"
] | [
276,
4
] | [
279,
28
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.async_alarm_disarm | (self, code=None) | Send disarm command.
This method is a coroutine.
| Send disarm command. | async def async_alarm_disarm(self, code=None):
"""Send disarm command.
This method is a coroutine.
"""
code_required = self._config[CONF_CODE_DISARM_REQUIRED]
if code_required and not self._validate_code(code, "disarming"):
return
payload = self._config[CONF_PAYLOAD_DISARM]
self._publish(code, payload) | [
"async",
"def",
"async_alarm_disarm",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"code_required",
"=",
"self",
".",
"_config",
"[",
"CONF_CODE_DISARM_REQUIRED",
"]",
"if",
"code_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"\"disarming\"",
")",
":",
"return",
"payload",
"=",
"self",
".",
"_config",
"[",
"CONF_PAYLOAD_DISARM",
"]",
"self",
".",
"_publish",
"(",
"code",
",",
"payload",
")"
] | [
281,
4
] | [
290,
36
] | python | en | ['en', 'pt', 'en'] | True |
MqttAlarm.async_alarm_arm_home | (self, code=None) | Send arm home command.
This method is a coroutine.
| Send arm home command. | async def async_alarm_arm_home(self, code=None):
"""Send arm home command.
This method is a coroutine.
"""
code_required = self._config[CONF_CODE_ARM_REQUIRED]
if code_required and not self._validate_code(code, "arming home"):
return
action = self._config[CONF_PAYLOAD_ARM_HOME]
self._publish(code, action) | [
"async",
"def",
"async_alarm_arm_home",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"code_required",
"=",
"self",
".",
"_config",
"[",
"CONF_CODE_ARM_REQUIRED",
"]",
"if",
"code_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"\"arming home\"",
")",
":",
"return",
"action",
"=",
"self",
".",
"_config",
"[",
"CONF_PAYLOAD_ARM_HOME",
"]",
"self",
".",
"_publish",
"(",
"code",
",",
"action",
")"
] | [
292,
4
] | [
301,
35
] | python | en | ['en', 'pt', 'en'] | True |
MqttAlarm.async_alarm_arm_away | (self, code=None) | Send arm away command.
This method is a coroutine.
| Send arm away command. | async def async_alarm_arm_away(self, code=None):
"""Send arm away command.
This method is a coroutine.
"""
code_required = self._config[CONF_CODE_ARM_REQUIRED]
if code_required and not self._validate_code(code, "arming away"):
return
action = self._config[CONF_PAYLOAD_ARM_AWAY]
self._publish(code, action) | [
"async",
"def",
"async_alarm_arm_away",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"code_required",
"=",
"self",
".",
"_config",
"[",
"CONF_CODE_ARM_REQUIRED",
"]",
"if",
"code_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"\"arming away\"",
")",
":",
"return",
"action",
"=",
"self",
".",
"_config",
"[",
"CONF_PAYLOAD_ARM_AWAY",
"]",
"self",
".",
"_publish",
"(",
"code",
",",
"action",
")"
] | [
303,
4
] | [
312,
35
] | python | en | ['en', 'en', 'en'] | True |
MqttAlarm.async_alarm_arm_night | (self, code=None) | Send arm night command.
This method is a coroutine.
| Send arm night command. | async def async_alarm_arm_night(self, code=None):
"""Send arm night command.
This method is a coroutine.
"""
code_required = self._config[CONF_CODE_ARM_REQUIRED]
if code_required and not self._validate_code(code, "arming night"):
return
action = self._config[CONF_PAYLOAD_ARM_NIGHT]
self._publish(code, action) | [
"async",
"def",
"async_alarm_arm_night",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"code_required",
"=",
"self",
".",
"_config",
"[",
"CONF_CODE_ARM_REQUIRED",
"]",
"if",
"code_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"\"arming night\"",
")",
":",
"return",
"action",
"=",
"self",
".",
"_config",
"[",
"CONF_PAYLOAD_ARM_NIGHT",
"]",
"self",
".",
"_publish",
"(",
"code",
",",
"action",
")"
] | [
314,
4
] | [
323,
35
] | python | en | ['en', 'zh', 'en'] | True |
MqttAlarm.async_alarm_arm_custom_bypass | (self, code=None) | Send arm custom bypass command.
This method is a coroutine.
| Send arm custom bypass command. | async def async_alarm_arm_custom_bypass(self, code=None):
"""Send arm custom bypass command.
This method is a coroutine.
"""
code_required = self._config[CONF_CODE_ARM_REQUIRED]
if code_required and not self._validate_code(code, "arming custom bypass"):
return
action = self._config[CONF_PAYLOAD_ARM_CUSTOM_BYPASS]
self._publish(code, action) | [
"async",
"def",
"async_alarm_arm_custom_bypass",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"code_required",
"=",
"self",
".",
"_config",
"[",
"CONF_CODE_ARM_REQUIRED",
"]",
"if",
"code_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"\"arming custom bypass\"",
")",
":",
"return",
"action",
"=",
"self",
".",
"_config",
"[",
"CONF_PAYLOAD_ARM_CUSTOM_BYPASS",
"]",
"self",
".",
"_publish",
"(",
"code",
",",
"action",
")"
] | [
325,
4
] | [
334,
35
] | python | en | ['en', 'ga', 'en'] | True |
MqttAlarm._publish | (self, code, action) | Publish via mqtt. | Publish via mqtt. | def _publish(self, code, action):
"""Publish via mqtt."""
command_template = self._config[CONF_COMMAND_TEMPLATE]
values = {"action": action, "code": code}
payload = command_template.async_render(**values, parse_result=False)
mqtt.async_publish(
self.hass,
self._config[CONF_COMMAND_TOPIC],
payload,
self._config[CONF_QOS],
self._config[CONF_RETAIN],
) | [
"def",
"_publish",
"(",
"self",
",",
"code",
",",
"action",
")",
":",
"command_template",
"=",
"self",
".",
"_config",
"[",
"CONF_COMMAND_TEMPLATE",
"]",
"values",
"=",
"{",
"\"action\"",
":",
"action",
",",
"\"code\"",
":",
"code",
"}",
"payload",
"=",
"command_template",
".",
"async_render",
"(",
"*",
"*",
"values",
",",
"parse_result",
"=",
"False",
")",
"mqtt",
".",
"async_publish",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_config",
"[",
"CONF_COMMAND_TOPIC",
"]",
",",
"payload",
",",
"self",
".",
"_config",
"[",
"CONF_QOS",
"]",
",",
"self",
".",
"_config",
"[",
"CONF_RETAIN",
"]",
",",
")"
] | [
336,
4
] | [
347,
9
] | python | ca | ['sv', 'ca', 'it'] | False |
MqttAlarm._validate_code | (self, code, state) | Validate given code. | Validate given code. | def _validate_code(self, code, state):
"""Validate given code."""
conf_code = self._config.get(CONF_CODE)
check = conf_code is None or code == conf_code
if not check:
_LOGGER.warning("Wrong code entered for %s", state)
return check | [
"def",
"_validate_code",
"(",
"self",
",",
"code",
",",
"state",
")",
":",
"conf_code",
"=",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_CODE",
")",
"check",
"=",
"conf_code",
"is",
"None",
"or",
"code",
"==",
"conf_code",
"if",
"not",
"check",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Wrong code entered for %s\"",
",",
"state",
")",
"return",
"check"
] | [
349,
4
] | [
355,
20
] | python | en | ['en', 'en', 'en'] | True |
TestUVCSetup.setUp | (self) | Set up things to be run when tests are started. | Set up things to be run when tests are started. | def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.hass.stop) | [
"def",
"setUp",
"(",
"self",
")",
":",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"addCleanup",
"(",
"self",
".",
"hass",
".",
"stop",
")"
] | [
20,
4
] | [
23,
39
] | python | en | ['en', 'en', 'en'] | True |
TestUVCSetup.test_setup_full_config | (self, mock_uvc, mock_remote) | Test the setup with full configuration. | Test the setup with full configuration. | def test_setup_full_config(self, mock_uvc, mock_remote):
"""Test the setup with full configuration."""
config = {
"platform": "uvc",
"nvr": "foo",
"password": "bar",
"port": 123,
"key": "secret",
}
mock_cameras = [
{"uuid": "one", "name": "Front", "id": "id1"},
{"uuid": "two", "name": "Back", "id": "id2"},
{"uuid": "three", "name": "Old AirCam", "id": "id3"},
]
def mock_get_camera(uuid):
"""Create a mock camera."""
if uuid == "id3":
return {"model": "airCam"}
return {"model": "UVC"}
mock_remote.return_value.index.return_value = mock_cameras
mock_remote.return_value.get_camera.side_effect = mock_get_camera
mock_remote.return_value.server_version = (3, 2, 0)
assert setup_component(self.hass, "camera", {"camera": config})
self.hass.block_till_done()
assert mock_remote.call_count == 1
assert mock_remote.call_args == mock.call("foo", 123, "secret", ssl=False)
mock_uvc.assert_has_calls(
[
mock.call(mock_remote.return_value, "id1", "Front", "bar"),
mock.call(mock_remote.return_value, "id2", "Back", "bar"),
]
) | [
"def",
"test_setup_full_config",
"(",
"self",
",",
"mock_uvc",
",",
"mock_remote",
")",
":",
"config",
"=",
"{",
"\"platform\"",
":",
"\"uvc\"",
",",
"\"nvr\"",
":",
"\"foo\"",
",",
"\"password\"",
":",
"\"bar\"",
",",
"\"port\"",
":",
"123",
",",
"\"key\"",
":",
"\"secret\"",
",",
"}",
"mock_cameras",
"=",
"[",
"{",
"\"uuid\"",
":",
"\"one\"",
",",
"\"name\"",
":",
"\"Front\"",
",",
"\"id\"",
":",
"\"id1\"",
"}",
",",
"{",
"\"uuid\"",
":",
"\"two\"",
",",
"\"name\"",
":",
"\"Back\"",
",",
"\"id\"",
":",
"\"id2\"",
"}",
",",
"{",
"\"uuid\"",
":",
"\"three\"",
",",
"\"name\"",
":",
"\"Old AirCam\"",
",",
"\"id\"",
":",
"\"id3\"",
"}",
",",
"]",
"def",
"mock_get_camera",
"(",
"uuid",
")",
":",
"\"\"\"Create a mock camera.\"\"\"",
"if",
"uuid",
"==",
"\"id3\"",
":",
"return",
"{",
"\"model\"",
":",
"\"airCam\"",
"}",
"return",
"{",
"\"model\"",
":",
"\"UVC\"",
"}",
"mock_remote",
".",
"return_value",
".",
"index",
".",
"return_value",
"=",
"mock_cameras",
"mock_remote",
".",
"return_value",
".",
"get_camera",
".",
"side_effect",
"=",
"mock_get_camera",
"mock_remote",
".",
"return_value",
".",
"server_version",
"=",
"(",
"3",
",",
"2",
",",
"0",
")",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"camera\"",
",",
"{",
"\"camera\"",
":",
"config",
"}",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"mock_remote",
".",
"call_count",
"==",
"1",
"assert",
"mock_remote",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
"\"foo\"",
",",
"123",
",",
"\"secret\"",
",",
"ssl",
"=",
"False",
")",
"mock_uvc",
".",
"assert_has_calls",
"(",
"[",
"mock",
".",
"call",
"(",
"mock_remote",
".",
"return_value",
",",
"\"id1\"",
",",
"\"Front\"",
",",
"\"bar\"",
")",
",",
"mock",
".",
"call",
"(",
"mock_remote",
".",
"return_value",
",",
"\"id2\"",
",",
"\"Back\"",
",",
"\"bar\"",
")",
",",
"]",
")"
] | [
27,
4
] | [
62,
9
] | python | en | ['en', 'en', 'en'] | True |
TestUVCSetup.test_setup_partial_config | (self, mock_uvc, mock_remote) | Test the setup with partial configuration. | Test the setup with partial configuration. | def test_setup_partial_config(self, mock_uvc, mock_remote):
"""Test the setup with partial configuration."""
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
mock_cameras = [
{"uuid": "one", "name": "Front", "id": "id1"},
{"uuid": "two", "name": "Back", "id": "id2"},
]
mock_remote.return_value.index.return_value = mock_cameras
mock_remote.return_value.get_camera.return_value = {"model": "UVC"}
mock_remote.return_value.server_version = (3, 2, 0)
assert setup_component(self.hass, "camera", {"camera": config})
self.hass.block_till_done()
assert mock_remote.call_count == 1
assert mock_remote.call_args == mock.call("foo", 7080, "secret", ssl=False)
mock_uvc.assert_has_calls(
[
mock.call(mock_remote.return_value, "id1", "Front", "ubnt"),
mock.call(mock_remote.return_value, "id2", "Back", "ubnt"),
]
) | [
"def",
"test_setup_partial_config",
"(",
"self",
",",
"mock_uvc",
",",
"mock_remote",
")",
":",
"config",
"=",
"{",
"\"platform\"",
":",
"\"uvc\"",
",",
"\"nvr\"",
":",
"\"foo\"",
",",
"\"key\"",
":",
"\"secret\"",
"}",
"mock_cameras",
"=",
"[",
"{",
"\"uuid\"",
":",
"\"one\"",
",",
"\"name\"",
":",
"\"Front\"",
",",
"\"id\"",
":",
"\"id1\"",
"}",
",",
"{",
"\"uuid\"",
":",
"\"two\"",
",",
"\"name\"",
":",
"\"Back\"",
",",
"\"id\"",
":",
"\"id2\"",
"}",
",",
"]",
"mock_remote",
".",
"return_value",
".",
"index",
".",
"return_value",
"=",
"mock_cameras",
"mock_remote",
".",
"return_value",
".",
"get_camera",
".",
"return_value",
"=",
"{",
"\"model\"",
":",
"\"UVC\"",
"}",
"mock_remote",
".",
"return_value",
".",
"server_version",
"=",
"(",
"3",
",",
"2",
",",
"0",
")",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"camera\"",
",",
"{",
"\"camera\"",
":",
"config",
"}",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"mock_remote",
".",
"call_count",
"==",
"1",
"assert",
"mock_remote",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
"\"foo\"",
",",
"7080",
",",
"\"secret\"",
",",
"ssl",
"=",
"False",
")",
"mock_uvc",
".",
"assert_has_calls",
"(",
"[",
"mock",
".",
"call",
"(",
"mock_remote",
".",
"return_value",
",",
"\"id1\"",
",",
"\"Front\"",
",",
"\"ubnt\"",
")",
",",
"mock",
".",
"call",
"(",
"mock_remote",
".",
"return_value",
",",
"\"id2\"",
",",
"\"Back\"",
",",
"\"ubnt\"",
")",
",",
"]",
")"
] | [
66,
4
] | [
87,
9
] | python | en | ['en', 'en', 'en'] | True |
TestUVCSetup.test_setup_partial_config_v31x | (self, mock_uvc, mock_remote) | Test the setup with a v3.1.x server. | Test the setup with a v3.1.x server. | def test_setup_partial_config_v31x(self, mock_uvc, mock_remote):
"""Test the setup with a v3.1.x server."""
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
mock_cameras = [
{"uuid": "one", "name": "Front", "id": "id1"},
{"uuid": "two", "name": "Back", "id": "id2"},
]
mock_remote.return_value.index.return_value = mock_cameras
mock_remote.return_value.get_camera.return_value = {"model": "UVC"}
mock_remote.return_value.server_version = (3, 1, 3)
assert setup_component(self.hass, "camera", {"camera": config})
self.hass.block_till_done()
assert mock_remote.call_count == 1
assert mock_remote.call_args == mock.call("foo", 7080, "secret", ssl=False)
mock_uvc.assert_has_calls(
[
mock.call(mock_remote.return_value, "one", "Front", "ubnt"),
mock.call(mock_remote.return_value, "two", "Back", "ubnt"),
]
) | [
"def",
"test_setup_partial_config_v31x",
"(",
"self",
",",
"mock_uvc",
",",
"mock_remote",
")",
":",
"config",
"=",
"{",
"\"platform\"",
":",
"\"uvc\"",
",",
"\"nvr\"",
":",
"\"foo\"",
",",
"\"key\"",
":",
"\"secret\"",
"}",
"mock_cameras",
"=",
"[",
"{",
"\"uuid\"",
":",
"\"one\"",
",",
"\"name\"",
":",
"\"Front\"",
",",
"\"id\"",
":",
"\"id1\"",
"}",
",",
"{",
"\"uuid\"",
":",
"\"two\"",
",",
"\"name\"",
":",
"\"Back\"",
",",
"\"id\"",
":",
"\"id2\"",
"}",
",",
"]",
"mock_remote",
".",
"return_value",
".",
"index",
".",
"return_value",
"=",
"mock_cameras",
"mock_remote",
".",
"return_value",
".",
"get_camera",
".",
"return_value",
"=",
"{",
"\"model\"",
":",
"\"UVC\"",
"}",
"mock_remote",
".",
"return_value",
".",
"server_version",
"=",
"(",
"3",
",",
"1",
",",
"3",
")",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"camera\"",
",",
"{",
"\"camera\"",
":",
"config",
"}",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"mock_remote",
".",
"call_count",
"==",
"1",
"assert",
"mock_remote",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
"\"foo\"",
",",
"7080",
",",
"\"secret\"",
",",
"ssl",
"=",
"False",
")",
"mock_uvc",
".",
"assert_has_calls",
"(",
"[",
"mock",
".",
"call",
"(",
"mock_remote",
".",
"return_value",
",",
"\"one\"",
",",
"\"Front\"",
",",
"\"ubnt\"",
")",
",",
"mock",
".",
"call",
"(",
"mock_remote",
".",
"return_value",
",",
"\"two\"",
",",
"\"Back\"",
",",
"\"ubnt\"",
")",
",",
"]",
")"
] | [
91,
4
] | [
112,
9
] | python | en | ['en', 'pt', 'en'] | True |
TestUVCSetup.test_setup_incomplete_config | (self, mock_uvc) | Test the setup with incomplete configuration. | Test the setup with incomplete configuration. | def test_setup_incomplete_config(self, mock_uvc):
"""Test the setup with incomplete configuration."""
assert setup_component(self.hass, "camera", {"platform": "uvc", "nvr": "foo"})
self.hass.block_till_done()
assert not mock_uvc.called
assert setup_component(
self.hass, "camera", {"platform": "uvc", "key": "secret"}
)
self.hass.block_till_done()
assert not mock_uvc.called
assert setup_component(
self.hass, "camera", {"platform": "uvc", "port": "invalid"}
)
self.hass.block_till_done()
assert not mock_uvc.called | [
"def",
"test_setup_incomplete_config",
"(",
"self",
",",
"mock_uvc",
")",
":",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"camera\"",
",",
"{",
"\"platform\"",
":",
"\"uvc\"",
",",
"\"nvr\"",
":",
"\"foo\"",
"}",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"not",
"mock_uvc",
".",
"called",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"camera\"",
",",
"{",
"\"platform\"",
":",
"\"uvc\"",
",",
"\"key\"",
":",
"\"secret\"",
"}",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"not",
"mock_uvc",
".",
"called",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"camera\"",
",",
"{",
"\"platform\"",
":",
"\"uvc\"",
",",
"\"port\"",
":",
"\"invalid\"",
"}",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"not",
"mock_uvc",
".",
"called"
] | [
115,
4
] | [
132,
34
] | python | en | ['en', 'en', 'en'] | True |
TestUVCSetup.setup_nvr_errors_during_indexing | (self, error, mock_remote, mock_uvc) | Set up test for NVR errors during indexing. | Set up test for NVR errors during indexing. | def setup_nvr_errors_during_indexing(self, error, mock_remote, mock_uvc):
"""Set up test for NVR errors during indexing."""
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
mock_remote.return_value.index.side_effect = error
assert setup_component(self.hass, "camera", {"camera": config})
self.hass.block_till_done()
assert not mock_uvc.called | [
"def",
"setup_nvr_errors_during_indexing",
"(",
"self",
",",
"error",
",",
"mock_remote",
",",
"mock_uvc",
")",
":",
"config",
"=",
"{",
"\"platform\"",
":",
"\"uvc\"",
",",
"\"nvr\"",
":",
"\"foo\"",
",",
"\"key\"",
":",
"\"secret\"",
"}",
"mock_remote",
".",
"return_value",
".",
"index",
".",
"side_effect",
"=",
"error",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"camera\"",
",",
"{",
"\"camera\"",
":",
"config",
"}",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"not",
"mock_uvc",
".",
"called"
] | [
136,
4
] | [
143,
34
] | python | en | ['en', 'en', 'en'] | True |
TestUVCSetup.test_setup_nvr_error_during_indexing_notauthorized | (self) | Test for error: nvr.NotAuthorized. | Test for error: nvr.NotAuthorized. | def test_setup_nvr_error_during_indexing_notauthorized(self):
"""Test for error: nvr.NotAuthorized."""
self.setup_nvr_errors_during_indexing(nvr.NotAuthorized) | [
"def",
"test_setup_nvr_error_during_indexing_notauthorized",
"(",
"self",
")",
":",
"self",
".",
"setup_nvr_errors_during_indexing",
"(",
"nvr",
".",
"NotAuthorized",
")"
] | [
145,
4
] | [
147,
64
] | python | en | ['da', 'en', 'en'] | True |
TestUVCSetup.test_setup_nvr_error_during_indexing_nvrerror | (self) | Test for error: nvr.NvrError. | Test for error: nvr.NvrError. | def test_setup_nvr_error_during_indexing_nvrerror(self):
"""Test for error: nvr.NvrError."""
self.setup_nvr_errors_during_indexing(nvr.NvrError)
pytest.raises(PlatformNotReady) | [
"def",
"test_setup_nvr_error_during_indexing_nvrerror",
"(",
"self",
")",
":",
"self",
".",
"setup_nvr_errors_during_indexing",
"(",
"nvr",
".",
"NvrError",
")",
"pytest",
".",
"raises",
"(",
"PlatformNotReady",
")"
] | [
149,
4
] | [
152,
39
] | python | da | ['da', 'no', 'hi'] | False |
TestUVCSetup.test_setup_nvr_error_during_indexing_connectionerror | (self) | Test for error: requests.exceptions.ConnectionError. | Test for error: requests.exceptions.ConnectionError. | def test_setup_nvr_error_during_indexing_connectionerror(self):
"""Test for error: requests.exceptions.ConnectionError."""
self.setup_nvr_errors_during_indexing(requests.exceptions.ConnectionError)
pytest.raises(PlatformNotReady) | [
"def",
"test_setup_nvr_error_during_indexing_connectionerror",
"(",
"self",
")",
":",
"self",
".",
"setup_nvr_errors_during_indexing",
"(",
"requests",
".",
"exceptions",
".",
"ConnectionError",
")",
"pytest",
".",
"raises",
"(",
"PlatformNotReady",
")"
] | [
154,
4
] | [
157,
39
] | python | en | ['da', 'en', 'en'] | True |
TestUVCSetup.setup_nvr_errors_during_initialization | (self, error, mock_remote, mock_uvc) | Set up test for NVR errors during initialization. | Set up test for NVR errors during initialization. | def setup_nvr_errors_during_initialization(self, error, mock_remote, mock_uvc):
"""Set up test for NVR errors during initialization."""
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
mock_remote.return_value = None
mock_remote.side_effect = error
assert setup_component(self.hass, "camera", {"camera": config})
self.hass.block_till_done()
assert not mock_remote.index.called
assert not mock_uvc.called | [
"def",
"setup_nvr_errors_during_initialization",
"(",
"self",
",",
"error",
",",
"mock_remote",
",",
"mock_uvc",
")",
":",
"config",
"=",
"{",
"\"platform\"",
":",
"\"uvc\"",
",",
"\"nvr\"",
":",
"\"foo\"",
",",
"\"key\"",
":",
"\"secret\"",
"}",
"mock_remote",
".",
"return_value",
"=",
"None",
"mock_remote",
".",
"side_effect",
"=",
"error",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"camera\"",
",",
"{",
"\"camera\"",
":",
"config",
"}",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"not",
"mock_remote",
".",
"index",
".",
"called",
"assert",
"not",
"mock_uvc",
".",
"called"
] | [
161,
4
] | [
170,
34
] | python | en | ['en', 'en', 'en'] | True |
TestUVCSetup.test_setup_nvr_error_during_initialization_notauthorized | (self) | Test for error: nvr.NotAuthorized. | Test for error: nvr.NotAuthorized. | def test_setup_nvr_error_during_initialization_notauthorized(self):
"""Test for error: nvr.NotAuthorized."""
self.setup_nvr_errors_during_initialization(nvr.NotAuthorized) | [
"def",
"test_setup_nvr_error_during_initialization_notauthorized",
"(",
"self",
")",
":",
"self",
".",
"setup_nvr_errors_during_initialization",
"(",
"nvr",
".",
"NotAuthorized",
")"
] | [
172,
4
] | [
174,
70
] | python | en | ['da', 'en', 'en'] | True |
TestUVCSetup.test_setup_nvr_error_during_initialization_nvrerror | (self) | Test for error: nvr.NvrError. | Test for error: nvr.NvrError. | def test_setup_nvr_error_during_initialization_nvrerror(self):
"""Test for error: nvr.NvrError."""
self.setup_nvr_errors_during_initialization(nvr.NvrError)
pytest.raises(PlatformNotReady) | [
"def",
"test_setup_nvr_error_during_initialization_nvrerror",
"(",
"self",
")",
":",
"self",
".",
"setup_nvr_errors_during_initialization",
"(",
"nvr",
".",
"NvrError",
")",
"pytest",
".",
"raises",
"(",
"PlatformNotReady",
")"
] | [
176,
4
] | [
179,
39
] | python | da | ['da', 'no', 'hi'] | False |
TestUVCSetup.test_setup_nvr_error_during_initialization_connectionerror | (self) | Test for error: requests.exceptions.ConnectionError. | Test for error: requests.exceptions.ConnectionError. | def test_setup_nvr_error_during_initialization_connectionerror(self):
"""Test for error: requests.exceptions.ConnectionError."""
self.setup_nvr_errors_during_initialization(requests.exceptions.ConnectionError)
pytest.raises(PlatformNotReady) | [
"def",
"test_setup_nvr_error_during_initialization_connectionerror",
"(",
"self",
")",
":",
"self",
".",
"setup_nvr_errors_during_initialization",
"(",
"requests",
".",
"exceptions",
".",
"ConnectionError",
")",
"pytest",
".",
"raises",
"(",
"PlatformNotReady",
")"
] | [
181,
4
] | [
184,
39
] | python | en | ['da', 'en', 'en'] | True |
TestUVC.setup_method | (self, method) | Set up the mock camera. | Set up the mock camera. | def setup_method(self, method):
"""Set up the mock camera."""
self.nvr = mock.MagicMock()
self.uuid = "uuid"
self.name = "name"
self.password = "seekret"
self.uvc = uvc.UnifiVideoCamera(self.nvr, self.uuid, self.name, self.password)
self.nvr.get_camera.return_value = {
"model": "UVC Fake",
"recordingSettings": {"fullTimeRecordEnabled": True},
"host": "host-a",
"internalHost": "host-b",
"username": "admin",
"channels": [
{
"id": "0",
"width": 1920,
"height": 1080,
"fps": 25,
"bitrate": 6000000,
"isRtspEnabled": True,
"rtspUris": [
"rtsp://host-a:7447/uuid_rtspchannel_0",
"rtsp://foo:7447/uuid_rtspchannel_0",
],
},
{
"id": "1",
"width": 1024,
"height": 576,
"fps": 15,
"bitrate": 1200000,
"isRtspEnabled": False,
"rtspUris": [
"rtsp://host-a:7447/uuid_rtspchannel_1",
"rtsp://foo:7447/uuid_rtspchannel_1",
],
},
],
}
self.nvr.server_version = (3, 2, 0)
self.uvc.update() | [
"def",
"setup_method",
"(",
"self",
",",
"method",
")",
":",
"self",
".",
"nvr",
"=",
"mock",
".",
"MagicMock",
"(",
")",
"self",
".",
"uuid",
"=",
"\"uuid\"",
"self",
".",
"name",
"=",
"\"name\"",
"self",
".",
"password",
"=",
"\"seekret\"",
"self",
".",
"uvc",
"=",
"uvc",
".",
"UnifiVideoCamera",
"(",
"self",
".",
"nvr",
",",
"self",
".",
"uuid",
",",
"self",
".",
"name",
",",
"self",
".",
"password",
")",
"self",
".",
"nvr",
".",
"get_camera",
".",
"return_value",
"=",
"{",
"\"model\"",
":",
"\"UVC Fake\"",
",",
"\"recordingSettings\"",
":",
"{",
"\"fullTimeRecordEnabled\"",
":",
"True",
"}",
",",
"\"host\"",
":",
"\"host-a\"",
",",
"\"internalHost\"",
":",
"\"host-b\"",
",",
"\"username\"",
":",
"\"admin\"",
",",
"\"channels\"",
":",
"[",
"{",
"\"id\"",
":",
"\"0\"",
",",
"\"width\"",
":",
"1920",
",",
"\"height\"",
":",
"1080",
",",
"\"fps\"",
":",
"25",
",",
"\"bitrate\"",
":",
"6000000",
",",
"\"isRtspEnabled\"",
":",
"True",
",",
"\"rtspUris\"",
":",
"[",
"\"rtsp://host-a:7447/uuid_rtspchannel_0\"",
",",
"\"rtsp://foo:7447/uuid_rtspchannel_0\"",
",",
"]",
",",
"}",
",",
"{",
"\"id\"",
":",
"\"1\"",
",",
"\"width\"",
":",
"1024",
",",
"\"height\"",
":",
"576",
",",
"\"fps\"",
":",
"15",
",",
"\"bitrate\"",
":",
"1200000",
",",
"\"isRtspEnabled\"",
":",
"False",
",",
"\"rtspUris\"",
":",
"[",
"\"rtsp://host-a:7447/uuid_rtspchannel_1\"",
",",
"\"rtsp://foo:7447/uuid_rtspchannel_1\"",
",",
"]",
",",
"}",
",",
"]",
",",
"}",
"self",
".",
"nvr",
".",
"server_version",
"=",
"(",
"3",
",",
"2",
",",
"0",
")",
"self",
".",
"uvc",
".",
"update",
"(",
")"
] | [
190,
4
] | [
231,
25
] | python | en | ['en', 'da', 'en'] | True |
TestUVC.test_properties | (self) | Test the properties. | Test the properties. | def test_properties(self):
"""Test the properties."""
assert self.name == self.uvc.name
assert self.uvc.is_recording
assert "Ubiquiti" == self.uvc.brand
assert "UVC Fake" == self.uvc.model
assert SUPPORT_STREAM == self.uvc.supported_features | [
"def",
"test_properties",
"(",
"self",
")",
":",
"assert",
"self",
".",
"name",
"==",
"self",
".",
"uvc",
".",
"name",
"assert",
"self",
".",
"uvc",
".",
"is_recording",
"assert",
"\"Ubiquiti\"",
"==",
"self",
".",
"uvc",
".",
"brand",
"assert",
"\"UVC Fake\"",
"==",
"self",
".",
"uvc",
".",
"model",
"assert",
"SUPPORT_STREAM",
"==",
"self",
".",
"uvc",
".",
"supported_features"
] | [
233,
4
] | [
239,
60
] | python | en | ['en', 'en', 'en'] | True |
TestUVC.test_stream | (self) | Test the RTSP stream URI. | Test the RTSP stream URI. | def test_stream(self):
"""Test the RTSP stream URI."""
stream_source = yield from self.uvc.stream_source()
assert stream_source == "rtsp://foo:7447/uuid_rtspchannel_0" | [
"def",
"test_stream",
"(",
"self",
")",
":",
"stream_source",
"=",
"yield",
"from",
"self",
".",
"uvc",
".",
"stream_source",
"(",
")",
"assert",
"stream_source",
"==",
"\"rtsp://foo:7447/uuid_rtspchannel_0\""
] | [
241,
4
] | [
244,
68
] | python | en | ['en', 'zh', 'en'] | True |
TestUVC.test_login | (self, mock_camera, mock_store) | Test the login. | Test the login. | def test_login(self, mock_camera, mock_store):
"""Test the login."""
self.uvc._login()
assert mock_camera.call_count == 1
assert mock_camera.call_args == mock.call("host-a", "admin", "seekret")
assert mock_camera.return_value.login.call_count == 1
assert mock_camera.return_value.login.call_args == mock.call() | [
"def",
"test_login",
"(",
"self",
",",
"mock_camera",
",",
"mock_store",
")",
":",
"self",
".",
"uvc",
".",
"_login",
"(",
")",
"assert",
"mock_camera",
".",
"call_count",
"==",
"1",
"assert",
"mock_camera",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
"\"host-a\"",
",",
"\"admin\"",
",",
"\"seekret\"",
")",
"assert",
"mock_camera",
".",
"return_value",
".",
"login",
".",
"call_count",
"==",
"1",
"assert",
"mock_camera",
".",
"return_value",
".",
"login",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
")"
] | [
248,
4
] | [
254,
70
] | python | en | ['en', 'co', 'en'] | True |
TestUVC.test_login_v31x | (self, mock_camera, mock_store) | Test login with v3.1.x server. | Test login with v3.1.x server. | def test_login_v31x(self, mock_camera, mock_store):
"""Test login with v3.1.x server."""
self.nvr.server_version = (3, 1, 3)
self.uvc._login()
assert mock_camera.call_count == 1
assert mock_camera.call_args == mock.call("host-a", "admin", "seekret")
assert mock_camera.return_value.login.call_count == 1
assert mock_camera.return_value.login.call_args == mock.call() | [
"def",
"test_login_v31x",
"(",
"self",
",",
"mock_camera",
",",
"mock_store",
")",
":",
"self",
".",
"nvr",
".",
"server_version",
"=",
"(",
"3",
",",
"1",
",",
"3",
")",
"self",
".",
"uvc",
".",
"_login",
"(",
")",
"assert",
"mock_camera",
".",
"call_count",
"==",
"1",
"assert",
"mock_camera",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
"\"host-a\"",
",",
"\"admin\"",
",",
"\"seekret\"",
")",
"assert",
"mock_camera",
".",
"return_value",
".",
"login",
".",
"call_count",
"==",
"1",
"assert",
"mock_camera",
".",
"return_value",
".",
"login",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
")"
] | [
258,
4
] | [
265,
70
] | python | en | ['en', 'da', 'en'] | True |
TestUVC.test_login_tries_both_addrs_and_caches | (self, mock_camera, mock_store) | Test the login tries. | Test the login tries. | def test_login_tries_both_addrs_and_caches(self, mock_camera, mock_store):
"""Test the login tries."""
responses = [0]
def mock_login(*a):
"""Mock login."""
try:
responses.pop(0)
raise OSError
except IndexError:
pass
mock_store.return_value.get_camera_password.return_value = None
mock_camera.return_value.login.side_effect = mock_login
self.uvc._login()
assert 2 == mock_camera.call_count
assert "host-b" == self.uvc._connect_addr
mock_camera.reset_mock()
self.uvc._login()
assert mock_camera.call_count == 1
assert mock_camera.call_args == mock.call("host-b", "admin", "seekret")
assert mock_camera.return_value.login.call_count == 1
assert mock_camera.return_value.login.call_args == mock.call() | [
"def",
"test_login_tries_both_addrs_and_caches",
"(",
"self",
",",
"mock_camera",
",",
"mock_store",
")",
":",
"responses",
"=",
"[",
"0",
"]",
"def",
"mock_login",
"(",
"*",
"a",
")",
":",
"\"\"\"Mock login.\"\"\"",
"try",
":",
"responses",
".",
"pop",
"(",
"0",
")",
"raise",
"OSError",
"except",
"IndexError",
":",
"pass",
"mock_store",
".",
"return_value",
".",
"get_camera_password",
".",
"return_value",
"=",
"None",
"mock_camera",
".",
"return_value",
".",
"login",
".",
"side_effect",
"=",
"mock_login",
"self",
".",
"uvc",
".",
"_login",
"(",
")",
"assert",
"2",
"==",
"mock_camera",
".",
"call_count",
"assert",
"\"host-b\"",
"==",
"self",
".",
"uvc",
".",
"_connect_addr",
"mock_camera",
".",
"reset_mock",
"(",
")",
"self",
".",
"uvc",
".",
"_login",
"(",
")",
"assert",
"mock_camera",
".",
"call_count",
"==",
"1",
"assert",
"mock_camera",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
"\"host-b\"",
",",
"\"admin\"",
",",
"\"seekret\"",
")",
"assert",
"mock_camera",
".",
"return_value",
".",
"login",
".",
"call_count",
"==",
"1",
"assert",
"mock_camera",
".",
"return_value",
".",
"login",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
")"
] | [
269,
4
] | [
292,
70
] | python | en | ['en', 'mt', 'en'] | True |
TestUVC.test_login_fails_both_properly | (self, mock_camera, mock_store) | Test if login fails properly. | Test if login fails properly. | def test_login_fails_both_properly(self, mock_camera, mock_store):
"""Test if login fails properly."""
mock_camera.return_value.login.side_effect = socket.error
assert self.uvc._login() is None
assert self.uvc._connect_addr is None | [
"def",
"test_login_fails_both_properly",
"(",
"self",
",",
"mock_camera",
",",
"mock_store",
")",
":",
"mock_camera",
".",
"return_value",
".",
"login",
".",
"side_effect",
"=",
"socket",
".",
"error",
"assert",
"self",
".",
"uvc",
".",
"_login",
"(",
")",
"is",
"None",
"assert",
"self",
".",
"uvc",
".",
"_connect_addr",
"is",
"None"
] | [
296,
4
] | [
300,
45
] | python | en | ['ms', 'en', 'en'] | True |
TestUVC.test_camera_image_tries_login_bails_on_failure | (self) | Test retrieving failure. | Test retrieving failure. | def test_camera_image_tries_login_bails_on_failure(self):
"""Test retrieving failure."""
with mock.patch.object(self.uvc, "_login") as mock_login:
mock_login.return_value = False
assert self.uvc.camera_image() is None
assert mock_login.call_count == 1
assert mock_login.call_args == mock.call() | [
"def",
"test_camera_image_tries_login_bails_on_failure",
"(",
"self",
")",
":",
"with",
"mock",
".",
"patch",
".",
"object",
"(",
"self",
".",
"uvc",
",",
"\"_login\"",
")",
"as",
"mock_login",
":",
"mock_login",
".",
"return_value",
"=",
"False",
"assert",
"self",
".",
"uvc",
".",
"camera_image",
"(",
")",
"is",
"None",
"assert",
"mock_login",
".",
"call_count",
"==",
"1",
"assert",
"mock_login",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
")"
] | [
302,
4
] | [
308,
54
] | python | en | ['en', 'pt', 'en'] | True |
TestUVC.test_camera_image_logged_in | (self) | Test the login state. | Test the login state. | def test_camera_image_logged_in(self):
"""Test the login state."""
self.uvc._camera = mock.MagicMock()
assert self.uvc._camera.get_snapshot.return_value == self.uvc.camera_image() | [
"def",
"test_camera_image_logged_in",
"(",
"self",
")",
":",
"self",
".",
"uvc",
".",
"_camera",
"=",
"mock",
".",
"MagicMock",
"(",
")",
"assert",
"self",
".",
"uvc",
".",
"_camera",
".",
"get_snapshot",
".",
"return_value",
"==",
"self",
".",
"uvc",
".",
"camera_image",
"(",
")"
] | [
310,
4
] | [
313,
84
] | python | en | ['en', 'en', 'en'] | True |
TestUVC.test_camera_image_error | (self) | Test the camera image error. | Test the camera image error. | def test_camera_image_error(self):
"""Test the camera image error."""
self.uvc._camera = mock.MagicMock()
self.uvc._camera.get_snapshot.side_effect = camera.CameraConnectError
assert self.uvc.camera_image() is None | [
"def",
"test_camera_image_error",
"(",
"self",
")",
":",
"self",
".",
"uvc",
".",
"_camera",
"=",
"mock",
".",
"MagicMock",
"(",
")",
"self",
".",
"uvc",
".",
"_camera",
".",
"get_snapshot",
".",
"side_effect",
"=",
"camera",
".",
"CameraConnectError",
"assert",
"self",
".",
"uvc",
".",
"camera_image",
"(",
")",
"is",
"None"
] | [
315,
4
] | [
319,
46
] | python | en | ['en', 'la', 'en'] | True |
TestUVC.test_camera_image_reauths | (self) | Test the re-authentication. | Test the re-authentication. | def test_camera_image_reauths(self):
"""Test the re-authentication."""
responses = [0]
def mock_snapshot():
"""Mock snapshot."""
try:
responses.pop()
raise camera.CameraAuthError()
except IndexError:
pass
return "image"
self.uvc._camera = mock.MagicMock()
self.uvc._camera.get_snapshot.side_effect = mock_snapshot
with mock.patch.object(self.uvc, "_login") as mock_login:
assert "image" == self.uvc.camera_image()
assert mock_login.call_count == 1
assert mock_login.call_args == mock.call()
assert [] == responses | [
"def",
"test_camera_image_reauths",
"(",
"self",
")",
":",
"responses",
"=",
"[",
"0",
"]",
"def",
"mock_snapshot",
"(",
")",
":",
"\"\"\"Mock snapshot.\"\"\"",
"try",
":",
"responses",
".",
"pop",
"(",
")",
"raise",
"camera",
".",
"CameraAuthError",
"(",
")",
"except",
"IndexError",
":",
"pass",
"return",
"\"image\"",
"self",
".",
"uvc",
".",
"_camera",
"=",
"mock",
".",
"MagicMock",
"(",
")",
"self",
".",
"uvc",
".",
"_camera",
".",
"get_snapshot",
".",
"side_effect",
"=",
"mock_snapshot",
"with",
"mock",
".",
"patch",
".",
"object",
"(",
"self",
".",
"uvc",
",",
"\"_login\"",
")",
"as",
"mock_login",
":",
"assert",
"\"image\"",
"==",
"self",
".",
"uvc",
".",
"camera_image",
"(",
")",
"assert",
"mock_login",
".",
"call_count",
"==",
"1",
"assert",
"mock_login",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
")",
"assert",
"[",
"]",
"==",
"responses"
] | [
321,
4
] | [
340,
34
] | python | en | ['en', 'en', 'en'] | True |
TestUVC.test_camera_image_reauths_only_once | (self) | Test if the re-authentication only happens once. | Test if the re-authentication only happens once. | def test_camera_image_reauths_only_once(self):
"""Test if the re-authentication only happens once."""
self.uvc._camera = mock.MagicMock()
self.uvc._camera.get_snapshot.side_effect = camera.CameraAuthError
with mock.patch.object(self.uvc, "_login") as mock_login:
with pytest.raises(camera.CameraAuthError):
self.uvc.camera_image()
assert mock_login.call_count == 1
assert mock_login.call_args == mock.call() | [
"def",
"test_camera_image_reauths_only_once",
"(",
"self",
")",
":",
"self",
".",
"uvc",
".",
"_camera",
"=",
"mock",
".",
"MagicMock",
"(",
")",
"self",
".",
"uvc",
".",
"_camera",
".",
"get_snapshot",
".",
"side_effect",
"=",
"camera",
".",
"CameraAuthError",
"with",
"mock",
".",
"patch",
".",
"object",
"(",
"self",
".",
"uvc",
",",
"\"_login\"",
")",
"as",
"mock_login",
":",
"with",
"pytest",
".",
"raises",
"(",
"camera",
".",
"CameraAuthError",
")",
":",
"self",
".",
"uvc",
".",
"camera_image",
"(",
")",
"assert",
"mock_login",
".",
"call_count",
"==",
"1",
"assert",
"mock_login",
".",
"call_args",
"==",
"mock",
".",
"call",
"(",
")"
] | [
342,
4
] | [
350,
54
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Demo humidifier devices. | Set up the Demo humidifier devices. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Demo humidifier devices."""
async_add_entities(
[
DemoHumidifier(
name="Humidifier",
mode=None,
target_humidity=68,
device_class=DEVICE_CLASS_HUMIDIFIER,
),
DemoHumidifier(
name="Dehumidifier",
mode=None,
target_humidity=54,
device_class=DEVICE_CLASS_DEHUMIDIFIER,
),
DemoHumidifier(
name="Hygrostat",
mode="home",
available_modes=["home", "eco"],
target_humidity=50,
),
]
) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"async_add_entities",
"(",
"[",
"DemoHumidifier",
"(",
"name",
"=",
"\"Humidifier\"",
",",
"mode",
"=",
"None",
",",
"target_humidity",
"=",
"68",
",",
"device_class",
"=",
"DEVICE_CLASS_HUMIDIFIER",
",",
")",
",",
"DemoHumidifier",
"(",
"name",
"=",
"\"Dehumidifier\"",
",",
"mode",
"=",
"None",
",",
"target_humidity",
"=",
"54",
",",
"device_class",
"=",
"DEVICE_CLASS_DEHUMIDIFIER",
",",
")",
",",
"DemoHumidifier",
"(",
"name",
"=",
"\"Hygrostat\"",
",",
"mode",
"=",
"\"home\"",
",",
"available_modes",
"=",
"[",
"\"home\"",
",",
"\"eco\"",
"]",
",",
"target_humidity",
"=",
"50",
",",
")",
",",
"]",
")"
] | [
11,
0
] | [
34,
5
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Demo humidifier devices config entry. | Set up the Demo humidifier devices config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Demo humidifier devices config entry."""
await async_setup_platform(hass, {}, async_add_entities) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"await",
"async_setup_platform",
"(",
"hass",
",",
"{",
"}",
",",
"async_add_entities",
")"
] | [
37,
0
] | [
39,
60
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.__init__ | (
self,
name,
mode,
target_humidity,
available_modes=None,
is_on=True,
device_class=None,
) | Initialize the humidifier device. | Initialize the humidifier device. | def __init__(
self,
name,
mode,
target_humidity,
available_modes=None,
is_on=True,
device_class=None,
):
"""Initialize the humidifier device."""
self._name = name
self._state = is_on
self._support_flags = SUPPORT_FLAGS
if mode is not None:
self._support_flags = self._support_flags | SUPPORT_MODES
self._target_humidity = target_humidity
self._mode = mode
self._available_modes = available_modes
self._device_class = device_class | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"mode",
",",
"target_humidity",
",",
"available_modes",
"=",
"None",
",",
"is_on",
"=",
"True",
",",
"device_class",
"=",
"None",
",",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_state",
"=",
"is_on",
"self",
".",
"_support_flags",
"=",
"SUPPORT_FLAGS",
"if",
"mode",
"is",
"not",
"None",
":",
"self",
".",
"_support_flags",
"=",
"self",
".",
"_support_flags",
"|",
"SUPPORT_MODES",
"self",
".",
"_target_humidity",
"=",
"target_humidity",
"self",
".",
"_mode",
"=",
"mode",
"self",
".",
"_available_modes",
"=",
"available_modes",
"self",
".",
"_device_class",
"=",
"device_class"
] | [
45,
4
] | [
63,
41
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self):
"""Return the list of supported features."""
return self._support_flags | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"self",
".",
"_support_flags"
] | [
66,
4
] | [
68,
34
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.should_poll | (self) | Return the polling state. | Return the polling state. | def should_poll(self):
"""Return the polling state."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
71,
4
] | [
73,
20
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.name | (self) | Return the name of the humidity device. | Return the name of the humidity device. | def name(self):
"""Return the name of the humidity device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
76,
4
] | [
78,
25
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.target_humidity | (self) | Return the humidity we try to reach. | Return the humidity we try to reach. | def target_humidity(self):
"""Return the humidity we try to reach."""
return self._target_humidity | [
"def",
"target_humidity",
"(",
"self",
")",
":",
"return",
"self",
".",
"_target_humidity"
] | [
81,
4
] | [
83,
36
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.mode | (self) | Return current mode. | Return current mode. | def mode(self):
"""Return current mode."""
return self._mode | [
"def",
"mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_mode"
] | [
86,
4
] | [
88,
25
] | python | en | ['en', 'da', 'en'] | True |
DemoHumidifier.available_modes | (self) | Return available modes. | Return available modes. | def available_modes(self):
"""Return available modes."""
return self._available_modes | [
"def",
"available_modes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_available_modes"
] | [
91,
4
] | [
93,
36
] | python | en | ['fr', 'en', 'en'] | True |
DemoHumidifier.is_on | (self) | Return true if the humidifier is on. | Return true if the humidifier is on. | def is_on(self):
"""Return true if the humidifier is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
96,
4
] | [
98,
26
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.device_class | (self) | Return the device class of the humidifier. | Return the device class of the humidifier. | def device_class(self):
"""Return the device class of the humidifier."""
return self._device_class | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device_class"
] | [
101,
4
] | [
103,
33
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.async_turn_on | (self, **kwargs) | Turn the device on. | Turn the device on. | async def async_turn_on(self, **kwargs):
"""Turn the device on."""
self._state = True
self.async_write_ha_state() | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_state",
"=",
"True",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
105,
4
] | [
108,
35
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.async_turn_off | (self, **kwargs) | Turn the device off. | Turn the device off. | async def async_turn_off(self, **kwargs):
"""Turn the device off."""
self._state = False
self.async_write_ha_state() | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_state",
"=",
"False",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
110,
4
] | [
113,
35
] | python | en | ['en', 'en', 'en'] | True |
DemoHumidifier.async_set_humidity | (self, humidity) | Set new humidity level. | Set new humidity level. | async def async_set_humidity(self, humidity):
"""Set new humidity level."""
self._target_humidity = humidity
self.async_write_ha_state() | [
"async",
"def",
"async_set_humidity",
"(",
"self",
",",
"humidity",
")",
":",
"self",
".",
"_target_humidity",
"=",
"humidity",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
115,
4
] | [
118,
35
] | python | en | ['en', 'sr', 'en'] | True |
DemoHumidifier.async_set_mode | (self, mode) | Update mode. | Update mode. | async def async_set_mode(self, mode):
"""Update mode."""
self._mode = mode
self.async_write_ha_state() | [
"async",
"def",
"async_set_mode",
"(",
"self",
",",
"mode",
")",
":",
"self",
".",
"_mode",
"=",
"mode",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
120,
4
] | [
123,
35
] | python | en | ['en', 'co', 'en'] | False |
DemoConfigFlow.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 OptionsFlowHandler(config_entry) | [
"def",
"async_get_options_flow",
"(",
"config_entry",
")",
":",
"return",
"OptionsFlowHandler",
"(",
"config_entry",
")"
] | [
24,
4
] | [
26,
47
] | python | en | ['en', 'en', 'en'] | True |
DemoConfigFlow.async_step_import | (self, import_info) | Set the config entry up from yaml. | Set the config entry up from yaml. | async def async_step_import(self, import_info):
"""Set the config entry up from yaml."""
return self.async_create_entry(title="Demo", data={}) | [
"async",
"def",
"async_step_import",
"(",
"self",
",",
"import_info",
")",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"\"Demo\"",
",",
"data",
"=",
"{",
"}",
")"
] | [
28,
4
] | [
30,
61
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.__init__ | (self, config_entry) | Initialize options flow. | Initialize options flow. | def __init__(self, config_entry):
"""Initialize options flow."""
self.config_entry = config_entry
self.options = dict(config_entry.options) | [
"def",
"__init__",
"(",
"self",
",",
"config_entry",
")",
":",
"self",
".",
"config_entry",
"=",
"config_entry",
"self",
".",
"options",
"=",
"dict",
"(",
"config_entry",
".",
"options",
")"
] | [
36,
4
] | [
39,
49
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_init | (self, user_input=None) | Manage the options. | Manage the options. | async def async_step_init(self, user_input=None):
"""Manage the options."""
return await self.async_step_options_1() | [
"async",
"def",
"async_step_init",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"await",
"self",
".",
"async_step_options_1",
"(",
")"
] | [
41,
4
] | [
43,
48
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_options_1 | (self, user_input=None) | Manage the options. | Manage the options. | async def async_step_options_1(self, user_input=None):
"""Manage the options."""
if user_input is not None:
self.options.update(user_input)
return await self.async_step_options_2()
return self.async_show_form(
step_id="options_1",
data_schema=vol.Schema(
{
vol.Required("constant"): "Constant Value",
vol.Optional(
CONF_BOOLEAN,
default=self.config_entry.options.get(CONF_BOOLEAN, False),
): bool,
vol.Optional(
CONF_INT,
default=self.config_entry.options.get(CONF_INT, 10),
): int,
}
),
) | [
"async",
"def",
"async_step_options_1",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"not",
"None",
":",
"self",
".",
"options",
".",
"update",
"(",
"user_input",
")",
"return",
"await",
"self",
".",
"async_step_options_2",
"(",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_1\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"\"constant\"",
")",
":",
"\"Constant Value\"",
",",
"vol",
".",
"Optional",
"(",
"CONF_BOOLEAN",
",",
"default",
"=",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_BOOLEAN",
",",
"False",
")",
",",
")",
":",
"bool",
",",
"vol",
".",
"Optional",
"(",
"CONF_INT",
",",
"default",
"=",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_INT",
",",
"10",
")",
",",
")",
":",
"int",
",",
"}",
")",
",",
")"
] | [
45,
4
] | [
66,
9
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler.async_step_options_2 | (self, user_input=None) | Manage the options 2. | Manage the options 2. | async def async_step_options_2(self, user_input=None):
"""Manage the options 2."""
if user_input is not None:
self.options.update(user_input)
return await self._update_options()
return self.async_show_form(
step_id="options_2",
data_schema=vol.Schema(
{
vol.Optional(
CONF_STRING,
default=self.config_entry.options.get(
CONF_STRING,
"Default",
),
): str,
vol.Optional(
CONF_SELECT,
default=self.config_entry.options.get(CONF_SELECT, "default"),
): vol.In(["default", "other"]),
vol.Optional(
CONF_MULTISELECT,
default=self.config_entry.options.get(
CONF_MULTISELECT, ["default"]
),
): cv.multi_select({"default": "Default", "other": "Other"}),
}
),
) | [
"async",
"def",
"async_step_options_2",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"not",
"None",
":",
"self",
".",
"options",
".",
"update",
"(",
"user_input",
")",
"return",
"await",
"self",
".",
"_update_options",
"(",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"options_2\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Optional",
"(",
"CONF_STRING",
",",
"default",
"=",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_STRING",
",",
"\"Default\"",
",",
")",
",",
")",
":",
"str",
",",
"vol",
".",
"Optional",
"(",
"CONF_SELECT",
",",
"default",
"=",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_SELECT",
",",
"\"default\"",
")",
",",
")",
":",
"vol",
".",
"In",
"(",
"[",
"\"default\"",
",",
"\"other\"",
"]",
")",
",",
"vol",
".",
"Optional",
"(",
"CONF_MULTISELECT",
",",
"default",
"=",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_MULTISELECT",
",",
"[",
"\"default\"",
"]",
")",
",",
")",
":",
"cv",
".",
"multi_select",
"(",
"{",
"\"default\"",
":",
"\"Default\"",
",",
"\"other\"",
":",
"\"Other\"",
"}",
")",
",",
"}",
")",
",",
")"
] | [
68,
4
] | [
97,
9
] | python | en | ['en', 'en', 'en'] | True |
OptionsFlowHandler._update_options | (self) | Update config entry options. | Update config entry options. | async def _update_options(self):
"""Update config entry options."""
return self.async_create_entry(title="", data=self.options) | [
"async",
"def",
"_update_options",
"(",
"self",
")",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"\"\"",
",",
"data",
"=",
"self",
".",
"options",
")"
] | [
99,
4
] | [
101,
67
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Command Sensor. | Set up the Command Sensor. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Command Sensor."""
setup_reload_service(hass, DOMAIN, PLATFORMS)
name = config.get(CONF_NAME)
command = config.get(CONF_COMMAND)
unit = config.get(CONF_UNIT_OF_MEASUREMENT)
value_template = config.get(CONF_VALUE_TEMPLATE)
command_timeout = config.get(CONF_COMMAND_TIMEOUT)
if value_template is not None:
value_template.hass = hass
json_attributes = config.get(CONF_JSON_ATTRIBUTES)
data = CommandSensorData(hass, command, command_timeout)
add_entities(
[CommandSensor(hass, data, name, unit, value_template, json_attributes)], True
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"command",
"=",
"config",
".",
"get",
"(",
"CONF_COMMAND",
")",
"unit",
"=",
"config",
".",
"get",
"(",
"CONF_UNIT_OF_MEASUREMENT",
")",
"value_template",
"=",
"config",
".",
"get",
"(",
"CONF_VALUE_TEMPLATE",
")",
"command_timeout",
"=",
"config",
".",
"get",
"(",
"CONF_COMMAND_TIMEOUT",
")",
"if",
"value_template",
"is",
"not",
"None",
":",
"value_template",
".",
"hass",
"=",
"hass",
"json_attributes",
"=",
"config",
".",
"get",
"(",
"CONF_JSON_ATTRIBUTES",
")",
"data",
"=",
"CommandSensorData",
"(",
"hass",
",",
"command",
",",
"command_timeout",
")",
"add_entities",
"(",
"[",
"CommandSensor",
"(",
"hass",
",",
"data",
",",
"name",
",",
"unit",
",",
"value_template",
",",
"json_attributes",
")",
"]",
",",
"True",
")"
] | [
45,
0
] | [
62,
5
] | python | en | ['en', 'bg', 'en'] | True |
CommandSensor.__init__ | (
self, hass, data, name, unit_of_measurement, value_template, json_attributes
) | Initialize the sensor. | Initialize the sensor. | def __init__(
self, hass, data, name, unit_of_measurement, value_template, json_attributes
):
"""Initialize the sensor."""
self._hass = hass
self.data = data
self._attributes = None
self._json_attributes = json_attributes
self._name = name
self._state = None
self._unit_of_measurement = unit_of_measurement
self._value_template = value_template | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"data",
",",
"name",
",",
"unit_of_measurement",
",",
"value_template",
",",
"json_attributes",
")",
":",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"data",
"=",
"data",
"self",
".",
"_attributes",
"=",
"None",
"self",
".",
"_json_attributes",
"=",
"json_attributes",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_unit_of_measurement",
"=",
"unit_of_measurement",
"self",
".",
"_value_template",
"=",
"value_template"
] | [
68,
4
] | [
79,
45
] | python | en | ['en', 'en', 'en'] | True |
CommandSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
82,
4
] | [
84,
25
] | python | en | ['en', 'mi', 'en'] | True |
CommandSensor.unit_of_measurement | (self) | Return the unit the value is expressed in. | Return the unit the value is expressed in. | def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
87,
4
] | [
89,
40
] | python | en | ['en', 'en', 'en'] | True |
CommandSensor.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"
] | [
92,
4
] | [
94,
26
] | python | en | ['en', 'en', 'en'] | True |
CommandSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
return self._attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_attributes"
] | [
97,
4
] | [
99,
31
] | python | en | ['en', 'en', 'en'] | True |
CommandSensor.update | (self) | Get the latest data and updates the state. | Get the latest data and updates the state. | def update(self):
"""Get the latest data and updates the state."""
self.data.update()
value = self.data.value
if self._json_attributes:
self._attributes = {}
if value:
try:
json_dict = json.loads(value)
if isinstance(json_dict, Mapping):
self._attributes = {
k: json_dict[k]
for k in self._json_attributes
if k in json_dict
}
else:
_LOGGER.warning("JSON result was not a dictionary")
except ValueError:
_LOGGER.warning("Unable to parse output as JSON: %s", value)
else:
_LOGGER.warning("Empty reply found when expecting JSON data")
if value is None:
value = STATE_UNKNOWN
elif self._value_template is not None:
self._state = self._value_template.render_with_possible_json_value(
value, STATE_UNKNOWN
)
else:
self._state = value | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"data",
".",
"update",
"(",
")",
"value",
"=",
"self",
".",
"data",
".",
"value",
"if",
"self",
".",
"_json_attributes",
":",
"self",
".",
"_attributes",
"=",
"{",
"}",
"if",
"value",
":",
"try",
":",
"json_dict",
"=",
"json",
".",
"loads",
"(",
"value",
")",
"if",
"isinstance",
"(",
"json_dict",
",",
"Mapping",
")",
":",
"self",
".",
"_attributes",
"=",
"{",
"k",
":",
"json_dict",
"[",
"k",
"]",
"for",
"k",
"in",
"self",
".",
"_json_attributes",
"if",
"k",
"in",
"json_dict",
"}",
"else",
":",
"_LOGGER",
".",
"warning",
"(",
"\"JSON result was not a dictionary\"",
")",
"except",
"ValueError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Unable to parse output as JSON: %s\"",
",",
"value",
")",
"else",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Empty reply found when expecting JSON data\"",
")",
"if",
"value",
"is",
"None",
":",
"value",
"=",
"STATE_UNKNOWN",
"elif",
"self",
".",
"_value_template",
"is",
"not",
"None",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_value_template",
".",
"render_with_possible_json_value",
"(",
"value",
",",
"STATE_UNKNOWN",
")",
"else",
":",
"self",
".",
"_state",
"=",
"value"
] | [
101,
4
] | [
131,
31
] | python | en | ['en', 'en', 'en'] | True |
CommandSensorData.__init__ | (self, hass, command, command_timeout) | Initialize the data object. | Initialize the data object. | def __init__(self, hass, command, command_timeout):
"""Initialize the data object."""
self.value = None
self.hass = hass
self.command = command
self.timeout = command_timeout | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"command",
",",
"command_timeout",
")",
":",
"self",
".",
"value",
"=",
"None",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"command",
"=",
"command",
"self",
".",
"timeout",
"=",
"command_timeout"
] | [
137,
4
] | [
142,
38
] | python | en | ['en', 'en', 'en'] | True |
CommandSensorData.update | (self) | Get the latest data with a shell command. | Get the latest data with a shell command. | def update(self):
"""Get the latest data with a shell command."""
command = self.command
cache = {}
if command in cache:
prog, args, args_compiled = cache[command]
elif " " not in command:
prog = command
args = None
args_compiled = None
cache[command] = (prog, args, args_compiled)
else:
prog, args = command.split(" ", 1)
args_compiled = template.Template(args, self.hass)
cache[command] = (prog, args, args_compiled)
if args_compiled:
try:
args_to_render = {"arguments": args}
rendered_args = args_compiled.render(args_to_render)
except TemplateError as ex:
_LOGGER.exception("Error rendering command template: %s", ex)
return
else:
rendered_args = None
if rendered_args == args:
# No template used. default behavior
pass
else:
# Template used. Construct the string used in the shell
command = f"{prog} {rendered_args}"
_LOGGER.debug("Running command: %s", command)
self.value = check_output_or_log(command, self.timeout) | [
"def",
"update",
"(",
"self",
")",
":",
"command",
"=",
"self",
".",
"command",
"cache",
"=",
"{",
"}",
"if",
"command",
"in",
"cache",
":",
"prog",
",",
"args",
",",
"args_compiled",
"=",
"cache",
"[",
"command",
"]",
"elif",
"\" \"",
"not",
"in",
"command",
":",
"prog",
"=",
"command",
"args",
"=",
"None",
"args_compiled",
"=",
"None",
"cache",
"[",
"command",
"]",
"=",
"(",
"prog",
",",
"args",
",",
"args_compiled",
")",
"else",
":",
"prog",
",",
"args",
"=",
"command",
".",
"split",
"(",
"\" \"",
",",
"1",
")",
"args_compiled",
"=",
"template",
".",
"Template",
"(",
"args",
",",
"self",
".",
"hass",
")",
"cache",
"[",
"command",
"]",
"=",
"(",
"prog",
",",
"args",
",",
"args_compiled",
")",
"if",
"args_compiled",
":",
"try",
":",
"args_to_render",
"=",
"{",
"\"arguments\"",
":",
"args",
"}",
"rendered_args",
"=",
"args_compiled",
".",
"render",
"(",
"args_to_render",
")",
"except",
"TemplateError",
"as",
"ex",
":",
"_LOGGER",
".",
"exception",
"(",
"\"Error rendering command template: %s\"",
",",
"ex",
")",
"return",
"else",
":",
"rendered_args",
"=",
"None",
"if",
"rendered_args",
"==",
"args",
":",
"# No template used. default behavior",
"pass",
"else",
":",
"# Template used. Construct the string used in the shell",
"command",
"=",
"f\"{prog} {rendered_args}\"",
"_LOGGER",
".",
"debug",
"(",
"\"Running command: %s\"",
",",
"command",
")",
"self",
".",
"value",
"=",
"check_output_or_log",
"(",
"command",
",",
"self",
".",
"timeout",
")"
] | [
144,
4
] | [
179,
63
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up binary sensor(s) for KNX platform. | Set up binary sensor(s) for KNX platform. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up binary sensor(s) for KNX platform."""
entities = []
for device in hass.data[DOMAIN].xknx.devices:
if isinstance(device, XknxBinarySensor):
entities.append(KNXBinarySensor(device))
async_add_entities(entities) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"entities",
"=",
"[",
"]",
"for",
"device",
"in",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"xknx",
".",
"devices",
":",
"if",
"isinstance",
"(",
"device",
",",
"XknxBinarySensor",
")",
":",
"entities",
".",
"append",
"(",
"KNXBinarySensor",
"(",
"device",
")",
")",
"async_add_entities",
"(",
"entities",
")"
] | [
11,
0
] | [
17,
32
] | python | en | ['en', 'pt', 'en'] | True |
KNXBinarySensor.__init__ | (self, device: XknxBinarySensor) | Initialize of KNX binary sensor. | Initialize of KNX binary sensor. | def __init__(self, device: XknxBinarySensor):
"""Initialize of KNX binary sensor."""
super().__init__(device) | [
"def",
"__init__",
"(",
"self",
",",
"device",
":",
"XknxBinarySensor",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"device",
")"
] | [
23,
4
] | [
25,
32
] | python | en | ['en', 'pl', 'en'] | True |
KNXBinarySensor.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self):
"""Return the class of this sensor."""
if self._device.device_class in DEVICE_CLASSES:
return self._device.device_class
return None | [
"def",
"device_class",
"(",
"self",
")",
":",
"if",
"self",
".",
"_device",
".",
"device_class",
"in",
"DEVICE_CLASSES",
":",
"return",
"self",
".",
"_device",
".",
"device_class",
"return",
"None"
] | [
28,
4
] | [
32,
19
] | python | en | ['en', 'en', 'en'] | True |
KNXBinarySensor.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 self._device.is_on() | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device",
".",
"is_on",
"(",
")"
] | [
35,
4
] | [
37,
35
] | python | en | ['en', 'fy', 'en'] | True |
KNXBinarySensor.device_state_attributes | (self) | Return device specific state attributes. | Return device specific state attributes. | def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return device specific state attributes."""
return {ATTR_COUNTER: self._device.counter} | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
":",
"return",
"{",
"ATTR_COUNTER",
":",
"self",
".",
"_device",
".",
"counter",
"}"
] | [
40,
4
] | [
42,
51
] | python | en | ['fr', 'en', 'en'] | True |
KNXBinarySensor.force_update | (self) |
Return True if state updates should be forced.
If True, a state change will be triggered anytime the state property is
updated, not just when the value changes.
|
Return True if state updates should be forced. | def force_update(self) -> bool:
"""
Return True if state updates should be forced.
If True, a state change will be triggered anytime the state property is
updated, not just when the value changes.
"""
return self._device.ignore_internal_state | [
"def",
"force_update",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"ignore_internal_state"
] | [
45,
4
] | [
52,
49
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.