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 |
---|---|---|---|---|---|---|---|---|---|---|---|
QnliProcessor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["question"].numpy().decode("utf-8"),
tensor_dict["sentence"].numpy().decode("utf-8"),
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"question\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"tensor_dict",
"[",
"\"sentence\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
476,
4
] | [
483,
9
] | python | en | ['en', 'en', 'en'] | True |
QnliProcessor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
485,
4
] | [
487,
98
] | python | en | ['en', 'en', 'en'] | True |
QnliProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev.tsv\"",
")",
")",
",",
"\"dev\"",
")"
] | [
489,
4
] | [
491,
94
] | python | en | ['en', 'en', 'en'] | True |
QnliProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test.tsv")), "test") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test.tsv\"",
")",
")",
",",
"\"test\"",
")"
] | [
493,
4
] | [
495,
96
] | python | en | ['en', 'en', 'en'] | True |
QnliProcessor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return ["entailment", "not_entailment"] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"\"entailment\"",
",",
"\"not_entailment\"",
"]"
] | [
497,
4
] | [
499,
47
] | python | en | ['en', 'en', 'en'] | True |
QnliProcessor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, line[0])
text_a = line[1]
text_b = line[2]
label = None if set_type == "test" else line[-1]
examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"line",
"[",
"0",
"]",
")",
"text_a",
"=",
"line",
"[",
"1",
"]",
"text_b",
"=",
"line",
"[",
"2",
"]",
"label",
"=",
"None",
"if",
"set_type",
"==",
"\"test\"",
"else",
"line",
"[",
"-",
"1",
"]",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"text_b",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
501,
4
] | [
512,
23
] | python | en | ['en', 'en', 'en'] | True |
RteProcessor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["sentence1"].numpy().decode("utf-8"),
tensor_dict["sentence2"].numpy().decode("utf-8"),
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"sentence1\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"tensor_dict",
"[",
"\"sentence2\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
522,
4
] | [
529,
9
] | python | en | ['en', 'en', 'en'] | True |
RteProcessor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
531,
4
] | [
533,
98
] | python | en | ['en', 'en', 'en'] | True |
RteProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev.tsv\"",
")",
")",
",",
"\"dev\"",
")"
] | [
535,
4
] | [
537,
94
] | python | en | ['en', 'en', 'en'] | True |
RteProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test.tsv")), "test") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test.tsv\"",
")",
")",
",",
"\"test\"",
")"
] | [
539,
4
] | [
541,
96
] | python | en | ['en', 'en', 'en'] | True |
RteProcessor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return ["entailment", "not_entailment"] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"\"entailment\"",
",",
"\"not_entailment\"",
"]"
] | [
543,
4
] | [
545,
47
] | python | en | ['en', 'en', 'en'] | True |
RteProcessor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, line[0])
text_a = line[1]
text_b = line[2]
label = None if set_type == "test" else line[-1]
examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"line",
"[",
"0",
"]",
")",
"text_a",
"=",
"line",
"[",
"1",
"]",
"text_b",
"=",
"line",
"[",
"2",
"]",
"label",
"=",
"None",
"if",
"set_type",
"==",
"\"test\"",
"else",
"line",
"[",
"-",
"1",
"]",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"text_b",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
547,
4
] | [
558,
23
] | python | en | ['en', 'en', 'en'] | True |
WnliProcessor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["sentence1"].numpy().decode("utf-8"),
tensor_dict["sentence2"].numpy().decode("utf-8"),
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"sentence1\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"tensor_dict",
"[",
"\"sentence2\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
568,
4
] | [
575,
9
] | python | en | ['en', 'en', 'en'] | True |
WnliProcessor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
577,
4
] | [
579,
98
] | python | en | ['en', 'en', 'en'] | True |
WnliProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev.tsv\"",
")",
")",
",",
"\"dev\"",
")"
] | [
581,
4
] | [
583,
94
] | python | en | ['en', 'en', 'en'] | True |
WnliProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test.tsv")), "test") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test.tsv\"",
")",
")",
",",
"\"test\"",
")"
] | [
585,
4
] | [
587,
96
] | python | en | ['en', 'en', 'en'] | True |
WnliProcessor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return ["0", "1"] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"\"0\"",
",",
"\"1\"",
"]"
] | [
589,
4
] | [
591,
25
] | python | en | ['en', 'en', 'en'] | True |
WnliProcessor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, line[0])
text_a = line[1]
text_b = line[2]
label = None if set_type == "test" else line[-1]
examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"line",
"[",
"0",
"]",
")",
"text_a",
"=",
"line",
"[",
"1",
"]",
"text_b",
"=",
"line",
"[",
"2",
"]",
"label",
"=",
"None",
"if",
"set_type",
"==",
"\"test\"",
"else",
"line",
"[",
"-",
"1",
"]",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"text_b",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
593,
4
] | [
604,
23
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up certificate expiry sensor. | Set up certificate expiry sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up certificate expiry sensor."""
@callback
def schedule_import(_):
"""Schedule delayed import after HA is fully started."""
async_call_later(hass, 10, do_import)
@callback
def do_import(_):
"""Process YAML import."""
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=dict(config)
)
)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, schedule_import) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"@",
"callback",
"def",
"schedule_import",
"(",
"_",
")",
":",
"\"\"\"Schedule delayed import after HA is fully started.\"\"\"",
"async_call_later",
"(",
"hass",
",",
"10",
",",
"do_import",
")",
"@",
"callback",
"def",
"do_import",
"(",
"_",
")",
":",
"\"\"\"Process YAML import.\"\"\"",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"dict",
"(",
"config",
")",
")",
")",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_START",
",",
"schedule_import",
")"
] | [
30,
0
] | [
47,
74
] | python | en | ['en', 'pt', 'en'] | True |
async_setup_entry | (hass, entry, async_add_entities) | Add cert-expiry entry. | Add cert-expiry entry. | async def async_setup_entry(hass, entry, async_add_entities):
"""Add cert-expiry entry."""
coordinator = hass.data[DOMAIN][entry.entry_id]
sensors = [
SSLCertificateTimestamp(coordinator),
]
async_add_entities(sensors, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"coordinator",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"sensors",
"=",
"[",
"SSLCertificateTimestamp",
"(",
"coordinator",
")",
",",
"]",
"async_add_entities",
"(",
"sensors",
",",
"True",
")"
] | [
50,
0
] | [
58,
37
] | python | en | ['en', 'kk', 'en'] | True |
CertExpiryEntity.icon | (self) | Icon to use in the frontend, if any. | Icon to use in the frontend, if any. | def icon(self):
"""Icon to use in the frontend, if any."""
return "mdi:certificate" | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"\"mdi:certificate\""
] | [
65,
4
] | [
67,
32
] | python | en | ['en', 'en', 'en'] | True |
CertExpiryEntity.device_state_attributes | (self) | Return additional sensor state attributes. | Return additional sensor state attributes. | def device_state_attributes(self):
"""Return additional sensor state attributes."""
return {
"is_valid": self.coordinator.is_cert_valid,
"error": str(self.coordinator.cert_error),
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"\"is_valid\"",
":",
"self",
".",
"coordinator",
".",
"is_cert_valid",
",",
"\"error\"",
":",
"str",
"(",
"self",
".",
"coordinator",
".",
"cert_error",
")",
",",
"}"
] | [
70,
4
] | [
75,
9
] | python | en | ['en', 'da', 'en'] | True |
SSLCertificateTimestamp.device_class | (self) | Return the device class of the sensor. | Return the device class of the sensor. | def device_class(self):
"""Return the device class of the sensor."""
return DEVICE_CLASS_TIMESTAMP | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_TIMESTAMP"
] | [
82,
4
] | [
84,
37
] | python | en | ['en', 'en', 'en'] | True |
SSLCertificateTimestamp.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"Cert Expiry Timestamp ({self.coordinator.name})" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"Cert Expiry Timestamp ({self.coordinator.name})\""
] | [
87,
4
] | [
89,
65
] | python | en | ['en', 'mi', 'en'] | True |
SSLCertificateTimestamp.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
if self.coordinator.data:
return self.coordinator.data.isoformat()
return None | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"coordinator",
".",
"data",
":",
"return",
"self",
".",
"coordinator",
".",
"data",
".",
"isoformat",
"(",
")",
"return",
"None"
] | [
92,
4
] | [
96,
19
] | python | en | ['en', 'en', 'en'] | True |
SSLCertificateTimestamp.unique_id | (self) | Return a unique id for the sensor. | Return a unique id for the sensor. | def unique_id(self):
"""Return a unique id for the sensor."""
return f"{self.coordinator.host}:{self.coordinator.port}-timestamp" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self.coordinator.host}:{self.coordinator.port}-timestamp\""
] | [
99,
4
] | [
101,
75
] | python | en | ['en', 'ca', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the cloud binary sensors. | Set up the cloud binary sensors. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the cloud binary sensors."""
if discovery_info is None:
return
cloud = hass.data[DOMAIN]
async_add_entities([CloudRemoteBinary(cloud)]) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"cloud",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"async_add_entities",
"(",
"[",
"CloudRemoteBinary",
"(",
"cloud",
")",
"]",
")"
] | [
14,
0
] | [
20,
50
] | python | en | ['en', 'bg', 'en'] | True |
CloudRemoteBinary.__init__ | (self, cloud) | Initialize the binary sensor. | Initialize the binary sensor. | def __init__(self, cloud):
"""Initialize the binary sensor."""
self.cloud = cloud
self._unsub_dispatcher = None | [
"def",
"__init__",
"(",
"self",
",",
"cloud",
")",
":",
"self",
".",
"cloud",
"=",
"cloud",
"self",
".",
"_unsub_dispatcher",
"=",
"None"
] | [
26,
4
] | [
29,
37
] | python | en | ['en', 'haw', 'en'] | True |
CloudRemoteBinary.name | (self) | Return the name of the binary sensor, if any. | Return the name of the binary sensor, if any. | def name(self) -> str:
"""Return the name of the binary sensor, if any."""
return "Remote UI" | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"\"Remote UI\""
] | [
32,
4
] | [
34,
26
] | python | en | ['en', 'ig', 'en'] | True |
CloudRemoteBinary.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self) -> str:
"""Return a unique ID."""
return "cloud-remote-ui-connectivity" | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"\"cloud-remote-ui-connectivity\""
] | [
37,
4
] | [
39,
45
] | python | ca | ['fr', 'ca', 'en'] | False |
CloudRemoteBinary.is_on | (self) | Return true if the binary sensor is on. | Return true if the binary sensor is on. | def is_on(self) -> bool:
"""Return true if the binary sensor is on."""
return self.cloud.remote.is_connected | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"cloud",
".",
"remote",
".",
"is_connected"
] | [
42,
4
] | [
44,
45
] | python | en | ['en', 'fy', 'en'] | True |
CloudRemoteBinary.device_class | (self) | Return the class of this device, from component DEVICE_CLASSES. | Return the class of this device, from component DEVICE_CLASSES. | def device_class(self) -> str:
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_CONNECTIVITY | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_CONNECTIVITY"
] | [
47,
4
] | [
49,
40
] | python | en | ['en', 'en', 'en'] | True |
CloudRemoteBinary.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self) -> bool:
"""Return True if entity is available."""
return self.cloud.remote.certificate is not None | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"cloud",
".",
"remote",
".",
"certificate",
"is",
"not",
"None"
] | [
52,
4
] | [
54,
56
] | python | en | ['en', 'en', 'en'] | True |
CloudRemoteBinary.should_poll | (self) | Return True if entity has to be polled for state. | Return True if entity has to be polled for state. | def should_poll(self) -> bool:
"""Return True if entity has to be polled for state."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"False"
] | [
57,
4
] | [
59,
20
] | python | en | ['en', 'en', 'en'] | True |
CloudRemoteBinary.async_added_to_hass | (self) | Register update dispatcher. | Register update dispatcher. | async def async_added_to_hass(self):
"""Register update dispatcher."""
async def async_state_update(data):
"""Update callback."""
await asyncio.sleep(WAIT_UNTIL_CHANGE)
self.async_write_ha_state()
self._unsub_dispatcher = async_dispatcher_connect(
self.hass, DISPATCHER_REMOTE_UPDATE, async_state_update
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"async",
"def",
"async_state_update",
"(",
"data",
")",
":",
"\"\"\"Update callback.\"\"\"",
"await",
"asyncio",
".",
"sleep",
"(",
"WAIT_UNTIL_CHANGE",
")",
"self",
".",
"async_write_ha_state",
"(",
")",
"self",
".",
"_unsub_dispatcher",
"=",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"DISPATCHER_REMOTE_UPDATE",
",",
"async_state_update",
")"
] | [
61,
4
] | [
71,
9
] | python | de | ['it', 'de', 'en'] | False |
CloudRemoteBinary.async_will_remove_from_hass | (self) | Register update dispatcher. | Register update dispatcher. | async def async_will_remove_from_hass(self):
"""Register update dispatcher."""
if self._unsub_dispatcher is not None:
self._unsub_dispatcher()
self._unsub_dispatcher = None | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"if",
"self",
".",
"_unsub_dispatcher",
"is",
"not",
"None",
":",
"self",
".",
"_unsub_dispatcher",
"(",
")",
"self",
".",
"_unsub_dispatcher",
"=",
"None"
] | [
73,
4
] | [
77,
41
] | python | de | ['it', 'de', 'en'] | False |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Honeywell thermostat. | Set up the Honeywell thermostat. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Honeywell thermostat."""
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
try:
client = somecomfort.SomeComfort(username, password)
except somecomfort.AuthError:
_LOGGER.error("Failed to login to honeywell account %s", username)
return
except somecomfort.SomeComfortError:
_LOGGER.error(
"Failed to initialize the Honeywell client: "
"Check your configuration (username, password), "
"or maybe you have exceeded the API rate limit?"
)
return
dev_id = config.get(CONF_DEV_ID)
loc_id = config.get(CONF_LOC_ID)
cool_away_temp = config.get(CONF_COOL_AWAY_TEMPERATURE)
heat_away_temp = config.get(CONF_HEAT_AWAY_TEMPERATURE)
add_entities(
[
HoneywellUSThermostat(
client,
device,
cool_away_temp,
heat_away_temp,
username,
password,
)
for location in client.locations_by_id.values()
for device in location.devices_by_id.values()
if (
(not loc_id or location.locationid == loc_id)
and (not dev_id or device.deviceid == dev_id)
)
]
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"username",
"=",
"config",
".",
"get",
"(",
"CONF_USERNAME",
")",
"password",
"=",
"config",
".",
"get",
"(",
"CONF_PASSWORD",
")",
"try",
":",
"client",
"=",
"somecomfort",
".",
"SomeComfort",
"(",
"username",
",",
"password",
")",
"except",
"somecomfort",
".",
"AuthError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to login to honeywell account %s\"",
",",
"username",
")",
"return",
"except",
"somecomfort",
".",
"SomeComfortError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to initialize the Honeywell client: \"",
"\"Check your configuration (username, password), \"",
"\"or maybe you have exceeded the API rate limit?\"",
")",
"return",
"dev_id",
"=",
"config",
".",
"get",
"(",
"CONF_DEV_ID",
")",
"loc_id",
"=",
"config",
".",
"get",
"(",
"CONF_LOC_ID",
")",
"cool_away_temp",
"=",
"config",
".",
"get",
"(",
"CONF_COOL_AWAY_TEMPERATURE",
")",
"heat_away_temp",
"=",
"config",
".",
"get",
"(",
"CONF_HEAT_AWAY_TEMPERATURE",
")",
"add_entities",
"(",
"[",
"HoneywellUSThermostat",
"(",
"client",
",",
"device",
",",
"cool_away_temp",
",",
"heat_away_temp",
",",
"username",
",",
"password",
",",
")",
"for",
"location",
"in",
"client",
".",
"locations_by_id",
".",
"values",
"(",
")",
"for",
"device",
"in",
"location",
".",
"devices_by_id",
".",
"values",
"(",
")",
"if",
"(",
"(",
"not",
"loc_id",
"or",
"location",
".",
"locationid",
"==",
"loc_id",
")",
"and",
"(",
"not",
"dev_id",
"or",
"device",
".",
"deviceid",
"==",
"dev_id",
")",
")",
"]",
")"
] | [
106,
0
] | [
146,
5
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.__init__ | (
self, client, device, cool_away_temp, heat_away_temp, username, password
) | Initialize the thermostat. | Initialize the thermostat. | def __init__(
self, client, device, cool_away_temp, heat_away_temp, username, password
):
"""Initialize the thermostat."""
self._client = client
self._device = device
self._cool_away_temp = cool_away_temp
self._heat_away_temp = heat_away_temp
self._away = False
self._username = username
self._password = password
_LOGGER.debug("latestData = %s ", device._data)
# not all honeywell HVACs support all modes
mappings = [v for k, v in HVAC_MODE_TO_HW_MODE.items() if device.raw_ui_data[k]]
self._hvac_mode_map = {k: v for d in mappings for k, v in d.items()}
self._supported_features = (
SUPPORT_PRESET_MODE
| SUPPORT_TARGET_TEMPERATURE
| SUPPORT_TARGET_TEMPERATURE_RANGE
)
if device._data["canControlHumidification"]:
self._supported_features |= SUPPORT_TARGET_HUMIDITY
if device.raw_ui_data["SwitchEmergencyHeatAllowed"]:
self._supported_features |= SUPPORT_AUX_HEAT
if not device._data["hasFan"]:
return
# not all honeywell fans support all modes
mappings = [v for k, v in FAN_MODE_TO_HW.items() if device.raw_fan_data[k]]
self._fan_mode_map = {k: v for d in mappings for k, v in d.items()}
self._supported_features |= SUPPORT_FAN_MODE | [
"def",
"__init__",
"(",
"self",
",",
"client",
",",
"device",
",",
"cool_away_temp",
",",
"heat_away_temp",
",",
"username",
",",
"password",
")",
":",
"self",
".",
"_client",
"=",
"client",
"self",
".",
"_device",
"=",
"device",
"self",
".",
"_cool_away_temp",
"=",
"cool_away_temp",
"self",
".",
"_heat_away_temp",
"=",
"heat_away_temp",
"self",
".",
"_away",
"=",
"False",
"self",
".",
"_username",
"=",
"username",
"self",
".",
"_password",
"=",
"password",
"_LOGGER",
".",
"debug",
"(",
"\"latestData = %s \"",
",",
"device",
".",
"_data",
")",
"# not all honeywell HVACs support all modes",
"mappings",
"=",
"[",
"v",
"for",
"k",
",",
"v",
"in",
"HVAC_MODE_TO_HW_MODE",
".",
"items",
"(",
")",
"if",
"device",
".",
"raw_ui_data",
"[",
"k",
"]",
"]",
"self",
".",
"_hvac_mode_map",
"=",
"{",
"k",
":",
"v",
"for",
"d",
"in",
"mappings",
"for",
"k",
",",
"v",
"in",
"d",
".",
"items",
"(",
")",
"}",
"self",
".",
"_supported_features",
"=",
"(",
"SUPPORT_PRESET_MODE",
"|",
"SUPPORT_TARGET_TEMPERATURE",
"|",
"SUPPORT_TARGET_TEMPERATURE_RANGE",
")",
"if",
"device",
".",
"_data",
"[",
"\"canControlHumidification\"",
"]",
":",
"self",
".",
"_supported_features",
"|=",
"SUPPORT_TARGET_HUMIDITY",
"if",
"device",
".",
"raw_ui_data",
"[",
"\"SwitchEmergencyHeatAllowed\"",
"]",
":",
"self",
".",
"_supported_features",
"|=",
"SUPPORT_AUX_HEAT",
"if",
"not",
"device",
".",
"_data",
"[",
"\"hasFan\"",
"]",
":",
"return",
"# not all honeywell fans support all modes",
"mappings",
"=",
"[",
"v",
"for",
"k",
",",
"v",
"in",
"FAN_MODE_TO_HW",
".",
"items",
"(",
")",
"if",
"device",
".",
"raw_fan_data",
"[",
"k",
"]",
"]",
"self",
".",
"_fan_mode_map",
"=",
"{",
"k",
":",
"v",
"for",
"d",
"in",
"mappings",
"for",
"k",
",",
"v",
"in",
"d",
".",
"items",
"(",
")",
"}",
"self",
".",
"_supported_features",
"|=",
"SUPPORT_FAN_MODE"
] | [
152,
4
] | [
189,
52
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.name | (self) | Return the name of the honeywell, if any. | Return the name of the honeywell, if any. | def name(self) -> Optional[str]:
"""Return the name of the honeywell, if any."""
return self._device.name | [
"def",
"name",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"self",
".",
"_device",
".",
"name"
] | [
192,
4
] | [
194,
32
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.device_state_attributes | (self) | Return the device specific state attributes. | Return the device specific state attributes. | def device_state_attributes(self) -> Dict[str, Any]:
"""Return the device specific state attributes."""
data = {}
data[ATTR_FAN_ACTION] = "running" if self._device.fan_running else "idle"
if self._device.raw_dr_data:
data["dr_phase"] = self._device.raw_dr_data.get("Phase")
return data | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"data",
"=",
"{",
"}",
"data",
"[",
"ATTR_FAN_ACTION",
"]",
"=",
"\"running\"",
"if",
"self",
".",
"_device",
".",
"fan_running",
"else",
"\"idle\"",
"if",
"self",
".",
"_device",
".",
"raw_dr_data",
":",
"data",
"[",
"\"dr_phase\"",
"]",
"=",
"self",
".",
"_device",
".",
"raw_dr_data",
".",
"get",
"(",
"\"Phase\"",
")",
"return",
"data"
] | [
197,
4
] | [
203,
19
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.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 self._supported_features | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_supported_features"
] | [
206,
4
] | [
208,
39
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.min_temp | (self) | Return the minimum temperature. | Return the minimum temperature. | def min_temp(self) -> float:
"""Return the minimum temperature."""
if self.hvac_mode in [HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL]:
return self._device.raw_ui_data["CoolLowerSetptLimit"]
if self.hvac_mode == HVAC_MODE_HEAT:
return self._device.raw_ui_data["HeatLowerSetptLimit"]
return None | [
"def",
"min_temp",
"(",
"self",
")",
"->",
"float",
":",
"if",
"self",
".",
"hvac_mode",
"in",
"[",
"HVAC_MODE_COOL",
",",
"HVAC_MODE_HEAT_COOL",
"]",
":",
"return",
"self",
".",
"_device",
".",
"raw_ui_data",
"[",
"\"CoolLowerSetptLimit\"",
"]",
"if",
"self",
".",
"hvac_mode",
"==",
"HVAC_MODE_HEAT",
":",
"return",
"self",
".",
"_device",
".",
"raw_ui_data",
"[",
"\"HeatLowerSetptLimit\"",
"]",
"return",
"None"
] | [
211,
4
] | [
217,
19
] | python | en | ['en', 'la', 'en'] | True |
HoneywellUSThermostat.max_temp | (self) | Return the maximum temperature. | Return the maximum temperature. | def max_temp(self) -> float:
"""Return the maximum temperature."""
if self.hvac_mode == HVAC_MODE_COOL:
return self._device.raw_ui_data["CoolUpperSetptLimit"]
if self.hvac_mode in [HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL]:
return self._device.raw_ui_data["HeatUpperSetptLimit"]
return None | [
"def",
"max_temp",
"(",
"self",
")",
"->",
"float",
":",
"if",
"self",
".",
"hvac_mode",
"==",
"HVAC_MODE_COOL",
":",
"return",
"self",
".",
"_device",
".",
"raw_ui_data",
"[",
"\"CoolUpperSetptLimit\"",
"]",
"if",
"self",
".",
"hvac_mode",
"in",
"[",
"HVAC_MODE_HEAT",
",",
"HVAC_MODE_HEAT_COOL",
"]",
":",
"return",
"self",
".",
"_device",
".",
"raw_ui_data",
"[",
"\"HeatUpperSetptLimit\"",
"]",
"return",
"None"
] | [
220,
4
] | [
226,
19
] | python | en | ['en', 'la', 'en'] | True |
HoneywellUSThermostat.temperature_unit | (self) | Return the unit of measurement. | Return the unit of measurement. | def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS if self._device.temperature_unit == "C" else TEMP_FAHRENHEIT | [
"def",
"temperature_unit",
"(",
"self",
")",
"->",
"str",
":",
"return",
"TEMP_CELSIUS",
"if",
"self",
".",
"_device",
".",
"temperature_unit",
"==",
"\"C\"",
"else",
"TEMP_FAHRENHEIT"
] | [
229,
4
] | [
231,
88
] | python | en | ['en', 'la', 'en'] | True |
HoneywellUSThermostat.current_humidity | (self) | Return the current humidity. | Return the current humidity. | def current_humidity(self) -> Optional[int]:
"""Return the current humidity."""
return self._device.current_humidity | [
"def",
"current_humidity",
"(",
"self",
")",
"->",
"Optional",
"[",
"int",
"]",
":",
"return",
"self",
".",
"_device",
".",
"current_humidity"
] | [
234,
4
] | [
236,
44
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.hvac_mode | (self) | Return hvac operation ie. heat, cool mode. | Return hvac operation ie. heat, cool mode. | def hvac_mode(self) -> str:
"""Return hvac operation ie. heat, cool mode."""
return HW_MODE_TO_HVAC_MODE[self._device.system_mode] | [
"def",
"hvac_mode",
"(",
"self",
")",
"->",
"str",
":",
"return",
"HW_MODE_TO_HVAC_MODE",
"[",
"self",
".",
"_device",
".",
"system_mode",
"]"
] | [
239,
4
] | [
241,
61
] | python | bg | ['en', 'bg', 'bg'] | True |
HoneywellUSThermostat.hvac_modes | (self) | Return the list of available hvac operation modes. | Return the list of available hvac operation modes. | def hvac_modes(self) -> List[str]:
"""Return the list of available hvac operation modes."""
return list(self._hvac_mode_map) | [
"def",
"hvac_modes",
"(",
"self",
")",
"->",
"List",
"[",
"str",
"]",
":",
"return",
"list",
"(",
"self",
".",
"_hvac_mode_map",
")"
] | [
244,
4
] | [
246,
40
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.hvac_action | (self) | Return the current running hvac operation if supported. | Return the current running hvac operation if supported. | def hvac_action(self) -> Optional[str]:
"""Return the current running hvac operation if supported."""
if self.hvac_mode == HVAC_MODE_OFF:
return None
return HW_MODE_TO_HA_HVAC_ACTION[self._device.equipment_output_status] | [
"def",
"hvac_action",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"if",
"self",
".",
"hvac_mode",
"==",
"HVAC_MODE_OFF",
":",
"return",
"None",
"return",
"HW_MODE_TO_HA_HVAC_ACTION",
"[",
"self",
".",
"_device",
".",
"equipment_output_status",
"]"
] | [
249,
4
] | [
253,
78
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.current_temperature | (self) | Return the current temperature. | Return the current temperature. | def current_temperature(self) -> Optional[float]:
"""Return the current temperature."""
return self._device.current_temperature | [
"def",
"current_temperature",
"(",
"self",
")",
"->",
"Optional",
"[",
"float",
"]",
":",
"return",
"self",
".",
"_device",
".",
"current_temperature"
] | [
256,
4
] | [
258,
47
] | python | en | ['en', 'la', 'en'] | True |
HoneywellUSThermostat.target_temperature | (self) | Return the temperature we try to reach. | Return the temperature we try to reach. | def target_temperature(self) -> Optional[float]:
"""Return the temperature we try to reach."""
if self.hvac_mode == HVAC_MODE_COOL:
return self._device.setpoint_cool
if self.hvac_mode == HVAC_MODE_HEAT:
return self._device.setpoint_heat
return None | [
"def",
"target_temperature",
"(",
"self",
")",
"->",
"Optional",
"[",
"float",
"]",
":",
"if",
"self",
".",
"hvac_mode",
"==",
"HVAC_MODE_COOL",
":",
"return",
"self",
".",
"_device",
".",
"setpoint_cool",
"if",
"self",
".",
"hvac_mode",
"==",
"HVAC_MODE_HEAT",
":",
"return",
"self",
".",
"_device",
".",
"setpoint_heat",
"return",
"None"
] | [
261,
4
] | [
267,
19
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.target_temperature_high | (self) | Return the highbound target temperature we try to reach. | Return the highbound target temperature we try to reach. | def target_temperature_high(self) -> Optional[float]:
"""Return the highbound target temperature we try to reach."""
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
return self._device.setpoint_cool
return None | [
"def",
"target_temperature_high",
"(",
"self",
")",
"->",
"Optional",
"[",
"float",
"]",
":",
"if",
"self",
".",
"hvac_mode",
"==",
"HVAC_MODE_HEAT_COOL",
":",
"return",
"self",
".",
"_device",
".",
"setpoint_cool",
"return",
"None"
] | [
270,
4
] | [
274,
19
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.target_temperature_low | (self) | Return the lowbound target temperature we try to reach. | Return the lowbound target temperature we try to reach. | def target_temperature_low(self) -> Optional[float]:
"""Return the lowbound target temperature we try to reach."""
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
return self._device.setpoint_heat
return None | [
"def",
"target_temperature_low",
"(",
"self",
")",
"->",
"Optional",
"[",
"float",
"]",
":",
"if",
"self",
".",
"hvac_mode",
"==",
"HVAC_MODE_HEAT_COOL",
":",
"return",
"self",
".",
"_device",
".",
"setpoint_heat",
"return",
"None"
] | [
277,
4
] | [
281,
19
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.preset_mode | (self) | Return the current preset mode, e.g., home, away, temp. | Return the current preset mode, e.g., home, away, temp. | def preset_mode(self) -> Optional[str]:
"""Return the current preset mode, e.g., home, away, temp."""
return PRESET_AWAY if self._away else None | [
"def",
"preset_mode",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"PRESET_AWAY",
"if",
"self",
".",
"_away",
"else",
"None"
] | [
284,
4
] | [
286,
50
] | python | en | ['en', 'pt', 'en'] | True |
HoneywellUSThermostat.preset_modes | (self) | Return a list of available preset modes. | Return a list of available preset modes. | def preset_modes(self) -> Optional[List[str]]:
"""Return a list of available preset modes."""
return [PRESET_NONE, PRESET_AWAY] | [
"def",
"preset_modes",
"(",
"self",
")",
"->",
"Optional",
"[",
"List",
"[",
"str",
"]",
"]",
":",
"return",
"[",
"PRESET_NONE",
",",
"PRESET_AWAY",
"]"
] | [
289,
4
] | [
291,
41
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.is_aux_heat | (self) | Return true if aux heater. | Return true if aux heater. | def is_aux_heat(self) -> Optional[str]:
"""Return true if aux heater."""
return self._device.system_mode == "emheat" | [
"def",
"is_aux_heat",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"self",
".",
"_device",
".",
"system_mode",
"==",
"\"emheat\""
] | [
294,
4
] | [
296,
51
] | python | fr | ['fr', 'co', 'fr'] | True |
HoneywellUSThermostat.fan_mode | (self) | Return the fan setting. | Return the fan setting. | def fan_mode(self) -> Optional[str]:
"""Return the fan setting."""
return HW_FAN_MODE_TO_HA[self._device.fan_mode] | [
"def",
"fan_mode",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"HW_FAN_MODE_TO_HA",
"[",
"self",
".",
"_device",
".",
"fan_mode",
"]"
] | [
299,
4
] | [
301,
55
] | python | en | ['en', 'fy', 'en'] | True |
HoneywellUSThermostat.fan_modes | (self) | Return the list of available fan modes. | Return the list of available fan modes. | def fan_modes(self) -> Optional[List[str]]:
"""Return the list of available fan modes."""
return list(self._fan_mode_map) | [
"def",
"fan_modes",
"(",
"self",
")",
"->",
"Optional",
"[",
"List",
"[",
"str",
"]",
"]",
":",
"return",
"list",
"(",
"self",
".",
"_fan_mode_map",
")"
] | [
304,
4
] | [
306,
39
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat._set_temperature | (self, **kwargs) | Set new target temperature. | Set new target temperature. | def _set_temperature(self, **kwargs) -> None:
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
try:
# Get current mode
mode = self._device.system_mode
# Set hold if this is not the case
if getattr(self._device, f"hold_{mode}") is False:
# Get next period key
next_period_key = f"{mode.capitalize()}NextPeriod"
# Get next period raw value
next_period = self._device.raw_ui_data.get(next_period_key)
# Get next period time
hour, minute = divmod(next_period * 15, 60)
# Set hold time
setattr(self._device, f"hold_{mode}", datetime.time(hour, minute))
# Set temperature
setattr(self._device, f"setpoint_{mode}", temperature)
except somecomfort.SomeComfortError:
_LOGGER.error("Temperature %.1f out of range", temperature) | [
"def",
"_set_temperature",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"temperature",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TEMPERATURE",
")",
"if",
"temperature",
"is",
"None",
":",
"return",
"try",
":",
"# Get current mode",
"mode",
"=",
"self",
".",
"_device",
".",
"system_mode",
"# Set hold if this is not the case",
"if",
"getattr",
"(",
"self",
".",
"_device",
",",
"f\"hold_{mode}\"",
")",
"is",
"False",
":",
"# Get next period key",
"next_period_key",
"=",
"f\"{mode.capitalize()}NextPeriod\"",
"# Get next period raw value",
"next_period",
"=",
"self",
".",
"_device",
".",
"raw_ui_data",
".",
"get",
"(",
"next_period_key",
")",
"# Get next period time",
"hour",
",",
"minute",
"=",
"divmod",
"(",
"next_period",
"*",
"15",
",",
"60",
")",
"# Set hold time",
"setattr",
"(",
"self",
".",
"_device",
",",
"f\"hold_{mode}\"",
",",
"datetime",
".",
"time",
"(",
"hour",
",",
"minute",
")",
")",
"# Set temperature",
"setattr",
"(",
"self",
".",
"_device",
",",
"f\"setpoint_{mode}\"",
",",
"temperature",
")",
"except",
"somecomfort",
".",
"SomeComfortError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Temperature %.1f out of range\"",
",",
"temperature",
")"
] | [
308,
4
] | [
329,
71
] | python | en | ['en', 'ca', 'en'] | True |
HoneywellUSThermostat.set_temperature | (self, **kwargs) | Set new target temperature. | Set new target temperature. | def set_temperature(self, **kwargs) -> None:
"""Set new target temperature."""
if {HVAC_MODE_COOL, HVAC_MODE_HEAT} & set(self._hvac_mode_map):
self._set_temperature(**kwargs)
try:
if HVAC_MODE_HEAT_COOL in self._hvac_mode_map:
temperature = kwargs.get(ATTR_TARGET_TEMP_HIGH)
if temperature:
self._device.setpoint_cool = temperature
temperature = kwargs.get(ATTR_TARGET_TEMP_LOW)
if temperature:
self._device.setpoint_heat = temperature
except somecomfort.SomeComfortError as err:
_LOGGER.error("Invalid temperature %s: %s", temperature, err) | [
"def",
"set_temperature",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"if",
"{",
"HVAC_MODE_COOL",
",",
"HVAC_MODE_HEAT",
"}",
"&",
"set",
"(",
"self",
".",
"_hvac_mode_map",
")",
":",
"self",
".",
"_set_temperature",
"(",
"*",
"*",
"kwargs",
")",
"try",
":",
"if",
"HVAC_MODE_HEAT_COOL",
"in",
"self",
".",
"_hvac_mode_map",
":",
"temperature",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TARGET_TEMP_HIGH",
")",
"if",
"temperature",
":",
"self",
".",
"_device",
".",
"setpoint_cool",
"=",
"temperature",
"temperature",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TARGET_TEMP_LOW",
")",
"if",
"temperature",
":",
"self",
".",
"_device",
".",
"setpoint_heat",
"=",
"temperature",
"except",
"somecomfort",
".",
"SomeComfortError",
"as",
"err",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid temperature %s: %s\"",
",",
"temperature",
",",
"err",
")"
] | [
331,
4
] | [
345,
73
] | python | en | ['en', 'ca', 'en'] | True |
HoneywellUSThermostat.set_fan_mode | (self, fan_mode: str) | Set new target fan mode. | Set new target fan mode. | def set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode."""
self._device.fan_mode = self._fan_mode_map[fan_mode] | [
"def",
"set_fan_mode",
"(",
"self",
",",
"fan_mode",
":",
"str",
")",
"->",
"None",
":",
"self",
".",
"_device",
".",
"fan_mode",
"=",
"self",
".",
"_fan_mode_map",
"[",
"fan_mode",
"]"
] | [
347,
4
] | [
349,
60
] | python | en | ['sv', 'fy', 'en'] | False |
HoneywellUSThermostat.set_hvac_mode | (self, hvac_mode: str) | Set new target hvac mode. | Set new target hvac mode. | def set_hvac_mode(self, hvac_mode: str) -> None:
"""Set new target hvac mode."""
self._device.system_mode = self._hvac_mode_map[hvac_mode] | [
"def",
"set_hvac_mode",
"(",
"self",
",",
"hvac_mode",
":",
"str",
")",
"->",
"None",
":",
"self",
".",
"_device",
".",
"system_mode",
"=",
"self",
".",
"_hvac_mode_map",
"[",
"hvac_mode",
"]"
] | [
351,
4
] | [
353,
65
] | python | da | ['da', 'su', 'en'] | False |
HoneywellUSThermostat._turn_away_mode_on | (self) | Turn away on.
Somecomfort does have a proprietary away mode, but it doesn't really
work the way it should. For example: If you set a temperature manually
it doesn't get overwritten when away mode is switched on.
| Turn away on. | def _turn_away_mode_on(self) -> None:
"""Turn away on.
Somecomfort does have a proprietary away mode, but it doesn't really
work the way it should. For example: If you set a temperature manually
it doesn't get overwritten when away mode is switched on.
"""
self._away = True
try:
# Get current mode
mode = self._device.system_mode
except somecomfort.SomeComfortError:
_LOGGER.error("Can not get system mode")
return
try:
# Set permanent hold
setattr(self._device, f"hold_{mode}", True)
# Set temperature
setattr(
self._device, f"setpoint_{mode}", getattr(self, f"_{mode}_away_temp")
)
except somecomfort.SomeComfortError:
_LOGGER.error(
"Temperature %.1f out of range", getattr(self, f"_{mode}_away_temp")
) | [
"def",
"_turn_away_mode_on",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"_away",
"=",
"True",
"try",
":",
"# Get current mode",
"mode",
"=",
"self",
".",
"_device",
".",
"system_mode",
"except",
"somecomfort",
".",
"SomeComfortError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Can not get system mode\"",
")",
"return",
"try",
":",
"# Set permanent hold",
"setattr",
"(",
"self",
".",
"_device",
",",
"f\"hold_{mode}\"",
",",
"True",
")",
"# Set temperature",
"setattr",
"(",
"self",
".",
"_device",
",",
"f\"setpoint_{mode}\"",
",",
"getattr",
"(",
"self",
",",
"f\"_{mode}_away_temp\"",
")",
")",
"except",
"somecomfort",
".",
"SomeComfortError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Temperature %.1f out of range\"",
",",
"getattr",
"(",
"self",
",",
"f\"_{mode}_away_temp\"",
")",
")"
] | [
355,
4
] | [
380,
13
] | python | en | ['en', 'yo', 'en'] | True |
HoneywellUSThermostat._turn_away_mode_off | (self) | Turn away off. | Turn away off. | def _turn_away_mode_off(self) -> None:
"""Turn away off."""
self._away = False
try:
# Disabling all hold modes
self._device.hold_cool = False
self._device.hold_heat = False
except somecomfort.SomeComfortError:
_LOGGER.error("Can not stop hold mode") | [
"def",
"_turn_away_mode_off",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"_away",
"=",
"False",
"try",
":",
"# Disabling all hold modes",
"self",
".",
"_device",
".",
"hold_cool",
"=",
"False",
"self",
".",
"_device",
".",
"hold_heat",
"=",
"False",
"except",
"somecomfort",
".",
"SomeComfortError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Can not stop hold mode\"",
")"
] | [
382,
4
] | [
390,
51
] | python | en | ['en', 'yo', 'en'] | True |
HoneywellUSThermostat.set_preset_mode | (self, preset_mode: str) | Set new preset mode. | Set new preset mode. | def set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if preset_mode == PRESET_AWAY:
self._turn_away_mode_on()
else:
self._turn_away_mode_off() | [
"def",
"set_preset_mode",
"(",
"self",
",",
"preset_mode",
":",
"str",
")",
"->",
"None",
":",
"if",
"preset_mode",
"==",
"PRESET_AWAY",
":",
"self",
".",
"_turn_away_mode_on",
"(",
")",
"else",
":",
"self",
".",
"_turn_away_mode_off",
"(",
")"
] | [
392,
4
] | [
397,
38
] | python | en | ['en', 'sr', 'en'] | True |
HoneywellUSThermostat.turn_aux_heat_on | (self) | Turn auxiliary heater on. | Turn auxiliary heater on. | def turn_aux_heat_on(self) -> None:
"""Turn auxiliary heater on."""
self._device.system_mode = "emheat" | [
"def",
"turn_aux_heat_on",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"_device",
".",
"system_mode",
"=",
"\"emheat\""
] | [
399,
4
] | [
401,
43
] | python | en | ['fr', 'fi', 'en'] | False |
HoneywellUSThermostat.turn_aux_heat_off | (self) | Turn auxiliary heater off. | Turn auxiliary heater off. | def turn_aux_heat_off(self) -> None:
"""Turn auxiliary heater off."""
if HVAC_MODE_HEAT in self.hvac_modes:
self.set_hvac_mode(HVAC_MODE_HEAT)
else:
self.set_hvac_mode(HVAC_MODE_OFF) | [
"def",
"turn_aux_heat_off",
"(",
"self",
")",
"->",
"None",
":",
"if",
"HVAC_MODE_HEAT",
"in",
"self",
".",
"hvac_modes",
":",
"self",
".",
"set_hvac_mode",
"(",
"HVAC_MODE_HEAT",
")",
"else",
":",
"self",
".",
"set_hvac_mode",
"(",
"HVAC_MODE_OFF",
")"
] | [
403,
4
] | [
408,
45
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat._retry | (self) | Recreate a new somecomfort client.
When we got an error, the best way to be sure that the next query
will succeed, is to recreate a new somecomfort client.
| Recreate a new somecomfort client. | def _retry(self) -> bool:
"""Recreate a new somecomfort client.
When we got an error, the best way to be sure that the next query
will succeed, is to recreate a new somecomfort client.
"""
try:
self._client = somecomfort.SomeComfort(self._username, self._password)
except somecomfort.AuthError:
_LOGGER.error("Failed to login to honeywell account %s", self._username)
return False
except somecomfort.SomeComfortError as ex:
_LOGGER.error("Failed to initialize honeywell client: %s", str(ex))
return False
devices = [
device
for location in self._client.locations_by_id.values()
for device in location.devices_by_id.values()
if device.name == self._device.name
]
if len(devices) != 1:
_LOGGER.error("Failed to find device %s", self._device.name)
return False
self._device = devices[0]
return True | [
"def",
"_retry",
"(",
"self",
")",
"->",
"bool",
":",
"try",
":",
"self",
".",
"_client",
"=",
"somecomfort",
".",
"SomeComfort",
"(",
"self",
".",
"_username",
",",
"self",
".",
"_password",
")",
"except",
"somecomfort",
".",
"AuthError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to login to honeywell account %s\"",
",",
"self",
".",
"_username",
")",
"return",
"False",
"except",
"somecomfort",
".",
"SomeComfortError",
"as",
"ex",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to initialize honeywell client: %s\"",
",",
"str",
"(",
"ex",
")",
")",
"return",
"False",
"devices",
"=",
"[",
"device",
"for",
"location",
"in",
"self",
".",
"_client",
".",
"locations_by_id",
".",
"values",
"(",
")",
"for",
"device",
"in",
"location",
".",
"devices_by_id",
".",
"values",
"(",
")",
"if",
"device",
".",
"name",
"==",
"self",
".",
"_device",
".",
"name",
"]",
"if",
"len",
"(",
"devices",
")",
"!=",
"1",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to find device %s\"",
",",
"self",
".",
"_device",
".",
"name",
")",
"return",
"False",
"self",
".",
"_device",
"=",
"devices",
"[",
"0",
"]",
"return",
"True"
] | [
410,
4
] | [
437,
19
] | python | en | ['en', 'en', 'en'] | True |
HoneywellUSThermostat.update | (self) | Update the state. | Update the state. | def update(self) -> None:
"""Update the state."""
retries = 3
while retries > 0:
try:
self._device.refresh()
break
except (
somecomfort.client.APIRateLimited,
OSError,
requests.exceptions.ReadTimeout,
) as exp:
retries -= 1
if retries == 0:
raise exp
if not self._retry():
raise exp
_LOGGER.error("SomeComfort update failed, Retrying - Error: %s", exp)
_LOGGER.debug(
"latestData = %s ", self._device._data # pylint: disable=protected-access
) | [
"def",
"update",
"(",
"self",
")",
"->",
"None",
":",
"retries",
"=",
"3",
"while",
"retries",
">",
"0",
":",
"try",
":",
"self",
".",
"_device",
".",
"refresh",
"(",
")",
"break",
"except",
"(",
"somecomfort",
".",
"client",
".",
"APIRateLimited",
",",
"OSError",
",",
"requests",
".",
"exceptions",
".",
"ReadTimeout",
",",
")",
"as",
"exp",
":",
"retries",
"-=",
"1",
"if",
"retries",
"==",
"0",
":",
"raise",
"exp",
"if",
"not",
"self",
".",
"_retry",
"(",
")",
":",
"raise",
"exp",
"_LOGGER",
".",
"error",
"(",
"\"SomeComfort update failed, Retrying - Error: %s\"",
",",
"exp",
")",
"_LOGGER",
".",
"debug",
"(",
"\"latestData = %s \"",
",",
"self",
".",
"_device",
".",
"_data",
"# pylint: disable=protected-access",
")"
] | [
439,
4
] | [
460,
9
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass: HomeAssistantType, config: ConfigEntry) | Establish connection with MELCloud. | Establish connection with MELCloud. | async def async_setup(hass: HomeAssistantType, config: ConfigEntry):
"""Establish connection with MELCloud."""
if DOMAIN not in config:
return True
username = config[DOMAIN][CONF_USERNAME]
token = config[DOMAIN][CONF_TOKEN]
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_USERNAME: username, CONF_TOKEN: token},
)
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config",
":",
"ConfigEntry",
")",
":",
"if",
"DOMAIN",
"not",
"in",
"config",
":",
"return",
"True",
"username",
"=",
"config",
"[",
"DOMAIN",
"]",
"[",
"CONF_USERNAME",
"]",
"token",
"=",
"config",
"[",
"DOMAIN",
"]",
"[",
"CONF_TOKEN",
"]",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"{",
"CONF_USERNAME",
":",
"username",
",",
"CONF_TOKEN",
":",
"token",
"}",
",",
")",
")",
"return",
"True"
] | [
41,
0
] | [
55,
15
] | python | en | ['en', 'fr', 'en'] | True |
async_setup_entry | (hass: HomeAssistantType, entry: ConfigEntry) | Establish connection with MELClooud. | Establish connection with MELClooud. | async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Establish connection with MELClooud."""
conf = entry.data
mel_devices = await mel_devices_setup(hass, conf[CONF_TOKEN])
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: mel_devices})
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"conf",
"=",
"entry",
".",
"data",
"mel_devices",
"=",
"await",
"mel_devices_setup",
"(",
"hass",
",",
"conf",
"[",
"CONF_TOKEN",
"]",
")",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
".",
"update",
"(",
"{",
"entry",
".",
"entry_id",
":",
"mel_devices",
"}",
")",
"for",
"platform",
"in",
"PLATFORMS",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"entry",
",",
"platform",
")",
")",
"return",
"True"
] | [
58,
0
] | [
67,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass, config_entry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass, config_entry):
"""Unload a config entry."""
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(config_entry, platform)
for platform in PLATFORMS
]
)
hass.data[DOMAIN].pop(config_entry.entry_id)
if not hass.data[DOMAIN]:
hass.data.pop(DOMAIN)
return True | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
",",
"config_entry",
")",
":",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"config_entry",
",",
"platform",
")",
"for",
"platform",
"in",
"PLATFORMS",
"]",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"config_entry",
".",
"entry_id",
")",
"if",
"not",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
":",
"hass",
".",
"data",
".",
"pop",
"(",
"DOMAIN",
")",
"return",
"True"
] | [
70,
0
] | [
81,
15
] | python | en | ['en', 'es', 'en'] | True |
mel_devices_setup | (hass, token) | Query connected devices from MELCloud. | Query connected devices from MELCloud. | async def mel_devices_setup(hass, token) -> List[MelCloudDevice]:
"""Query connected devices from MELCloud."""
session = hass.helpers.aiohttp_client.async_get_clientsession()
try:
with timeout(10):
all_devices = await get_devices(
token,
session,
conf_update_interval=timedelta(minutes=5),
device_set_debounce=timedelta(seconds=1),
)
except (asyncio.TimeoutError, ClientConnectionError) as ex:
raise ConfigEntryNotReady() from ex
wrapped_devices = {}
for device_type, devices in all_devices.items():
wrapped_devices[device_type] = [MelCloudDevice(device) for device in devices]
return wrapped_devices | [
"async",
"def",
"mel_devices_setup",
"(",
"hass",
",",
"token",
")",
"->",
"List",
"[",
"MelCloudDevice",
"]",
":",
"session",
"=",
"hass",
".",
"helpers",
".",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
")",
"try",
":",
"with",
"timeout",
"(",
"10",
")",
":",
"all_devices",
"=",
"await",
"get_devices",
"(",
"token",
",",
"session",
",",
"conf_update_interval",
"=",
"timedelta",
"(",
"minutes",
"=",
"5",
")",
",",
"device_set_debounce",
"=",
"timedelta",
"(",
"seconds",
"=",
"1",
")",
",",
")",
"except",
"(",
"asyncio",
".",
"TimeoutError",
",",
"ClientConnectionError",
")",
"as",
"ex",
":",
"raise",
"ConfigEntryNotReady",
"(",
")",
"from",
"ex",
"wrapped_devices",
"=",
"{",
"}",
"for",
"device_type",
",",
"devices",
"in",
"all_devices",
".",
"items",
"(",
")",
":",
"wrapped_devices",
"[",
"device_type",
"]",
"=",
"[",
"MelCloudDevice",
"(",
"device",
")",
"for",
"device",
"in",
"devices",
"]",
"return",
"wrapped_devices"
] | [
144,
0
] | [
161,
26
] | python | en | ['en', 'en', 'en'] | True |
MelCloudDevice.__init__ | (self, device: Device) | Construct a device wrapper. | Construct a device wrapper. | def __init__(self, device: Device):
"""Construct a device wrapper."""
self.device = device
self.name = device.name
self._available = True | [
"def",
"__init__",
"(",
"self",
",",
"device",
":",
"Device",
")",
":",
"self",
".",
"device",
"=",
"device",
"self",
".",
"name",
"=",
"device",
".",
"name",
"self",
".",
"_available",
"=",
"True"
] | [
87,
4
] | [
91,
30
] | python | en | ['es', 'en', 'en'] | True |
MelCloudDevice.async_update | (self, **kwargs) | Pull the latest data from MELCloud. | Pull the latest data from MELCloud. | async def async_update(self, **kwargs):
"""Pull the latest data from MELCloud."""
try:
await self.device.update()
self._available = True
except ClientConnectionError:
_LOGGER.warning("Connection failed for %s", self.name)
self._available = False | [
"async",
"def",
"async_update",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"await",
"self",
".",
"device",
".",
"update",
"(",
")",
"self",
".",
"_available",
"=",
"True",
"except",
"ClientConnectionError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Connection failed for %s\"",
",",
"self",
".",
"name",
")",
"self",
".",
"_available",
"=",
"False"
] | [
94,
4
] | [
101,
35
] | python | en | ['en', 'en', 'en'] | True |
MelCloudDevice.async_set | (self, properties: Dict[str, Any]) | Write state changes to the MELCloud API. | Write state changes to the MELCloud API. | async def async_set(self, properties: Dict[str, Any]):
"""Write state changes to the MELCloud API."""
try:
await self.device.set(properties)
self._available = True
except ClientConnectionError:
_LOGGER.warning("Connection failed for %s", self.name)
self._available = False | [
"async",
"def",
"async_set",
"(",
"self",
",",
"properties",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
":",
"try",
":",
"await",
"self",
".",
"device",
".",
"set",
"(",
"properties",
")",
"self",
".",
"_available",
"=",
"True",
"except",
"ClientConnectionError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Connection failed for %s\"",
",",
"self",
".",
"name",
")",
"self",
".",
"_available",
"=",
"False"
] | [
103,
4
] | [
110,
35
] | python | en | ['en', 'en', 'en'] | True |
MelCloudDevice.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self) -> bool:
"""Return True if entity is available."""
return self._available | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_available"
] | [
113,
4
] | [
115,
30
] | python | en | ['en', 'en', 'en'] | True |
MelCloudDevice.device_id | (self) | Return device ID. | Return device ID. | def device_id(self):
"""Return device ID."""
return self.device.device_id | [
"def",
"device_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"device_id"
] | [
118,
4
] | [
120,
36
] | python | en | ['es', 'mt', 'en'] | False |
MelCloudDevice.building_id | (self) | Return building ID of the device. | Return building ID of the device. | def building_id(self):
"""Return building ID of the device."""
return self.device.building_id | [
"def",
"building_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"building_id"
] | [
123,
4
] | [
125,
38
] | python | en | ['en', 'en', 'en'] | True |
MelCloudDevice.device_info | (self) | Return a device description for device registry. | Return a device description for device registry. | def device_info(self):
"""Return a device description for device registry."""
_device_info = {
"connections": {(CONNECTION_NETWORK_MAC, self.device.mac)},
"identifiers": {(DOMAIN, f"{self.device.mac}-{self.device.serial}")},
"manufacturer": "Mitsubishi Electric",
"name": self.name,
}
unit_infos = self.device.units
if unit_infos is not None:
_device_info["model"] = ", ".join(
[x["model"] for x in unit_infos if x["model"]]
)
return _device_info | [
"def",
"device_info",
"(",
"self",
")",
":",
"_device_info",
"=",
"{",
"\"connections\"",
":",
"{",
"(",
"CONNECTION_NETWORK_MAC",
",",
"self",
".",
"device",
".",
"mac",
")",
"}",
",",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"f\"{self.device.mac}-{self.device.serial}\"",
")",
"}",
",",
"\"manufacturer\"",
":",
"\"Mitsubishi Electric\"",
",",
"\"name\"",
":",
"self",
".",
"name",
",",
"}",
"unit_infos",
"=",
"self",
".",
"device",
".",
"units",
"if",
"unit_infos",
"is",
"not",
"None",
":",
"_device_info",
"[",
"\"model\"",
"]",
"=",
"\", \"",
".",
"join",
"(",
"[",
"x",
"[",
"\"model\"",
"]",
"for",
"x",
"in",
"unit_infos",
"if",
"x",
"[",
"\"model\"",
"]",
"]",
")",
"return",
"_device_info"
] | [
128,
4
] | [
141,
27
] | python | en | ['ro', 'fr', 'en'] | False |
create_position_ids_from_input_ids | (input_ids, padding_idx, past_key_values_length=0) |
Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols
are ignored. This is modified from fairseq's `utils.make_positions`.
Args:
x: torch.Tensor x:
Returns: torch.Tensor
|
Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols
are ignored. This is modified from fairseq's `utils.make_positions`. | def create_position_ids_from_input_ids(input_ids, padding_idx, past_key_values_length=0):
"""
Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols
are ignored. This is modified from fairseq's `utils.make_positions`.
Args:
x: torch.Tensor x:
Returns: torch.Tensor
"""
# The series of casts and type-conversions here are carefully balanced to both work with ONNX export and XLA.
mask = input_ids.ne(padding_idx).int()
incremental_indices = (torch.cumsum(mask, dim=1).type_as(mask) + past_key_values_length) * mask
return incremental_indices.long() + padding_idx | [
"def",
"create_position_ids_from_input_ids",
"(",
"input_ids",
",",
"padding_idx",
",",
"past_key_values_length",
"=",
"0",
")",
":",
"# The series of casts and type-conversions here are carefully balanced to both work with ONNX export and XLA.",
"mask",
"=",
"input_ids",
".",
"ne",
"(",
"padding_idx",
")",
".",
"int",
"(",
")",
"incremental_indices",
"=",
"(",
"torch",
".",
"cumsum",
"(",
"mask",
",",
"dim",
"=",
"1",
")",
".",
"type_as",
"(",
"mask",
")",
"+",
"past_key_values_length",
")",
"*",
"mask",
"return",
"incremental_indices",
".",
"long",
"(",
")",
"+",
"padding_idx"
] | [
1493,
0
] | [
1506,
51
] | python | en | ['en', 'error', 'th'] | False |
RobertaEmbeddings.create_position_ids_from_inputs_embeds | (self, inputs_embeds) |
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.
Args:
inputs_embeds: torch.Tensor
Returns: torch.Tensor
|
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids. | def create_position_ids_from_inputs_embeds(self, inputs_embeds):
"""
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.
Args:
inputs_embeds: torch.Tensor
Returns: torch.Tensor
"""
input_shape = inputs_embeds.size()[:-1]
sequence_length = input_shape[1]
position_ids = torch.arange(
self.padding_idx + 1, sequence_length + self.padding_idx + 1, dtype=torch.long, device=inputs_embeds.device
)
return position_ids.unsqueeze(0).expand(input_shape) | [
"def",
"create_position_ids_from_inputs_embeds",
"(",
"self",
",",
"inputs_embeds",
")",
":",
"input_shape",
"=",
"inputs_embeds",
".",
"size",
"(",
")",
"[",
":",
"-",
"1",
"]",
"sequence_length",
"=",
"input_shape",
"[",
"1",
"]",
"position_ids",
"=",
"torch",
".",
"arange",
"(",
"self",
".",
"padding_idx",
"+",
"1",
",",
"sequence_length",
"+",
"self",
".",
"padding_idx",
"+",
"1",
",",
"dtype",
"=",
"torch",
".",
"long",
",",
"device",
"=",
"inputs_embeds",
".",
"device",
")",
"return",
"position_ids",
".",
"unsqueeze",
"(",
"0",
")",
".",
"expand",
"(",
"input_shape",
")"
] | [
127,
4
] | [
142,
60
] | python | en | ['en', 'error', 'th'] | False |
RobertaPreTrainedModel._init_weights | (self, module) | Initialize the weights | Initialize the weights | def _init_weights(self, module):
""" Initialize the weights """
if isinstance(module, nn.Linear):
# Slightly different from the TF version which uses truncated_normal for initialization
# cf https://github.com/pytorch/pytorch/pull/5617
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
if module.bias is not None:
module.bias.data.zero_()
elif isinstance(module, nn.Embedding):
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
if module.padding_idx is not None:
module.weight.data[module.padding_idx].zero_()
elif isinstance(module, nn.LayerNorm):
module.bias.data.zero_()
module.weight.data.fill_(1.0) | [
"def",
"_init_weights",
"(",
"self",
",",
"module",
")",
":",
"if",
"isinstance",
"(",
"module",
",",
"nn",
".",
"Linear",
")",
":",
"# Slightly different from the TF version which uses truncated_normal for initialization",
"# cf https://github.com/pytorch/pytorch/pull/5617",
"module",
".",
"weight",
".",
"data",
".",
"normal_",
"(",
"mean",
"=",
"0.0",
",",
"std",
"=",
"self",
".",
"config",
".",
"initializer_range",
")",
"if",
"module",
".",
"bias",
"is",
"not",
"None",
":",
"module",
".",
"bias",
".",
"data",
".",
"zero_",
"(",
")",
"elif",
"isinstance",
"(",
"module",
",",
"nn",
".",
"Embedding",
")",
":",
"module",
".",
"weight",
".",
"data",
".",
"normal_",
"(",
"mean",
"=",
"0.0",
",",
"std",
"=",
"self",
".",
"config",
".",
"initializer_range",
")",
"if",
"module",
".",
"padding_idx",
"is",
"not",
"None",
":",
"module",
".",
"weight",
".",
"data",
"[",
"module",
".",
"padding_idx",
"]",
".",
"zero_",
"(",
")",
"elif",
"isinstance",
"(",
"module",
",",
"nn",
".",
"LayerNorm",
")",
":",
"module",
".",
"bias",
".",
"data",
".",
"zero_",
"(",
")",
"module",
".",
"weight",
".",
"data",
".",
"fill_",
"(",
"1.0",
")"
] | [
575,
4
] | [
589,
41
] | python | en | ['en', 'en', 'en'] | True |
mz_mock | () | Mock pychromecast MultizoneManager. | Mock pychromecast MultizoneManager. | def mz_mock():
"""Mock pychromecast MultizoneManager."""
return MagicMock() | [
"def",
"mz_mock",
"(",
")",
":",
"return",
"MagicMock",
"(",
")"
] | [
24,
0
] | [
26,
22
] | python | en | ['en', 'zu', 'pt'] | False |
quick_play_mock | () | Mock pychromecast quick_play. | Mock pychromecast quick_play. | def quick_play_mock():
"""Mock pychromecast quick_play."""
return MagicMock() | [
"def",
"quick_play_mock",
"(",
")",
":",
"return",
"MagicMock",
"(",
")"
] | [
30,
0
] | [
32,
22
] | python | en | ['fr', 'sr', 'en'] | False |
cast_mock | (mz_mock, quick_play_mock) | Mock pychromecast. | Mock pychromecast. | def cast_mock(mz_mock, quick_play_mock):
"""Mock pychromecast."""
pycast_mock = MagicMock()
pycast_mock.start_discovery.return_value = (None, Mock())
dial_mock = MagicMock(name="XXX")
dial_mock.get_device_status.return_value.uuid = "fake_uuid"
dial_mock.get_device_status.return_value.manufacturer = "fake_manufacturer"
dial_mock.get_device_status.return_value.model_name = "fake_model_name"
dial_mock.get_device_status.return_value.friendly_name = "fake_friendly_name"
with patch(
"homeassistant.components.cast.media_player.pychromecast", pycast_mock
), patch(
"homeassistant.components.cast.discovery.pychromecast", pycast_mock
), patch(
"homeassistant.components.cast.media_player.MultizoneManager",
return_value=mz_mock,
), patch(
"homeassistant.components.cast.media_player.zeroconf.async_get_instance",
AsyncMock(),
), patch(
"homeassistant.components.cast.media_player.quick_play",
quick_play_mock,
):
yield | [
"def",
"cast_mock",
"(",
"mz_mock",
",",
"quick_play_mock",
")",
":",
"pycast_mock",
"=",
"MagicMock",
"(",
")",
"pycast_mock",
".",
"start_discovery",
".",
"return_value",
"=",
"(",
"None",
",",
"Mock",
"(",
")",
")",
"dial_mock",
"=",
"MagicMock",
"(",
"name",
"=",
"\"XXX\"",
")",
"dial_mock",
".",
"get_device_status",
".",
"return_value",
".",
"uuid",
"=",
"\"fake_uuid\"",
"dial_mock",
".",
"get_device_status",
".",
"return_value",
".",
"manufacturer",
"=",
"\"fake_manufacturer\"",
"dial_mock",
".",
"get_device_status",
".",
"return_value",
".",
"model_name",
"=",
"\"fake_model_name\"",
"dial_mock",
".",
"get_device_status",
".",
"return_value",
".",
"friendly_name",
"=",
"\"fake_friendly_name\"",
"with",
"patch",
"(",
"\"homeassistant.components.cast.media_player.pychromecast\"",
",",
"pycast_mock",
")",
",",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast\"",
",",
"pycast_mock",
")",
",",
"patch",
"(",
"\"homeassistant.components.cast.media_player.MultizoneManager\"",
",",
"return_value",
"=",
"mz_mock",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.cast.media_player.zeroconf.async_get_instance\"",
",",
"AsyncMock",
"(",
")",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.cast.media_player.quick_play\"",
",",
"quick_play_mock",
",",
")",
":",
"yield"
] | [
36,
0
] | [
60,
13
] | python | hr | ['pl', 'hr', 'ru'] | False |
get_fake_chromecast | (info: ChromecastInfo) | Generate a Fake Chromecast object with the specified arguments. | Generate a Fake Chromecast object with the specified arguments. | def get_fake_chromecast(info: ChromecastInfo):
"""Generate a Fake Chromecast object with the specified arguments."""
mock = MagicMock(host=info.host, port=info.port, uuid=info.uuid)
mock.media_controller.status = None
return mock | [
"def",
"get_fake_chromecast",
"(",
"info",
":",
"ChromecastInfo",
")",
":",
"mock",
"=",
"MagicMock",
"(",
"host",
"=",
"info",
".",
"host",
",",
"port",
"=",
"info",
".",
"port",
",",
"uuid",
"=",
"info",
".",
"uuid",
")",
"mock",
".",
"media_controller",
".",
"status",
"=",
"None",
"return",
"mock"
] | [
69,
0
] | [
73,
15
] | python | en | ['en', 'en', 'en'] | True |
get_fake_chromecast_info | (
host="192.168.178.42", port=8009, uuid: Optional[UUID] = FakeUUID
) | Generate a Fake ChromecastInfo with the specified arguments. | Generate a Fake ChromecastInfo with the specified arguments. | def get_fake_chromecast_info(
host="192.168.178.42", port=8009, uuid: Optional[UUID] = FakeUUID
):
"""Generate a Fake ChromecastInfo with the specified arguments."""
return ChromecastInfo(
host=host,
port=port,
uuid=uuid,
friendly_name="Speaker",
services={"the-service"},
) | [
"def",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"192.168.178.42\"",
",",
"port",
"=",
"8009",
",",
"uuid",
":",
"Optional",
"[",
"UUID",
"]",
"=",
"FakeUUID",
")",
":",
"return",
"ChromecastInfo",
"(",
"host",
"=",
"host",
",",
"port",
"=",
"port",
",",
"uuid",
"=",
"uuid",
",",
"friendly_name",
"=",
"\"Speaker\"",
",",
"services",
"=",
"{",
"\"the-service\"",
"}",
",",
")"
] | [
76,
0
] | [
86,
5
] | python | en | ['en', 'en', 'en'] | True |
get_fake_zconf | (host="192.168.178.42", port=8009) | Generate a Fake Zeroconf object with the specified arguments. | Generate a Fake Zeroconf object with the specified arguments. | def get_fake_zconf(host="192.168.178.42", port=8009):
"""Generate a Fake Zeroconf object with the specified arguments."""
parsed_addresses = MagicMock()
parsed_addresses.return_value = [host]
service_info = MagicMock(parsed_addresses=parsed_addresses, port=port)
zconf = MagicMock()
zconf.get_service_info.return_value = service_info
return zconf | [
"def",
"get_fake_zconf",
"(",
"host",
"=",
"\"192.168.178.42\"",
",",
"port",
"=",
"8009",
")",
":",
"parsed_addresses",
"=",
"MagicMock",
"(",
")",
"parsed_addresses",
".",
"return_value",
"=",
"[",
"host",
"]",
"service_info",
"=",
"MagicMock",
"(",
"parsed_addresses",
"=",
"parsed_addresses",
",",
"port",
"=",
"port",
")",
"zconf",
"=",
"MagicMock",
"(",
")",
"zconf",
".",
"get_service_info",
".",
"return_value",
"=",
"service_info",
"return",
"zconf"
] | [
89,
0
] | [
96,
16
] | python | en | ['en', 'en', 'en'] | True |
async_setup_cast | (hass, config=None) | Set up the cast platform. | Set up the cast platform. | async def async_setup_cast(hass, config=None):
"""Set up the cast platform."""
if config is None:
config = {}
with patch(
"homeassistant.helpers.entity_platform.EntityPlatform._async_schedule_add_entities"
) as add_entities:
MockConfigEntry(domain="cast").add_to_hass(hass)
await async_setup_component(hass, "cast", {"cast": {"media_player": config}})
await hass.async_block_till_done()
return add_entities | [
"async",
"def",
"async_setup_cast",
"(",
"hass",
",",
"config",
"=",
"None",
")",
":",
"if",
"config",
"is",
"None",
":",
"config",
"=",
"{",
"}",
"with",
"patch",
"(",
"\"homeassistant.helpers.entity_platform.EntityPlatform._async_schedule_add_entities\"",
")",
"as",
"add_entities",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"\"cast\"",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"cast\"",
",",
"{",
"\"cast\"",
":",
"{",
"\"media_player\"",
":",
"config",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"return",
"add_entities"
] | [
99,
0
] | [
110,
23
] | python | en | ['en', 'da', 'en'] | True |
async_setup_cast_internal_discovery | (hass, config=None) | Set up the cast platform and the discovery. | Set up the cast platform and the discovery. | async def async_setup_cast_internal_discovery(hass, config=None):
"""Set up the cast platform and the discovery."""
listener = MagicMock(services={})
browser = MagicMock(zc={})
with patch(
"homeassistant.components.cast.discovery.pychromecast.CastListener",
return_value=listener,
) as cast_listener, patch(
"homeassistant.components.cast.discovery.pychromecast.start_discovery",
return_value=browser,
) as start_discovery:
add_entities = await async_setup_cast(hass, config)
await hass.async_block_till_done()
await hass.async_block_till_done()
assert start_discovery.call_count == 1
discovery_callback = cast_listener.call_args[0][0]
def discover_chromecast(service_name: str, info: ChromecastInfo) -> None:
"""Discover a chromecast device."""
listener.services[info.uuid] = (
{service_name},
info.uuid,
info.model_name,
info.friendly_name,
)
discovery_callback(info.uuid, service_name)
return discover_chromecast, add_entities | [
"async",
"def",
"async_setup_cast_internal_discovery",
"(",
"hass",
",",
"config",
"=",
"None",
")",
":",
"listener",
"=",
"MagicMock",
"(",
"services",
"=",
"{",
"}",
")",
"browser",
"=",
"MagicMock",
"(",
"zc",
"=",
"{",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast.CastListener\"",
",",
"return_value",
"=",
"listener",
",",
")",
"as",
"cast_listener",
",",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast.start_discovery\"",
",",
"return_value",
"=",
"browser",
",",
")",
"as",
"start_discovery",
":",
"add_entities",
"=",
"await",
"async_setup_cast",
"(",
"hass",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"start_discovery",
".",
"call_count",
"==",
"1",
"discovery_callback",
"=",
"cast_listener",
".",
"call_args",
"[",
"0",
"]",
"[",
"0",
"]",
"def",
"discover_chromecast",
"(",
"service_name",
":",
"str",
",",
"info",
":",
"ChromecastInfo",
")",
"->",
"None",
":",
"\"\"\"Discover a chromecast device.\"\"\"",
"listener",
".",
"services",
"[",
"info",
".",
"uuid",
"]",
"=",
"(",
"{",
"service_name",
"}",
",",
"info",
".",
"uuid",
",",
"info",
".",
"model_name",
",",
"info",
".",
"friendly_name",
",",
")",
"discovery_callback",
"(",
"info",
".",
"uuid",
",",
"service_name",
")",
"return",
"discover_chromecast",
",",
"add_entities"
] | [
113,
0
] | [
143,
44
] | python | en | ['en', 'en', 'en'] | True |
async_setup_media_player_cast | (hass: HomeAssistantType, info: ChromecastInfo) | Set up the cast platform with async_setup_component. | Set up the cast platform with async_setup_component. | async def async_setup_media_player_cast(hass: HomeAssistantType, info: ChromecastInfo):
"""Set up the cast platform with async_setup_component."""
listener = MagicMock(services={})
browser = MagicMock(zc={})
chromecast = get_fake_chromecast(info)
zconf = get_fake_zconf(host=info.host, port=info.port)
with patch(
"homeassistant.components.cast.discovery.pychromecast.get_chromecast_from_service",
return_value=chromecast,
) as get_chromecast, patch(
"homeassistant.components.cast.discovery.pychromecast.CastListener",
return_value=listener,
) as cast_listener, patch(
"homeassistant.components.cast.discovery.pychromecast.start_discovery",
return_value=browser,
), patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf,
):
await async_setup_component(
hass, "cast", {"cast": {"media_player": {"uuid": info.uuid}}}
)
await hass.async_block_till_done()
discovery_callback = cast_listener.call_args[0][0]
service_name = "the-service"
listener.services[info.uuid] = (
{service_name},
info.uuid,
info.model_name,
info.friendly_name,
)
discovery_callback(info.uuid, service_name)
await hass.async_block_till_done()
await hass.async_block_till_done()
assert get_chromecast.call_count == 1
return chromecast | [
"async",
"def",
"async_setup_media_player_cast",
"(",
"hass",
":",
"HomeAssistantType",
",",
"info",
":",
"ChromecastInfo",
")",
":",
"listener",
"=",
"MagicMock",
"(",
"services",
"=",
"{",
"}",
")",
"browser",
"=",
"MagicMock",
"(",
"zc",
"=",
"{",
"}",
")",
"chromecast",
"=",
"get_fake_chromecast",
"(",
"info",
")",
"zconf",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"info",
".",
"host",
",",
"port",
"=",
"info",
".",
"port",
")",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast.get_chromecast_from_service\"",
",",
"return_value",
"=",
"chromecast",
",",
")",
"as",
"get_chromecast",
",",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast.CastListener\"",
",",
"return_value",
"=",
"listener",
",",
")",
"as",
"cast_listener",
",",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast.start_discovery\"",
",",
"return_value",
"=",
"browser",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf",
",",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"cast\"",
",",
"{",
"\"cast\"",
":",
"{",
"\"media_player\"",
":",
"{",
"\"uuid\"",
":",
"info",
".",
"uuid",
"}",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"discovery_callback",
"=",
"cast_listener",
".",
"call_args",
"[",
"0",
"]",
"[",
"0",
"]",
"service_name",
"=",
"\"the-service\"",
"listener",
".",
"services",
"[",
"info",
".",
"uuid",
"]",
"=",
"(",
"{",
"service_name",
"}",
",",
"info",
".",
"uuid",
",",
"info",
".",
"model_name",
",",
"info",
".",
"friendly_name",
",",
")",
"discovery_callback",
"(",
"info",
".",
"uuid",
",",
"service_name",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"get_chromecast",
".",
"call_count",
"==",
"1",
"return",
"chromecast"
] | [
146,
0
] | [
185,
25
] | python | en | ['en', 'fr', 'en'] | True |
get_status_callbacks | (chromecast_mock, mz_mock=None) | Get registered status callbacks from the chromecast mock. | Get registered status callbacks from the chromecast mock. | def get_status_callbacks(chromecast_mock, mz_mock=None):
"""Get registered status callbacks from the chromecast mock."""
status_listener = chromecast_mock.register_status_listener.call_args[0][0]
cast_status_cb = status_listener.new_cast_status
connection_listener = chromecast_mock.register_connection_listener.call_args[0][0]
conn_status_cb = connection_listener.new_connection_status
mc = chromecast_mock.socket_client.media_controller
media_status_cb = mc.register_status_listener.call_args[0][0].new_media_status
if not mz_mock:
return cast_status_cb, conn_status_cb, media_status_cb
mz_listener = mz_mock.register_listener.call_args[0][1]
group_media_status_cb = mz_listener.multizone_new_media_status
return cast_status_cb, conn_status_cb, media_status_cb, group_media_status_cb | [
"def",
"get_status_callbacks",
"(",
"chromecast_mock",
",",
"mz_mock",
"=",
"None",
")",
":",
"status_listener",
"=",
"chromecast_mock",
".",
"register_status_listener",
".",
"call_args",
"[",
"0",
"]",
"[",
"0",
"]",
"cast_status_cb",
"=",
"status_listener",
".",
"new_cast_status",
"connection_listener",
"=",
"chromecast_mock",
".",
"register_connection_listener",
".",
"call_args",
"[",
"0",
"]",
"[",
"0",
"]",
"conn_status_cb",
"=",
"connection_listener",
".",
"new_connection_status",
"mc",
"=",
"chromecast_mock",
".",
"socket_client",
".",
"media_controller",
"media_status_cb",
"=",
"mc",
".",
"register_status_listener",
".",
"call_args",
"[",
"0",
"]",
"[",
"0",
"]",
".",
"new_media_status",
"if",
"not",
"mz_mock",
":",
"return",
"cast_status_cb",
",",
"conn_status_cb",
",",
"media_status_cb",
"mz_listener",
"=",
"mz_mock",
".",
"register_listener",
".",
"call_args",
"[",
"0",
"]",
"[",
"1",
"]",
"group_media_status_cb",
"=",
"mz_listener",
".",
"multizone_new_media_status",
"return",
"cast_status_cb",
",",
"conn_status_cb",
",",
"media_status_cb",
",",
"group_media_status_cb"
] | [
188,
0
] | [
204,
81
] | python | en | ['en', 'no', 'en'] | True |
test_start_discovery_called_once | (hass) | Test pychromecast.start_discovery called exactly once. | Test pychromecast.start_discovery called exactly once. | async def test_start_discovery_called_once(hass):
"""Test pychromecast.start_discovery called exactly once."""
with patch(
"homeassistant.components.cast.discovery.pychromecast.start_discovery",
return_value=Mock(),
) as start_discovery:
await async_setup_cast(hass)
assert start_discovery.call_count == 1
await async_setup_cast(hass)
assert start_discovery.call_count == 1 | [
"async",
"def",
"test_start_discovery_called_once",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast.start_discovery\"",
",",
"return_value",
"=",
"Mock",
"(",
")",
",",
")",
"as",
"start_discovery",
":",
"await",
"async_setup_cast",
"(",
"hass",
")",
"assert",
"start_discovery",
".",
"call_count",
"==",
"1",
"await",
"async_setup_cast",
"(",
"hass",
")",
"assert",
"start_discovery",
".",
"call_count",
"==",
"1"
] | [
207,
0
] | [
218,
46
] | python | en | ['en', 'en', 'en'] | True |
test_stop_discovery_called_on_stop | (hass) | Test pychromecast.stop_discovery called on shutdown. | Test pychromecast.stop_discovery called on shutdown. | async def test_stop_discovery_called_on_stop(hass):
"""Test pychromecast.stop_discovery called on shutdown."""
browser = MagicMock(zc={})
with patch(
"homeassistant.components.cast.discovery.pychromecast.start_discovery",
return_value=browser,
) as start_discovery:
# start_discovery should be called with empty config
await async_setup_cast(hass, {})
assert start_discovery.call_count == 1
with patch(
"homeassistant.components.cast.discovery.pychromecast.discovery.stop_discovery"
) as stop_discovery:
# stop discovery should be called on shutdown
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
await hass.async_block_till_done()
stop_discovery.assert_called_once_with(browser) | [
"async",
"def",
"test_stop_discovery_called_on_stop",
"(",
"hass",
")",
":",
"browser",
"=",
"MagicMock",
"(",
"zc",
"=",
"{",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast.start_discovery\"",
",",
"return_value",
"=",
"browser",
",",
")",
"as",
"start_discovery",
":",
"# start_discovery should be called with empty config",
"await",
"async_setup_cast",
"(",
"hass",
",",
"{",
"}",
")",
"assert",
"start_discovery",
".",
"call_count",
"==",
"1",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.pychromecast.discovery.stop_discovery\"",
")",
"as",
"stop_discovery",
":",
"# stop discovery should be called on shutdown",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_HOMEASSISTANT_STOP",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"stop_discovery",
".",
"assert_called_once_with",
"(",
"browser",
")"
] | [
221,
0
] | [
241,
55
] | python | en | ['en', 'en', 'en'] | True |
test_create_cast_device_without_uuid | (hass) | Test create a cast device with no UUId does not create an entity. | Test create a cast device with no UUId does not create an entity. | async def test_create_cast_device_without_uuid(hass):
"""Test create a cast device with no UUId does not create an entity."""
info = get_fake_chromecast_info(uuid=None)
cast_device = cast._async_create_cast_device(hass, info)
assert cast_device is None | [
"async",
"def",
"test_create_cast_device_without_uuid",
"(",
"hass",
")",
":",
"info",
"=",
"get_fake_chromecast_info",
"(",
"uuid",
"=",
"None",
")",
"cast_device",
"=",
"cast",
".",
"_async_create_cast_device",
"(",
"hass",
",",
"info",
")",
"assert",
"cast_device",
"is",
"None"
] | [
244,
0
] | [
248,
30
] | python | en | ['en', 'en', 'en'] | True |
test_create_cast_device_with_uuid | (hass) | Test create cast devices with UUID creates entities. | Test create cast devices with UUID creates entities. | async def test_create_cast_device_with_uuid(hass):
"""Test create cast devices with UUID creates entities."""
added_casts = hass.data[cast.ADDED_CAST_DEVICES_KEY] = set()
info = get_fake_chromecast_info()
cast_device = cast._async_create_cast_device(hass, info)
assert cast_device is not None
assert info.uuid in added_casts
# Sending second time should not create new entity
cast_device = cast._async_create_cast_device(hass, info)
assert cast_device is None | [
"async",
"def",
"test_create_cast_device_with_uuid",
"(",
"hass",
")",
":",
"added_casts",
"=",
"hass",
".",
"data",
"[",
"cast",
".",
"ADDED_CAST_DEVICES_KEY",
"]",
"=",
"set",
"(",
")",
"info",
"=",
"get_fake_chromecast_info",
"(",
")",
"cast_device",
"=",
"cast",
".",
"_async_create_cast_device",
"(",
"hass",
",",
"info",
")",
"assert",
"cast_device",
"is",
"not",
"None",
"assert",
"info",
".",
"uuid",
"in",
"added_casts",
"# Sending second time should not create new entity",
"cast_device",
"=",
"cast",
".",
"_async_create_cast_device",
"(",
"hass",
",",
"info",
")",
"assert",
"cast_device",
"is",
"None"
] | [
251,
0
] | [
262,
30
] | python | en | ['en', 'en', 'en'] | True |
test_replay_past_chromecasts | (hass) | Test cast platform re-playing past chromecasts when adding new one. | Test cast platform re-playing past chromecasts when adding new one. | async def test_replay_past_chromecasts(hass):
"""Test cast platform re-playing past chromecasts when adding new one."""
cast_group1 = get_fake_chromecast_info(host="host1", port=8009, uuid=FakeUUID)
cast_group2 = get_fake_chromecast_info(
host="host2", port=8009, uuid=UUID("9462202c-e747-4af5-a66b-7dce0e1ebc09")
)
zconf_1 = get_fake_zconf(host="host1", port=8009)
zconf_2 = get_fake_zconf(host="host2", port=8009)
discover_cast, add_dev1 = await async_setup_cast_internal_discovery(
hass, config={"uuid": FakeUUID}
)
with patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf_2,
):
discover_cast("service2", cast_group2)
await hass.async_block_till_done()
await hass.async_block_till_done() # having tasks that add jobs
assert add_dev1.call_count == 0
with patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf_1,
):
discover_cast("service1", cast_group1)
await hass.async_block_till_done()
await hass.async_block_till_done() # having tasks that add jobs
assert add_dev1.call_count == 1
add_dev2 = Mock()
await cast._async_setup_platform(hass, {"host": "host2"}, add_dev2)
await hass.async_block_till_done()
assert add_dev2.call_count == 1 | [
"async",
"def",
"test_replay_past_chromecasts",
"(",
"hass",
")",
":",
"cast_group1",
"=",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"host1\"",
",",
"port",
"=",
"8009",
",",
"uuid",
"=",
"FakeUUID",
")",
"cast_group2",
"=",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"host2\"",
",",
"port",
"=",
"8009",
",",
"uuid",
"=",
"UUID",
"(",
"\"9462202c-e747-4af5-a66b-7dce0e1ebc09\"",
")",
")",
"zconf_1",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"\"host1\"",
",",
"port",
"=",
"8009",
")",
"zconf_2",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"\"host2\"",
",",
"port",
"=",
"8009",
")",
"discover_cast",
",",
"add_dev1",
"=",
"await",
"async_setup_cast_internal_discovery",
"(",
"hass",
",",
"config",
"=",
"{",
"\"uuid\"",
":",
"FakeUUID",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf_2",
",",
")",
":",
"discover_cast",
"(",
"\"service2\"",
",",
"cast_group2",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# having tasks that add jobs",
"assert",
"add_dev1",
".",
"call_count",
"==",
"0",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf_1",
",",
")",
":",
"discover_cast",
"(",
"\"service1\"",
",",
"cast_group1",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# having tasks that add jobs",
"assert",
"add_dev1",
".",
"call_count",
"==",
"1",
"add_dev2",
"=",
"Mock",
"(",
")",
"await",
"cast",
".",
"_async_setup_platform",
"(",
"hass",
",",
"{",
"\"host\"",
":",
"\"host2\"",
"}",
",",
"add_dev2",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"add_dev2",
".",
"call_count",
"==",
"1"
] | [
265,
0
] | [
299,
35
] | python | en | ['en', 'en', 'en'] | True |
test_manual_cast_chromecasts_uuid | (hass) | Test only wanted casts are added for manual configuration. | Test only wanted casts are added for manual configuration. | async def test_manual_cast_chromecasts_uuid(hass):
"""Test only wanted casts are added for manual configuration."""
cast_1 = get_fake_chromecast_info(host="host_1", uuid=FakeUUID)
cast_2 = get_fake_chromecast_info(host="host_2", uuid=FakeUUID2)
zconf_1 = get_fake_zconf(host="host_1")
zconf_2 = get_fake_zconf(host="host_2")
# Manual configuration of media player with host "configured_host"
discover_cast, add_dev1 = await async_setup_cast_internal_discovery(
hass, config={"uuid": FakeUUID}
)
with patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf_2,
):
discover_cast("service2", cast_2)
await hass.async_block_till_done()
await hass.async_block_till_done() # having tasks that add jobs
assert add_dev1.call_count == 0
with patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf_1,
):
discover_cast("service1", cast_1)
await hass.async_block_till_done()
await hass.async_block_till_done() # having tasks that add jobs
assert add_dev1.call_count == 1 | [
"async",
"def",
"test_manual_cast_chromecasts_uuid",
"(",
"hass",
")",
":",
"cast_1",
"=",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"host_1\"",
",",
"uuid",
"=",
"FakeUUID",
")",
"cast_2",
"=",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"host_2\"",
",",
"uuid",
"=",
"FakeUUID2",
")",
"zconf_1",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"\"host_1\"",
")",
"zconf_2",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"\"host_2\"",
")",
"# Manual configuration of media player with host \"configured_host\"",
"discover_cast",
",",
"add_dev1",
"=",
"await",
"async_setup_cast_internal_discovery",
"(",
"hass",
",",
"config",
"=",
"{",
"\"uuid\"",
":",
"FakeUUID",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf_2",
",",
")",
":",
"discover_cast",
"(",
"\"service2\"",
",",
"cast_2",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# having tasks that add jobs",
"assert",
"add_dev1",
".",
"call_count",
"==",
"0",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf_1",
",",
")",
":",
"discover_cast",
"(",
"\"service1\"",
",",
"cast_1",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# having tasks that add jobs",
"assert",
"add_dev1",
".",
"call_count",
"==",
"1"
] | [
302,
0
] | [
329,
35
] | python | en | ['en', 'en', 'en'] | True |
test_auto_cast_chromecasts | (hass) | Test all discovered casts are added for default configuration. | Test all discovered casts are added for default configuration. | async def test_auto_cast_chromecasts(hass):
"""Test all discovered casts are added for default configuration."""
cast_1 = get_fake_chromecast_info(host="some_host")
cast_2 = get_fake_chromecast_info(host="other_host", uuid=FakeUUID2)
zconf_1 = get_fake_zconf(host="some_host")
zconf_2 = get_fake_zconf(host="other_host")
# Manual configuration of media player with host "configured_host"
discover_cast, add_dev1 = await async_setup_cast_internal_discovery(hass)
with patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf_1,
):
discover_cast("service2", cast_2)
await hass.async_block_till_done()
await hass.async_block_till_done() # having tasks that add jobs
assert add_dev1.call_count == 1
with patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf_2,
):
discover_cast("service1", cast_1)
await hass.async_block_till_done()
await hass.async_block_till_done() # having tasks that add jobs
assert add_dev1.call_count == 2 | [
"async",
"def",
"test_auto_cast_chromecasts",
"(",
"hass",
")",
":",
"cast_1",
"=",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"some_host\"",
")",
"cast_2",
"=",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"other_host\"",
",",
"uuid",
"=",
"FakeUUID2",
")",
"zconf_1",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"\"some_host\"",
")",
"zconf_2",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"\"other_host\"",
")",
"# Manual configuration of media player with host \"configured_host\"",
"discover_cast",
",",
"add_dev1",
"=",
"await",
"async_setup_cast_internal_discovery",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf_1",
",",
")",
":",
"discover_cast",
"(",
"\"service2\"",
",",
"cast_2",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# having tasks that add jobs",
"assert",
"add_dev1",
".",
"call_count",
"==",
"1",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf_2",
",",
")",
":",
"discover_cast",
"(",
"\"service1\"",
",",
"cast_1",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# having tasks that add jobs",
"assert",
"add_dev1",
".",
"call_count",
"==",
"2"
] | [
332,
0
] | [
357,
35
] | python | en | ['en', 'en', 'en'] | True |
test_update_cast_chromecasts | (hass) | Test discovery of same UUID twice only adds one cast. | Test discovery of same UUID twice only adds one cast. | async def test_update_cast_chromecasts(hass):
"""Test discovery of same UUID twice only adds one cast."""
cast_1 = get_fake_chromecast_info(host="old_host")
cast_2 = get_fake_chromecast_info(host="new_host")
zconf_1 = get_fake_zconf(host="old_host")
zconf_2 = get_fake_zconf(host="new_host")
# Manual configuration of media player with host "configured_host"
discover_cast, add_dev1 = await async_setup_cast_internal_discovery(hass)
with patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf_1,
):
discover_cast("service1", cast_1)
await hass.async_block_till_done()
await hass.async_block_till_done() # having tasks that add jobs
assert add_dev1.call_count == 1
with patch(
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
return_value=zconf_2,
):
discover_cast("service2", cast_2)
await hass.async_block_till_done()
await hass.async_block_till_done() # having tasks that add jobs
assert add_dev1.call_count == 1 | [
"async",
"def",
"test_update_cast_chromecasts",
"(",
"hass",
")",
":",
"cast_1",
"=",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"old_host\"",
")",
"cast_2",
"=",
"get_fake_chromecast_info",
"(",
"host",
"=",
"\"new_host\"",
")",
"zconf_1",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"\"old_host\"",
")",
"zconf_2",
"=",
"get_fake_zconf",
"(",
"host",
"=",
"\"new_host\"",
")",
"# Manual configuration of media player with host \"configured_host\"",
"discover_cast",
",",
"add_dev1",
"=",
"await",
"async_setup_cast_internal_discovery",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf_1",
",",
")",
":",
"discover_cast",
"(",
"\"service1\"",
",",
"cast_1",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# having tasks that add jobs",
"assert",
"add_dev1",
".",
"call_count",
"==",
"1",
"with",
"patch",
"(",
"\"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf\"",
",",
"return_value",
"=",
"zconf_2",
",",
")",
":",
"discover_cast",
"(",
"\"service2\"",
",",
"cast_2",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# having tasks that add jobs",
"assert",
"add_dev1",
".",
"call_count",
"==",
"1"
] | [
360,
0
] | [
386,
35
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.