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 |
---|---|---|---|---|---|---|---|---|---|---|---|
HomeKit.reset_accessories | (self, entity_ids) | Reset the accessory to load the latest configuration. | Reset the accessory to load the latest configuration. | def reset_accessories(self, entity_ids):
"""Reset the accessory to load the latest configuration."""
if not self.bridge:
self.driver.config_changed()
return
aid_storage = self.hass.data[DOMAIN][self._entry_id][AID_STORAGE]
removed = []
for entity_id in entity_ids:
aid = aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
if aid not in self.bridge.accessories:
continue
_LOGGER.info(
"HomeKit Bridge %s will reset accessory with linked entity_id %s",
self._name,
entity_id,
)
acc = self.remove_bridge_accessory(aid)
removed.append(acc)
if not removed:
# No matched accessories, probably on another bridge
return
self.driver.config_changed()
for acc in removed:
self.bridge.add_accessory(acc)
self.driver.config_changed() | [
"def",
"reset_accessories",
"(",
"self",
",",
"entity_ids",
")",
":",
"if",
"not",
"self",
".",
"bridge",
":",
"self",
".",
"driver",
".",
"config_changed",
"(",
")",
"return",
"aid_storage",
"=",
"self",
".",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"self",
".",
"_entry_id",
"]",
"[",
"AID_STORAGE",
"]",
"removed",
"=",
"[",
"]",
"for",
"entity_id",
"in",
"entity_ids",
":",
"aid",
"=",
"aid_storage",
".",
"get_or_allocate_aid_for_entity_id",
"(",
"entity_id",
")",
"if",
"aid",
"not",
"in",
"self",
".",
"bridge",
".",
"accessories",
":",
"continue",
"_LOGGER",
".",
"info",
"(",
"\"HomeKit Bridge %s will reset accessory with linked entity_id %s\"",
",",
"self",
".",
"_name",
",",
"entity_id",
",",
")",
"acc",
"=",
"self",
".",
"remove_bridge_accessory",
"(",
"aid",
")",
"removed",
".",
"append",
"(",
"acc",
")",
"if",
"not",
"removed",
":",
"# No matched accessories, probably on another bridge",
"return",
"self",
".",
"driver",
".",
"config_changed",
"(",
")",
"for",
"acc",
"in",
"removed",
":",
"self",
".",
"bridge",
".",
"add_accessory",
"(",
"acc",
")",
"self",
".",
"driver",
".",
"config_changed",
"(",
")"
] | [
476,
4
] | [
506,
36
] | python | en | ['en', 'en', 'en'] | True |
HomeKit.add_bridge_accessory | (self, state) | Try adding accessory to bridge if configured beforehand. | Try adding accessory to bridge if configured beforehand. | def add_bridge_accessory(self, state):
"""Try adding accessory to bridge if configured beforehand."""
if not self._filter(state.entity_id):
return
# The bridge itself counts as an accessory
if len(self.bridge.accessories) + 1 >= MAX_DEVICES:
_LOGGER.warning(
"Cannot add %s as this would exceed the %d device limit. Consider using the filter option",
state.entity_id,
MAX_DEVICES,
)
return
aid = self.hass.data[DOMAIN][self._entry_id][
AID_STORAGE
].get_or_allocate_aid_for_entity_id(state.entity_id)
conf = self._config.pop(state.entity_id, {})
# If an accessory cannot be created or added due to an exception
# of any kind (usually in pyhap) it should not prevent
# the rest of the accessories from being created
try:
acc = get_accessory(self.hass, self.driver, state, aid, conf)
if acc is not None:
self.bridge.add_accessory(acc)
except Exception: # pylint: disable=broad-except
_LOGGER.exception(
"Failed to create a HomeKit accessory for %s", state.entity_id
) | [
"def",
"add_bridge_accessory",
"(",
"self",
",",
"state",
")",
":",
"if",
"not",
"self",
".",
"_filter",
"(",
"state",
".",
"entity_id",
")",
":",
"return",
"# The bridge itself counts as an accessory",
"if",
"len",
"(",
"self",
".",
"bridge",
".",
"accessories",
")",
"+",
"1",
">=",
"MAX_DEVICES",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Cannot add %s as this would exceed the %d device limit. Consider using the filter option\"",
",",
"state",
".",
"entity_id",
",",
"MAX_DEVICES",
",",
")",
"return",
"aid",
"=",
"self",
".",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"self",
".",
"_entry_id",
"]",
"[",
"AID_STORAGE",
"]",
".",
"get_or_allocate_aid_for_entity_id",
"(",
"state",
".",
"entity_id",
")",
"conf",
"=",
"self",
".",
"_config",
".",
"pop",
"(",
"state",
".",
"entity_id",
",",
"{",
"}",
")",
"# If an accessory cannot be created or added due to an exception",
"# of any kind (usually in pyhap) it should not prevent",
"# the rest of the accessories from being created",
"try",
":",
"acc",
"=",
"get_accessory",
"(",
"self",
".",
"hass",
",",
"self",
".",
"driver",
",",
"state",
",",
"aid",
",",
"conf",
")",
"if",
"acc",
"is",
"not",
"None",
":",
"self",
".",
"bridge",
".",
"add_accessory",
"(",
"acc",
")",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"_LOGGER",
".",
"exception",
"(",
"\"Failed to create a HomeKit accessory for %s\"",
",",
"state",
".",
"entity_id",
")"
] | [
508,
4
] | [
536,
13
] | python | en | ['en', 'en', 'en'] | True |
HomeKit.remove_bridge_accessory | (self, aid) | Try adding accessory to bridge if configured beforehand. | Try adding accessory to bridge if configured beforehand. | def remove_bridge_accessory(self, aid):
"""Try adding accessory to bridge if configured beforehand."""
acc = None
if aid in self.bridge.accessories:
acc = self.bridge.accessories.pop(aid)
return acc | [
"def",
"remove_bridge_accessory",
"(",
"self",
",",
"aid",
")",
":",
"acc",
"=",
"None",
"if",
"aid",
"in",
"self",
".",
"bridge",
".",
"accessories",
":",
"acc",
"=",
"self",
".",
"bridge",
".",
"accessories",
".",
"pop",
"(",
"aid",
")",
"return",
"acc"
] | [
538,
4
] | [
543,
18
] | python | en | ['en', 'en', 'en'] | True |
HomeKit.async_start | (self, *args) | Start the accessory driver. | Start the accessory driver. | async def async_start(self, *args):
"""Start the accessory driver."""
if self.status != STATUS_READY:
return
self.status = STATUS_WAIT
ent_reg = await entity_registry.async_get_registry(self.hass)
dev_reg = await device_registry.async_get_registry(self.hass)
device_lookup = ent_reg.async_get_device_class_lookup(
{
(BINARY_SENSOR_DOMAIN, DEVICE_CLASS_BATTERY_CHARGING),
(BINARY_SENSOR_DOMAIN, DEVICE_CLASS_MOTION),
(BINARY_SENSOR_DOMAIN, DEVICE_CLASS_OCCUPANCY),
(SENSOR_DOMAIN, DEVICE_CLASS_BATTERY),
(SENSOR_DOMAIN, DEVICE_CLASS_HUMIDITY),
}
)
bridged_states = []
for state in self.hass.states.async_all():
if not self._filter(state.entity_id):
continue
ent_reg_ent = ent_reg.async_get(state.entity_id)
if ent_reg_ent:
await self._async_set_device_info_attributes(
ent_reg_ent, dev_reg, state.entity_id
)
self._async_configure_linked_sensors(ent_reg_ent, device_lookup, state)
bridged_states.append(state)
self._async_register_bridge(dev_reg)
await self.hass.async_add_executor_job(self._start, bridged_states)
_LOGGER.debug("Driver start for %s", self._name)
self.hass.add_job(self.driver.start_service)
self.status = STATUS_RUNNING | [
"async",
"def",
"async_start",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"status",
"!=",
"STATUS_READY",
":",
"return",
"self",
".",
"status",
"=",
"STATUS_WAIT",
"ent_reg",
"=",
"await",
"entity_registry",
".",
"async_get_registry",
"(",
"self",
".",
"hass",
")",
"dev_reg",
"=",
"await",
"device_registry",
".",
"async_get_registry",
"(",
"self",
".",
"hass",
")",
"device_lookup",
"=",
"ent_reg",
".",
"async_get_device_class_lookup",
"(",
"{",
"(",
"BINARY_SENSOR_DOMAIN",
",",
"DEVICE_CLASS_BATTERY_CHARGING",
")",
",",
"(",
"BINARY_SENSOR_DOMAIN",
",",
"DEVICE_CLASS_MOTION",
")",
",",
"(",
"BINARY_SENSOR_DOMAIN",
",",
"DEVICE_CLASS_OCCUPANCY",
")",
",",
"(",
"SENSOR_DOMAIN",
",",
"DEVICE_CLASS_BATTERY",
")",
",",
"(",
"SENSOR_DOMAIN",
",",
"DEVICE_CLASS_HUMIDITY",
")",
",",
"}",
")",
"bridged_states",
"=",
"[",
"]",
"for",
"state",
"in",
"self",
".",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
":",
"if",
"not",
"self",
".",
"_filter",
"(",
"state",
".",
"entity_id",
")",
":",
"continue",
"ent_reg_ent",
"=",
"ent_reg",
".",
"async_get",
"(",
"state",
".",
"entity_id",
")",
"if",
"ent_reg_ent",
":",
"await",
"self",
".",
"_async_set_device_info_attributes",
"(",
"ent_reg_ent",
",",
"dev_reg",
",",
"state",
".",
"entity_id",
")",
"self",
".",
"_async_configure_linked_sensors",
"(",
"ent_reg_ent",
",",
"device_lookup",
",",
"state",
")",
"bridged_states",
".",
"append",
"(",
"state",
")",
"self",
".",
"_async_register_bridge",
"(",
"dev_reg",
")",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"_start",
",",
"bridged_states",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Driver start for %s\"",
",",
"self",
".",
"_name",
")",
"self",
".",
"hass",
".",
"add_job",
"(",
"self",
".",
"driver",
".",
"start_service",
")",
"self",
".",
"status",
"=",
"STATUS_RUNNING"
] | [
545,
4
] | [
582,
36
] | python | en | ['en', 'en', 'en'] | True |
HomeKit._async_register_bridge | (self, dev_reg) | Register the bridge as a device so homekit_controller and exclude it from discovery. | Register the bridge as a device so homekit_controller and exclude it from discovery. | def _async_register_bridge(self, dev_reg):
"""Register the bridge as a device so homekit_controller and exclude it from discovery."""
formatted_mac = device_registry.format_mac(self.driver.state.mac)
# Connections and identifiers are both used here.
#
# connections exists so homekit_controller can know the
# virtual mac address of the bridge and know to not offer
# it via discovery.
#
# identifiers is used as well since the virtual mac may change
# because it will not survive manual pairing resets (deleting state file)
# which we have trained users to do over the past few years
# because this was the way you had to fix homekit when pairing
# failed.
#
connection = (device_registry.CONNECTION_NETWORK_MAC, formatted_mac)
identifier = (DOMAIN, self._entry_id, BRIDGE_SERIAL_NUMBER)
self._async_purge_old_bridges(dev_reg, identifier, connection)
dev_reg.async_get_or_create(
config_entry_id=self._entry_id,
identifiers={identifier},
connections={connection},
manufacturer=MANUFACTURER,
name=self._name,
model="Home Assistant HomeKit Bridge",
) | [
"def",
"_async_register_bridge",
"(",
"self",
",",
"dev_reg",
")",
":",
"formatted_mac",
"=",
"device_registry",
".",
"format_mac",
"(",
"self",
".",
"driver",
".",
"state",
".",
"mac",
")",
"# Connections and identifiers are both used here.",
"#",
"# connections exists so homekit_controller can know the",
"# virtual mac address of the bridge and know to not offer",
"# it via discovery.",
"#",
"# identifiers is used as well since the virtual mac may change",
"# because it will not survive manual pairing resets (deleting state file)",
"# which we have trained users to do over the past few years",
"# because this was the way you had to fix homekit when pairing",
"# failed.",
"#",
"connection",
"=",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"formatted_mac",
")",
"identifier",
"=",
"(",
"DOMAIN",
",",
"self",
".",
"_entry_id",
",",
"BRIDGE_SERIAL_NUMBER",
")",
"self",
".",
"_async_purge_old_bridges",
"(",
"dev_reg",
",",
"identifier",
",",
"connection",
")",
"dev_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"self",
".",
"_entry_id",
",",
"identifiers",
"=",
"{",
"identifier",
"}",
",",
"connections",
"=",
"{",
"connection",
"}",
",",
"manufacturer",
"=",
"MANUFACTURER",
",",
"name",
"=",
"self",
".",
"_name",
",",
"model",
"=",
"\"Home Assistant HomeKit Bridge\"",
",",
")"
] | [
585,
4
] | [
610,
9
] | python | en | ['en', 'en', 'en'] | True |
HomeKit._async_purge_old_bridges | (self, dev_reg, identifier, connection) | Purge bridges that exist from failed pairing or manual resets. | Purge bridges that exist from failed pairing or manual resets. | def _async_purge_old_bridges(self, dev_reg, identifier, connection):
"""Purge bridges that exist from failed pairing or manual resets."""
devices_to_purge = []
for entry in dev_reg.devices.values():
if self._entry_id in entry.config_entries and (
identifier not in entry.identifiers
or connection not in entry.connections
):
devices_to_purge.append(entry.id)
for device_id in devices_to_purge:
dev_reg.async_remove_device(device_id) | [
"def",
"_async_purge_old_bridges",
"(",
"self",
",",
"dev_reg",
",",
"identifier",
",",
"connection",
")",
":",
"devices_to_purge",
"=",
"[",
"]",
"for",
"entry",
"in",
"dev_reg",
".",
"devices",
".",
"values",
"(",
")",
":",
"if",
"self",
".",
"_entry_id",
"in",
"entry",
".",
"config_entries",
"and",
"(",
"identifier",
"not",
"in",
"entry",
".",
"identifiers",
"or",
"connection",
"not",
"in",
"entry",
".",
"connections",
")",
":",
"devices_to_purge",
".",
"append",
"(",
"entry",
".",
"id",
")",
"for",
"device_id",
"in",
"devices_to_purge",
":",
"dev_reg",
".",
"async_remove_device",
"(",
"device_id",
")"
] | [
613,
4
] | [
624,
50
] | python | en | ['en', 'en', 'en'] | True |
HomeKit.async_stop | (self, *args) | Stop the accessory driver. | Stop the accessory driver. | async def async_stop(self, *args):
"""Stop the accessory driver."""
if self.status != STATUS_RUNNING:
return
self.status = STATUS_STOPPED
_LOGGER.debug("Driver stop for %s", self._name)
await self.driver.async_stop()
if self.bridge:
for acc in self.bridge.accessories.values():
acc.async_stop()
else:
self.driver.accessory.async_stop() | [
"async",
"def",
"async_stop",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"status",
"!=",
"STATUS_RUNNING",
":",
"return",
"self",
".",
"status",
"=",
"STATUS_STOPPED",
"_LOGGER",
".",
"debug",
"(",
"\"Driver stop for %s\"",
",",
"self",
".",
"_name",
")",
"await",
"self",
".",
"driver",
".",
"async_stop",
"(",
")",
"if",
"self",
".",
"bridge",
":",
"for",
"acc",
"in",
"self",
".",
"bridge",
".",
"accessories",
".",
"values",
"(",
")",
":",
"acc",
".",
"async_stop",
"(",
")",
"else",
":",
"self",
".",
"driver",
".",
"accessory",
".",
"async_stop",
"(",
")"
] | [
664,
4
] | [
675,
46
] | python | en | ['en', 'en', 'en'] | True |
HomeKit._async_set_device_info_attributes | (self, ent_reg_ent, dev_reg, entity_id) | Set attributes that will be used for homekit device info. | Set attributes that will be used for homekit device info. | async def _async_set_device_info_attributes(self, ent_reg_ent, dev_reg, entity_id):
"""Set attributes that will be used for homekit device info."""
ent_cfg = self._config.setdefault(entity_id, {})
if ent_reg_ent.device_id:
dev_reg_ent = dev_reg.async_get(ent_reg_ent.device_id)
if dev_reg_ent is not None:
# Handle missing devices
if dev_reg_ent.manufacturer:
ent_cfg[ATTR_MANUFACTURER] = dev_reg_ent.manufacturer
if dev_reg_ent.model:
ent_cfg[ATTR_MODEL] = dev_reg_ent.model
if dev_reg_ent.sw_version:
ent_cfg[ATTR_SOFTWARE_VERSION] = dev_reg_ent.sw_version
if ATTR_MANUFACTURER not in ent_cfg:
try:
integration = await async_get_integration(
self.hass, ent_reg_ent.platform
)
ent_cfg[ATTR_INTERGRATION] = integration.name
except IntegrationNotFound:
ent_cfg[ATTR_INTERGRATION] = ent_reg_ent.platform | [
"async",
"def",
"_async_set_device_info_attributes",
"(",
"self",
",",
"ent_reg_ent",
",",
"dev_reg",
",",
"entity_id",
")",
":",
"ent_cfg",
"=",
"self",
".",
"_config",
".",
"setdefault",
"(",
"entity_id",
",",
"{",
"}",
")",
"if",
"ent_reg_ent",
".",
"device_id",
":",
"dev_reg_ent",
"=",
"dev_reg",
".",
"async_get",
"(",
"ent_reg_ent",
".",
"device_id",
")",
"if",
"dev_reg_ent",
"is",
"not",
"None",
":",
"# Handle missing devices",
"if",
"dev_reg_ent",
".",
"manufacturer",
":",
"ent_cfg",
"[",
"ATTR_MANUFACTURER",
"]",
"=",
"dev_reg_ent",
".",
"manufacturer",
"if",
"dev_reg_ent",
".",
"model",
":",
"ent_cfg",
"[",
"ATTR_MODEL",
"]",
"=",
"dev_reg_ent",
".",
"model",
"if",
"dev_reg_ent",
".",
"sw_version",
":",
"ent_cfg",
"[",
"ATTR_SOFTWARE_VERSION",
"]",
"=",
"dev_reg_ent",
".",
"sw_version",
"if",
"ATTR_MANUFACTURER",
"not",
"in",
"ent_cfg",
":",
"try",
":",
"integration",
"=",
"await",
"async_get_integration",
"(",
"self",
".",
"hass",
",",
"ent_reg_ent",
".",
"platform",
")",
"ent_cfg",
"[",
"ATTR_INTERGRATION",
"]",
"=",
"integration",
".",
"name",
"except",
"IntegrationNotFound",
":",
"ent_cfg",
"[",
"ATTR_INTERGRATION",
"]",
"=",
"ent_reg_ent",
".",
"platform"
] | [
735,
4
] | [
755,
65
] | python | en | ['en', 'en', 'en'] | True |
HomeKitPairingQRView.get | (self, request) | Retrieve the pairing QRCode image. | Retrieve the pairing QRCode image. | async def get(self, request):
"""Retrieve the pairing QRCode image."""
if not request.query_string:
raise Unauthorized()
entry_id, secret = request.query_string.split("-")
if (
entry_id not in request.app["hass"].data[DOMAIN]
or secret
!= request.app["hass"].data[DOMAIN][entry_id][HOMEKIT_PAIRING_QR_SECRET]
):
raise Unauthorized()
return web.Response(
body=request.app["hass"].data[DOMAIN][entry_id][HOMEKIT_PAIRING_QR],
content_type="image/svg+xml",
) | [
"async",
"def",
"get",
"(",
"self",
",",
"request",
")",
":",
"if",
"not",
"request",
".",
"query_string",
":",
"raise",
"Unauthorized",
"(",
")",
"entry_id",
",",
"secret",
"=",
"request",
".",
"query_string",
".",
"split",
"(",
"\"-\"",
")",
"if",
"(",
"entry_id",
"not",
"in",
"request",
".",
"app",
"[",
"\"hass\"",
"]",
".",
"data",
"[",
"DOMAIN",
"]",
"or",
"secret",
"!=",
"request",
".",
"app",
"[",
"\"hass\"",
"]",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry_id",
"]",
"[",
"HOMEKIT_PAIRING_QR_SECRET",
"]",
")",
":",
"raise",
"Unauthorized",
"(",
")",
"return",
"web",
".",
"Response",
"(",
"body",
"=",
"request",
".",
"app",
"[",
"\"hass\"",
"]",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry_id",
"]",
"[",
"HOMEKIT_PAIRING_QR",
"]",
",",
"content_type",
"=",
"\"image/svg+xml\"",
",",
")"
] | [
765,
4
] | [
780,
9
] | python | en | ['en', 'sr', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Homematic light platform. | Set up the Homematic light platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Homematic light platform."""
if discovery_info is None:
return
devices = []
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
new_device = HMLight(conf)
devices.append(new_device)
add_entities(devices, True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"devices",
"=",
"[",
"]",
"for",
"conf",
"in",
"discovery_info",
"[",
"ATTR_DISCOVER_DEVICES",
"]",
":",
"new_device",
"=",
"HMLight",
"(",
"conf",
")",
"devices",
".",
"append",
"(",
"new_device",
")",
"add_entities",
"(",
"devices",
",",
"True",
")"
] | [
20,
0
] | [
30,
31
] | python | en | ['en', 'da', 'en'] | True |
HMLight.brightness | (self) | Return the brightness of this light between 0..255. | Return the brightness of this light between 0..255. | def brightness(self):
"""Return the brightness of this light between 0..255."""
# Is dimmer?
if self._state == "LEVEL":
return int(self._hm_get_state() * 255)
return None | [
"def",
"brightness",
"(",
"self",
")",
":",
"# Is dimmer?",
"if",
"self",
".",
"_state",
"==",
"\"LEVEL\"",
":",
"return",
"int",
"(",
"self",
".",
"_hm_get_state",
"(",
")",
"*",
"255",
")",
"return",
"None"
] | [
37,
4
] | [
42,
19
] | python | en | ['en', 'en', 'en'] | True |
HMLight.is_on | (self) | Return true if light is on. | Return true if light is on. | def is_on(self):
"""Return true if light is on."""
try:
return self._hm_get_state() > 0
except TypeError:
return False | [
"def",
"is_on",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"_hm_get_state",
"(",
")",
">",
"0",
"except",
"TypeError",
":",
"return",
"False"
] | [
45,
4
] | [
50,
24
] | python | en | ['en', 'et', 'en'] | True |
HMLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
features = SUPPORT_BRIGHTNESS
if "COLOR" in self._hmdevice.WRITENODE:
features |= SUPPORT_COLOR
if "PROGRAM" in self._hmdevice.WRITENODE:
features |= SUPPORT_EFFECT
if hasattr(self._hmdevice, "get_color_temp"):
features |= SUPPORT_COLOR_TEMP
return features | [
"def",
"supported_features",
"(",
"self",
")",
":",
"features",
"=",
"SUPPORT_BRIGHTNESS",
"if",
"\"COLOR\"",
"in",
"self",
".",
"_hmdevice",
".",
"WRITENODE",
":",
"features",
"|=",
"SUPPORT_COLOR",
"if",
"\"PROGRAM\"",
"in",
"self",
".",
"_hmdevice",
".",
"WRITENODE",
":",
"features",
"|=",
"SUPPORT_EFFECT",
"if",
"hasattr",
"(",
"self",
".",
"_hmdevice",
",",
"\"get_color_temp\"",
")",
":",
"features",
"|=",
"SUPPORT_COLOR_TEMP",
"return",
"features"
] | [
53,
4
] | [
62,
23
] | python | en | ['da', 'en', 'en'] | True |
HMLight.hs_color | (self) | Return the hue and saturation color value [float, float]. | Return the hue and saturation color value [float, float]. | def hs_color(self):
"""Return the hue and saturation color value [float, float]."""
if not self.supported_features & SUPPORT_COLOR:
return None
hue, sat = self._hmdevice.get_hs_color(self._channel)
return hue * 360.0, sat * 100.0 | [
"def",
"hs_color",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"supported_features",
"&",
"SUPPORT_COLOR",
":",
"return",
"None",
"hue",
",",
"sat",
"=",
"self",
".",
"_hmdevice",
".",
"get_hs_color",
"(",
"self",
".",
"_channel",
")",
"return",
"hue",
"*",
"360.0",
",",
"sat",
"*",
"100.0"
] | [
65,
4
] | [
70,
39
] | python | en | ['en', 'en', 'en'] | True |
HMLight.color_temp | (self) | Return the color temp in mireds [int]. | Return the color temp in mireds [int]. | def color_temp(self):
"""Return the color temp in mireds [int]."""
if not self.supported_features & SUPPORT_COLOR_TEMP:
return None
hm_color_temp = self._hmdevice.get_color_temp(self._channel)
return self.max_mireds - (self.max_mireds - self.min_mireds) * hm_color_temp | [
"def",
"color_temp",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"supported_features",
"&",
"SUPPORT_COLOR_TEMP",
":",
"return",
"None",
"hm_color_temp",
"=",
"self",
".",
"_hmdevice",
".",
"get_color_temp",
"(",
"self",
".",
"_channel",
")",
"return",
"self",
".",
"max_mireds",
"-",
"(",
"self",
".",
"max_mireds",
"-",
"self",
".",
"min_mireds",
")",
"*",
"hm_color_temp"
] | [
73,
4
] | [
78,
84
] | python | en | ['en', 'en', 'en'] | True |
HMLight.effect_list | (self) | Return the list of supported effects. | Return the list of supported effects. | def effect_list(self):
"""Return the list of supported effects."""
if not self.supported_features & SUPPORT_EFFECT:
return None
return self._hmdevice.get_effect_list() | [
"def",
"effect_list",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"supported_features",
"&",
"SUPPORT_EFFECT",
":",
"return",
"None",
"return",
"self",
".",
"_hmdevice",
".",
"get_effect_list",
"(",
")"
] | [
81,
4
] | [
85,
47
] | python | en | ['en', 'en', 'en'] | True |
HMLight.effect | (self) | Return the current color change program of the light. | Return the current color change program of the light. | def effect(self):
"""Return the current color change program of the light."""
if not self.supported_features & SUPPORT_EFFECT:
return None
return self._hmdevice.get_effect() | [
"def",
"effect",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"supported_features",
"&",
"SUPPORT_EFFECT",
":",
"return",
"None",
"return",
"self",
".",
"_hmdevice",
".",
"get_effect",
"(",
")"
] | [
88,
4
] | [
92,
42
] | python | en | ['en', 'da', 'en'] | True |
HMLight.turn_on | (self, **kwargs) | Turn the light on and/or change color or color effect settings. | Turn the light on and/or change color or color effect settings. | def turn_on(self, **kwargs):
"""Turn the light on and/or change color or color effect settings."""
if ATTR_TRANSITION in kwargs:
self._hmdevice.setValue("RAMP_TIME", kwargs[ATTR_TRANSITION])
if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL":
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
self._hmdevice.set_level(percent_bright, self._channel)
elif (
ATTR_HS_COLOR not in kwargs
and ATTR_COLOR_TEMP not in kwargs
and ATTR_EFFECT not in kwargs
):
self._hmdevice.on(self._channel)
if ATTR_HS_COLOR in kwargs and self.supported_features & SUPPORT_COLOR:
self._hmdevice.set_hs_color(
hue=kwargs[ATTR_HS_COLOR][0] / 360.0,
saturation=kwargs[ATTR_HS_COLOR][1] / 100.0,
channel=self._channel,
)
if ATTR_COLOR_TEMP in kwargs:
hm_temp = (self.max_mireds - kwargs[ATTR_COLOR_TEMP]) / (
self.max_mireds - self.min_mireds
)
self._hmdevice.set_color_temp(hm_temp)
if ATTR_EFFECT in kwargs:
self._hmdevice.set_effect(kwargs[ATTR_EFFECT]) | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"ATTR_TRANSITION",
"in",
"kwargs",
":",
"self",
".",
"_hmdevice",
".",
"setValue",
"(",
"\"RAMP_TIME\"",
",",
"kwargs",
"[",
"ATTR_TRANSITION",
"]",
")",
"if",
"ATTR_BRIGHTNESS",
"in",
"kwargs",
"and",
"self",
".",
"_state",
"==",
"\"LEVEL\"",
":",
"percent_bright",
"=",
"float",
"(",
"kwargs",
"[",
"ATTR_BRIGHTNESS",
"]",
")",
"/",
"255",
"self",
".",
"_hmdevice",
".",
"set_level",
"(",
"percent_bright",
",",
"self",
".",
"_channel",
")",
"elif",
"(",
"ATTR_HS_COLOR",
"not",
"in",
"kwargs",
"and",
"ATTR_COLOR_TEMP",
"not",
"in",
"kwargs",
"and",
"ATTR_EFFECT",
"not",
"in",
"kwargs",
")",
":",
"self",
".",
"_hmdevice",
".",
"on",
"(",
"self",
".",
"_channel",
")",
"if",
"ATTR_HS_COLOR",
"in",
"kwargs",
"and",
"self",
".",
"supported_features",
"&",
"SUPPORT_COLOR",
":",
"self",
".",
"_hmdevice",
".",
"set_hs_color",
"(",
"hue",
"=",
"kwargs",
"[",
"ATTR_HS_COLOR",
"]",
"[",
"0",
"]",
"/",
"360.0",
",",
"saturation",
"=",
"kwargs",
"[",
"ATTR_HS_COLOR",
"]",
"[",
"1",
"]",
"/",
"100.0",
",",
"channel",
"=",
"self",
".",
"_channel",
",",
")",
"if",
"ATTR_COLOR_TEMP",
"in",
"kwargs",
":",
"hm_temp",
"=",
"(",
"self",
".",
"max_mireds",
"-",
"kwargs",
"[",
"ATTR_COLOR_TEMP",
"]",
")",
"/",
"(",
"self",
".",
"max_mireds",
"-",
"self",
".",
"min_mireds",
")",
"self",
".",
"_hmdevice",
".",
"set_color_temp",
"(",
"hm_temp",
")",
"if",
"ATTR_EFFECT",
"in",
"kwargs",
":",
"self",
".",
"_hmdevice",
".",
"set_effect",
"(",
"kwargs",
"[",
"ATTR_EFFECT",
"]",
")"
] | [
94,
4
] | [
121,
58
] | python | en | ['en', 'en', 'en'] | True |
HMLight.turn_off | (self, **kwargs) | Turn the light off. | Turn the light off. | def turn_off(self, **kwargs):
"""Turn the light off."""
self._hmdevice.off(self._channel) | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_hmdevice",
".",
"off",
"(",
"self",
".",
"_channel",
")"
] | [
123,
4
] | [
125,
41
] | python | en | ['en', 'zh', 'en'] | True |
HMLight._init_data_struct | (self) | Generate a data dict (self._data) from the Homematic metadata. | Generate a data dict (self._data) from the Homematic metadata. | def _init_data_struct(self):
"""Generate a data dict (self._data) from the Homematic metadata."""
# Use LEVEL
self._state = "LEVEL"
self._data[self._state] = None
if self.supported_features & SUPPORT_COLOR:
self._data.update({"COLOR": None})
if self.supported_features & SUPPORT_EFFECT:
self._data.update({"PROGRAM": None}) | [
"def",
"_init_data_struct",
"(",
"self",
")",
":",
"# Use LEVEL",
"self",
".",
"_state",
"=",
"\"LEVEL\"",
"self",
".",
"_data",
"[",
"self",
".",
"_state",
"]",
"=",
"None",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_COLOR",
":",
"self",
".",
"_data",
".",
"update",
"(",
"{",
"\"COLOR\"",
":",
"None",
"}",
")",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_EFFECT",
":",
"self",
".",
"_data",
".",
"update",
"(",
"{",
"\"PROGRAM\"",
":",
"None",
"}",
")"
] | [
127,
4
] | [
136,
48
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass: HomeAssistantType, config: ConfigType) | Set up the shell_command component. | Set up the shell_command component. | async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
"""Set up the shell_command component."""
conf = config.get(DOMAIN, {})
cache = {}
async def async_service_handler(service: ServiceCall) -> None:
"""Execute a shell command service."""
cmd = conf[service.service]
if cmd in cache:
prog, args, args_compiled = cache[cmd]
elif " " not in cmd:
prog = cmd
args = None
args_compiled = None
cache[cmd] = prog, args, args_compiled
else:
prog, args = cmd.split(" ", 1)
args_compiled = template.Template(args, hass)
cache[cmd] = prog, args, args_compiled
if args_compiled:
try:
rendered_args = args_compiled.async_render(
variables=service.data, parse_result=False
)
except TemplateError as ex:
_LOGGER.exception("Error rendering command template: %s", ex)
return
else:
rendered_args = None
if rendered_args == args:
# No template used. default behavior
# pylint: disable=no-member
create_process = asyncio.subprocess.create_subprocess_shell(
cmd,
stdin=None,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
else:
# Template used. Break into list and use create_subprocess_exec
# (which uses shell=False) for security
shlexed_cmd = [prog] + shlex.split(rendered_args)
# pylint: disable=no-member
create_process = asyncio.subprocess.create_subprocess_exec(
*shlexed_cmd,
stdin=None,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
process = await create_process
try:
stdout_data, stderr_data = await asyncio.wait_for(
process.communicate(), COMMAND_TIMEOUT
)
except asyncio.TimeoutError:
_LOGGER.exception(
"Timed out running command: `%s`, after: %ss", cmd, COMMAND_TIMEOUT
)
if process:
try:
await process.kill()
except TypeError:
pass
del process
return
if stdout_data:
_LOGGER.debug(
"Stdout of command: `%s`, return code: %s:\n%s",
cmd,
process.returncode,
stdout_data,
)
if stderr_data:
_LOGGER.debug(
"Stderr of command: `%s`, return code: %s:\n%s",
cmd,
process.returncode,
stderr_data,
)
if process.returncode != 0:
_LOGGER.exception(
"Error running command: `%s`, return code: %s", cmd, process.returncode
)
for name in conf:
hass.services.async_register(DOMAIN, name, async_service_handler)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config",
":",
"ConfigType",
")",
"->",
"bool",
":",
"conf",
"=",
"config",
".",
"get",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"cache",
"=",
"{",
"}",
"async",
"def",
"async_service_handler",
"(",
"service",
":",
"ServiceCall",
")",
"->",
"None",
":",
"\"\"\"Execute a shell command service.\"\"\"",
"cmd",
"=",
"conf",
"[",
"service",
".",
"service",
"]",
"if",
"cmd",
"in",
"cache",
":",
"prog",
",",
"args",
",",
"args_compiled",
"=",
"cache",
"[",
"cmd",
"]",
"elif",
"\" \"",
"not",
"in",
"cmd",
":",
"prog",
"=",
"cmd",
"args",
"=",
"None",
"args_compiled",
"=",
"None",
"cache",
"[",
"cmd",
"]",
"=",
"prog",
",",
"args",
",",
"args_compiled",
"else",
":",
"prog",
",",
"args",
"=",
"cmd",
".",
"split",
"(",
"\" \"",
",",
"1",
")",
"args_compiled",
"=",
"template",
".",
"Template",
"(",
"args",
",",
"hass",
")",
"cache",
"[",
"cmd",
"]",
"=",
"prog",
",",
"args",
",",
"args_compiled",
"if",
"args_compiled",
":",
"try",
":",
"rendered_args",
"=",
"args_compiled",
".",
"async_render",
"(",
"variables",
"=",
"service",
".",
"data",
",",
"parse_result",
"=",
"False",
")",
"except",
"TemplateError",
"as",
"ex",
":",
"_LOGGER",
".",
"exception",
"(",
"\"Error rendering command template: %s\"",
",",
"ex",
")",
"return",
"else",
":",
"rendered_args",
"=",
"None",
"if",
"rendered_args",
"==",
"args",
":",
"# No template used. default behavior",
"# pylint: disable=no-member",
"create_process",
"=",
"asyncio",
".",
"subprocess",
".",
"create_subprocess_shell",
"(",
"cmd",
",",
"stdin",
"=",
"None",
",",
"stdout",
"=",
"asyncio",
".",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"asyncio",
".",
"subprocess",
".",
"PIPE",
",",
")",
"else",
":",
"# Template used. Break into list and use create_subprocess_exec",
"# (which uses shell=False) for security",
"shlexed_cmd",
"=",
"[",
"prog",
"]",
"+",
"shlex",
".",
"split",
"(",
"rendered_args",
")",
"# pylint: disable=no-member",
"create_process",
"=",
"asyncio",
".",
"subprocess",
".",
"create_subprocess_exec",
"(",
"*",
"shlexed_cmd",
",",
"stdin",
"=",
"None",
",",
"stdout",
"=",
"asyncio",
".",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"asyncio",
".",
"subprocess",
".",
"PIPE",
",",
")",
"process",
"=",
"await",
"create_process",
"try",
":",
"stdout_data",
",",
"stderr_data",
"=",
"await",
"asyncio",
".",
"wait_for",
"(",
"process",
".",
"communicate",
"(",
")",
",",
"COMMAND_TIMEOUT",
")",
"except",
"asyncio",
".",
"TimeoutError",
":",
"_LOGGER",
".",
"exception",
"(",
"\"Timed out running command: `%s`, after: %ss\"",
",",
"cmd",
",",
"COMMAND_TIMEOUT",
")",
"if",
"process",
":",
"try",
":",
"await",
"process",
".",
"kill",
"(",
")",
"except",
"TypeError",
":",
"pass",
"del",
"process",
"return",
"if",
"stdout_data",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Stdout of command: `%s`, return code: %s:\\n%s\"",
",",
"cmd",
",",
"process",
".",
"returncode",
",",
"stdout_data",
",",
")",
"if",
"stderr_data",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Stderr of command: `%s`, return code: %s:\\n%s\"",
",",
"cmd",
",",
"process",
".",
"returncode",
",",
"stderr_data",
",",
")",
"if",
"process",
".",
"returncode",
"!=",
"0",
":",
"_LOGGER",
".",
"exception",
"(",
"\"Error running command: `%s`, return code: %s\"",
",",
"cmd",
",",
"process",
".",
"returncode",
")",
"for",
"name",
"in",
"conf",
":",
"hass",
".",
"services",
".",
"async_register",
"(",
"DOMAIN",
",",
"name",
",",
"async_service_handler",
")",
"return",
"True"
] | [
23,
0
] | [
118,
15
] | python | en | ['en', 'en', 'en'] | True |
_get_dyson_purecool_device | () | Return a valid device as provided by the Dyson web services. | Return a valid device as provided by the Dyson web services. | def _get_dyson_purecool_device():
"""Return a valid device as provided by the Dyson web services."""
device = mock.Mock(spec=DysonPureCool)
load_mock_device(device)
device.name = "Living room"
return device | [
"def",
"_get_dyson_purecool_device",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
"spec",
"=",
"DysonPureCool",
")",
"load_mock_device",
"(",
"device",
")",
"device",
".",
"name",
"=",
"\"Living room\"",
"return",
"device"
] | [
45,
0
] | [
50,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_dyson_purecoollink_device | () | Return a valid device as provided by the Dyson web services. | Return a valid device as provided by the Dyson web services. | def _get_dyson_purecoollink_device():
"""Return a valid device as provided by the Dyson web services."""
device = mock.Mock(spec=DysonPureCoolLink)
load_mock_device(device)
device.name = "Living room"
device.state.oscillation = "ON"
device.state.fan_mode = "FAN"
device.state.speed = FanSpeed.FAN_SPEED_AUTO.value
return device | [
"def",
"_get_dyson_purecoollink_device",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
"spec",
"=",
"DysonPureCoolLink",
")",
"load_mock_device",
"(",
"device",
")",
"device",
".",
"name",
"=",
"\"Living room\"",
"device",
".",
"state",
".",
"oscillation",
"=",
"\"ON\"",
"device",
".",
"state",
".",
"fan_mode",
"=",
"\"FAN\"",
"device",
".",
"state",
".",
"speed",
"=",
"FanSpeed",
".",
"FAN_SPEED_AUTO",
".",
"value",
"return",
"device"
] | [
53,
0
] | [
61,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_config | () | Return a config dictionary. | Return a config dictionary. | def _get_config():
"""Return a config dictionary."""
return {
dyson_parent.DOMAIN: {
dyson_parent.CONF_USERNAME: "email",
dyson_parent.CONF_PASSWORD: "password",
dyson_parent.CONF_LANGUAGE: "GB",
dyson_parent.CONF_DEVICES: [
{"device_id": "XX-XXXXX-XX", "device_ip": "192.168.0.1"}
],
}
} | [
"def",
"_get_config",
"(",
")",
":",
"return",
"{",
"dyson_parent",
".",
"DOMAIN",
":",
"{",
"dyson_parent",
".",
"CONF_USERNAME",
":",
"\"email\"",
",",
"dyson_parent",
".",
"CONF_PASSWORD",
":",
"\"password\"",
",",
"dyson_parent",
".",
"CONF_LANGUAGE",
":",
"\"GB\"",
",",
"dyson_parent",
".",
"CONF_DEVICES",
":",
"[",
"{",
"\"device_id\"",
":",
"\"XX-XXXXX-XX\"",
",",
"\"device_ip\"",
":",
"\"192.168.0.1\"",
"}",
"]",
",",
"}",
"}"
] | [
79,
0
] | [
90,
5
] | python | en | ['en', 'pt', 'en'] | True |
_get_device_with_no_state | () | Return a device with no state. | Return a device with no state. | def _get_device_with_no_state():
"""Return a device with no state."""
device = mock.Mock()
device.name = "Device_name"
device.state = None
return device | [
"def",
"_get_device_with_no_state",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
")",
"device",
".",
"name",
"=",
"\"Device_name\"",
"device",
".",
"state",
"=",
"None",
"return",
"device"
] | [
93,
0
] | [
98,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_device_off | () | Return a device with state off. | Return a device with state off. | def _get_device_off():
"""Return a device with state off."""
device = mock.Mock()
device.name = "Device_name"
device.state = mock.Mock()
device.state.fan_mode = "OFF"
device.state.night_mode = "ON"
device.state.speed = "0004"
return device | [
"def",
"_get_device_off",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
")",
"device",
".",
"name",
"=",
"\"Device_name\"",
"device",
".",
"state",
"=",
"mock",
".",
"Mock",
"(",
")",
"device",
".",
"state",
".",
"fan_mode",
"=",
"\"OFF\"",
"device",
".",
"state",
".",
"night_mode",
"=",
"\"ON\"",
"device",
".",
"state",
".",
"speed",
"=",
"\"0004\"",
"return",
"device"
] | [
101,
0
] | [
109,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_device_auto | () | Return a device with state auto. | Return a device with state auto. | def _get_device_auto():
"""Return a device with state auto."""
device = mock.Mock()
device.name = "Device_name"
device.state = mock.Mock()
device.state.fan_mode = "AUTO"
device.state.night_mode = "ON"
device.state.speed = "AUTO"
return device | [
"def",
"_get_device_auto",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
")",
"device",
".",
"name",
"=",
"\"Device_name\"",
"device",
".",
"state",
"=",
"mock",
".",
"Mock",
"(",
")",
"device",
".",
"state",
".",
"fan_mode",
"=",
"\"AUTO\"",
"device",
".",
"state",
".",
"night_mode",
"=",
"\"ON\"",
"device",
".",
"state",
".",
"speed",
"=",
"\"AUTO\"",
"return",
"device"
] | [
112,
0
] | [
120,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_device_on | () | Return a valid state on. | Return a valid state on. | def _get_device_on():
"""Return a valid state on."""
device = mock.Mock(spec=DysonPureCoolLink)
device.name = "Device_name"
device.state = mock.Mock()
device.state.fan_mode = "FAN"
device.state.fan_state = "FAN"
device.state.oscillation = "ON"
device.state.night_mode = "OFF"
device.state.speed = "0001"
return device | [
"def",
"_get_device_on",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
"spec",
"=",
"DysonPureCoolLink",
")",
"device",
".",
"name",
"=",
"\"Device_name\"",
"device",
".",
"state",
"=",
"mock",
".",
"Mock",
"(",
")",
"device",
".",
"state",
".",
"fan_mode",
"=",
"\"FAN\"",
"device",
".",
"state",
".",
"fan_state",
"=",
"\"FAN\"",
"device",
".",
"state",
".",
"oscillation",
"=",
"\"ON\"",
"device",
".",
"state",
".",
"night_mode",
"=",
"\"OFF\"",
"device",
".",
"state",
".",
"speed",
"=",
"\"0001\"",
"return",
"device"
] | [
123,
0
] | [
133,
17
] | python | en | ['en', 'et', 'en'] | True |
test_purecoollink_attributes | (devices, login, hass) | Test state attributes. | Test state attributes. | async def test_purecoollink_attributes(devices, login, hass):
"""Test state attributes."""
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
fan_state = hass.states.get("fan.living_room")
attributes = fan_state.attributes
assert fan_state.state == "on"
assert attributes[dyson.ATTR_NIGHT_MODE] is False
assert attributes[ATTR_SPEED] == FanSpeed.FAN_SPEED_AUTO.value
assert attributes[ATTR_OSCILLATING] is True | [
"async",
"def",
"test_purecoollink_attributes",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"fan_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"fan.living_room\"",
")",
"attributes",
"=",
"fan_state",
".",
"attributes",
"assert",
"fan_state",
".",
"state",
"==",
"\"on\"",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_NIGHT_MODE",
"]",
"is",
"False",
"assert",
"attributes",
"[",
"ATTR_SPEED",
"]",
"==",
"FanSpeed",
".",
"FAN_SPEED_AUTO",
".",
"value",
"assert",
"attributes",
"[",
"ATTR_OSCILLATING",
"]",
"is",
"True"
] | [
399,
0
] | [
409,
47
] | python | en | ['en', 'en', 'en'] | True |
test_purecool_turn_on | (devices, login, hass) | Test turn on. | Test turn on. | async def test_purecool_turn_on(devices, login, hass):
"""Test turn on."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: "fan.bed_room"}, True
)
assert device.turn_on.call_count == 0
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: "fan.living_room"}, True
)
assert device.turn_on.call_count == 1 | [
"async",
"def",
"test_purecool_turn_on",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
"}",
",",
"True",
")",
"assert",
"device",
".",
"turn_on",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
"}",
",",
"True",
")",
"assert",
"device",
".",
"turn_on",
".",
"call_count",
"==",
"1"
] | [
417,
0
] | [
431,
41
] | python | en | ['en', 'et', 'en'] | True |
test_purecool_set_speed | (devices, login, hass) | Test set speed. | Test set speed. | async def test_purecool_set_speed(devices, login, hass):
"""Test set speed."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "fan.bed_room", ATTR_SPEED: SPEED_LOW},
True,
)
assert device.set_fan_speed.call_count == 0
await hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "fan.living_room", ATTR_SPEED: SPEED_LOW},
True,
)
device.set_fan_speed.assert_called_with(FanSpeed.FAN_SPEED_4)
await hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "fan.living_room", ATTR_SPEED: SPEED_MEDIUM},
True,
)
device.set_fan_speed.assert_called_with(FanSpeed.FAN_SPEED_7)
await hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "fan.living_room", ATTR_SPEED: SPEED_HIGH},
True,
)
device.set_fan_speed.assert_called_with(FanSpeed.FAN_SPEED_10) | [
"async",
"def",
"test_purecool_set_speed",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
",",
"ATTR_SPEED",
":",
"SPEED_LOW",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_fan_speed",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"ATTR_SPEED",
":",
"SPEED_LOW",
"}",
",",
"True",
",",
")",
"device",
".",
"set_fan_speed",
".",
"assert_called_with",
"(",
"FanSpeed",
".",
"FAN_SPEED_4",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"ATTR_SPEED",
":",
"SPEED_MEDIUM",
"}",
",",
"True",
",",
")",
"device",
".",
"set_fan_speed",
".",
"assert_called_with",
"(",
"FanSpeed",
".",
"FAN_SPEED_7",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"ATTR_SPEED",
":",
"SPEED_HIGH",
"}",
",",
"True",
",",
")",
"device",
".",
"set_fan_speed",
".",
"assert_called_with",
"(",
"FanSpeed",
".",
"FAN_SPEED_10",
")"
] | [
439,
0
] | [
475,
66
] | python | en | ['en', 'de', 'en'] | True |
test_purecool_turn_off | (devices, login, hass) | Test turn off. | Test turn off. | async def test_purecool_turn_off(devices, login, hass):
"""Test turn off."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "fan.bed_room"}, True
)
assert device.turn_off.call_count == 0
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "fan.living_room"}, True
)
assert device.turn_off.call_count == 1 | [
"async",
"def",
"test_purecool_turn_off",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
"}",
",",
"True",
")",
"assert",
"device",
".",
"turn_off",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
"}",
",",
"True",
")",
"assert",
"device",
".",
"turn_off",
".",
"call_count",
"==",
"1"
] | [
483,
0
] | [
497,
42
] | python | en | ['en', 'cy', 'en'] | True |
test_purecool_set_dyson_speed | (devices, login, hass) | Test set exact dyson speed. | Test set exact dyson speed. | async def test_purecool_set_dyson_speed(devices, login, hass):
"""Test set exact dyson speed."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_DYSON_SPEED,
{
ATTR_ENTITY_ID: "fan.bed_room",
dyson.ATTR_DYSON_SPEED: int(FanSpeed.FAN_SPEED_2.value),
},
True,
)
assert device.set_fan_speed.call_count == 0
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_DYSON_SPEED,
{
ATTR_ENTITY_ID: "fan.living_room",
dyson.ATTR_DYSON_SPEED: int(FanSpeed.FAN_SPEED_2.value),
},
True,
)
device.set_fan_speed.assert_called_with(FanSpeed.FAN_SPEED_2) | [
"async",
"def",
"test_purecool_set_dyson_speed",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_DYSON_SPEED",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
",",
"dyson",
".",
"ATTR_DYSON_SPEED",
":",
"int",
"(",
"FanSpeed",
".",
"FAN_SPEED_2",
".",
"value",
")",
",",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_fan_speed",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_DYSON_SPEED",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"dyson",
".",
"ATTR_DYSON_SPEED",
":",
"int",
"(",
"FanSpeed",
".",
"FAN_SPEED_2",
".",
"value",
")",
",",
"}",
",",
"True",
",",
")",
"device",
".",
"set_fan_speed",
".",
"assert_called_with",
"(",
"FanSpeed",
".",
"FAN_SPEED_2",
")"
] | [
505,
0
] | [
531,
65
] | python | el-Latn | ['no', 'el-Latn', 'en'] | False |
test_purecool_oscillate | (devices, login, hass) | Test set oscillation. | Test set oscillation. | async def test_purecool_oscillate(devices, login, hass):
"""Test set oscillation."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_OSCILLATE,
{ATTR_ENTITY_ID: "fan.bed_room", ATTR_OSCILLATING: True},
True,
)
assert device.enable_oscillation.call_count == 0
await hass.services.async_call(
DOMAIN,
SERVICE_OSCILLATE,
{ATTR_ENTITY_ID: "fan.living_room", ATTR_OSCILLATING: True},
True,
)
assert device.enable_oscillation.call_count == 1
await hass.services.async_call(
DOMAIN,
SERVICE_OSCILLATE,
{ATTR_ENTITY_ID: "fan.living_room", ATTR_OSCILLATING: False},
True,
)
assert device.disable_oscillation.call_count == 1 | [
"async",
"def",
"test_purecool_oscillate",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_OSCILLATE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
",",
"ATTR_OSCILLATING",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_oscillation",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_OSCILLATE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"ATTR_OSCILLATING",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_oscillation",
".",
"call_count",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_OSCILLATE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"ATTR_OSCILLATING",
":",
"False",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"disable_oscillation",
".",
"call_count",
"==",
"1"
] | [
539,
0
] | [
567,
53
] | python | en | ['en', 'is', 'en'] | True |
test_purecool_set_night_mode | (devices, login, hass) | Test set night mode. | Test set night mode. | async def test_purecool_set_night_mode(devices, login, hass):
"""Test set night mode."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_NIGHT_MODE,
{"entity_id": "fan.bed_room", "night_mode": True},
True,
)
assert device.enable_night_mode.call_count == 0
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_NIGHT_MODE,
{"entity_id": "fan.living_room", "night_mode": True},
True,
)
assert device.enable_night_mode.call_count == 1
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_NIGHT_MODE,
{"entity_id": "fan.living_room", "night_mode": False},
True,
)
assert device.disable_night_mode.call_count == 1 | [
"async",
"def",
"test_purecool_set_night_mode",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_NIGHT_MODE",
",",
"{",
"\"entity_id\"",
":",
"\"fan.bed_room\"",
",",
"\"night_mode\"",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_night_mode",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_NIGHT_MODE",
",",
"{",
"\"entity_id\"",
":",
"\"fan.living_room\"",
",",
"\"night_mode\"",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_night_mode",
".",
"call_count",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_NIGHT_MODE",
",",
"{",
"\"entity_id\"",
":",
"\"fan.living_room\"",
",",
"\"night_mode\"",
":",
"False",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"disable_night_mode",
".",
"call_count",
"==",
"1"
] | [
575,
0
] | [
604,
52
] | python | en | ['en', 'jv', 'en'] | True |
test_purecool_set_auto_mode | (devices, login, hass) | Test set auto mode. | Test set auto mode. | async def test_purecool_set_auto_mode(devices, login, hass):
"""Test set auto mode."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_AUTO_MODE,
{ATTR_ENTITY_ID: "fan.bed_room", dyson.ATTR_AUTO_MODE: True},
True,
)
assert device.enable_auto_mode.call_count == 0
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_AUTO_MODE,
{ATTR_ENTITY_ID: "fan.living_room", dyson.ATTR_AUTO_MODE: True},
True,
)
assert device.enable_auto_mode.call_count == 1
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_AUTO_MODE,
{ATTR_ENTITY_ID: "fan.living_room", dyson.ATTR_AUTO_MODE: False},
True,
)
assert device.disable_auto_mode.call_count == 1 | [
"async",
"def",
"test_purecool_set_auto_mode",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_AUTO_MODE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
",",
"dyson",
".",
"ATTR_AUTO_MODE",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_auto_mode",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_AUTO_MODE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"dyson",
".",
"ATTR_AUTO_MODE",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_auto_mode",
".",
"call_count",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_AUTO_MODE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"dyson",
".",
"ATTR_AUTO_MODE",
":",
"False",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"disable_auto_mode",
".",
"call_count",
"==",
"1"
] | [
612,
0
] | [
640,
51
] | python | el-Latn | ['en', 'el-Latn', 'nl'] | False |
test_purecool_set_angle | (devices, login, hass) | Test set angle. | Test set angle. | async def test_purecool_set_angle(devices, login, hass):
"""Test set angle."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_ANGLE,
{
ATTR_ENTITY_ID: "fan.bed_room",
dyson.ATTR_ANGLE_LOW: 90,
dyson.ATTR_ANGLE_HIGH: 180,
},
True,
)
assert device.enable_oscillation.call_count == 0
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_ANGLE,
{
ATTR_ENTITY_ID: "fan.living_room",
dyson.ATTR_ANGLE_LOW: 90,
dyson.ATTR_ANGLE_HIGH: 180,
},
True,
)
device.enable_oscillation.assert_called_with(90, 180) | [
"async",
"def",
"test_purecool_set_angle",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_ANGLE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
",",
"dyson",
".",
"ATTR_ANGLE_LOW",
":",
"90",
",",
"dyson",
".",
"ATTR_ANGLE_HIGH",
":",
"180",
",",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_oscillation",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_ANGLE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"dyson",
".",
"ATTR_ANGLE_LOW",
":",
"90",
",",
"dyson",
".",
"ATTR_ANGLE_HIGH",
":",
"180",
",",
"}",
",",
"True",
",",
")",
"device",
".",
"enable_oscillation",
".",
"assert_called_with",
"(",
"90",
",",
"180",
")"
] | [
648,
0
] | [
676,
57
] | python | en | ['tl', 'haw', 'en'] | False |
test_purecool_set_flow_direction_front | (devices, login, hass) | Test set frontal flow direction. | Test set frontal flow direction. | async def test_purecool_set_flow_direction_front(devices, login, hass):
"""Test set frontal flow direction."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_FLOW_DIRECTION_FRONT,
{ATTR_ENTITY_ID: "fan.bed_room", dyson.ATTR_FLOW_DIRECTION_FRONT: True},
True,
)
assert device.enable_frontal_direction.call_count == 0
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_FLOW_DIRECTION_FRONT,
{ATTR_ENTITY_ID: "fan.living_room", dyson.ATTR_FLOW_DIRECTION_FRONT: True},
True,
)
assert device.enable_frontal_direction.call_count == 1
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_FLOW_DIRECTION_FRONT,
{ATTR_ENTITY_ID: "fan.living_room", dyson.ATTR_FLOW_DIRECTION_FRONT: False},
True,
)
assert device.disable_frontal_direction.call_count == 1 | [
"async",
"def",
"test_purecool_set_flow_direction_front",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_FLOW_DIRECTION_FRONT",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
",",
"dyson",
".",
"ATTR_FLOW_DIRECTION_FRONT",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_frontal_direction",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_FLOW_DIRECTION_FRONT",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"dyson",
".",
"ATTR_FLOW_DIRECTION_FRONT",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_frontal_direction",
".",
"call_count",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_FLOW_DIRECTION_FRONT",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"dyson",
".",
"ATTR_FLOW_DIRECTION_FRONT",
":",
"False",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"disable_frontal_direction",
".",
"call_count",
"==",
"1"
] | [
684,
0
] | [
712,
59
] | python | en | ['en', 'da', 'en'] | True |
test_purecool_set_timer | (devices, login, hass) | Test set timer. | Test set timer. | async def test_purecool_set_timer(devices, login, hass):
"""Test set timer."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_TIMER,
{ATTR_ENTITY_ID: "fan.bed_room", dyson.ATTR_TIMER: 60},
True,
)
assert device.enable_frontal_direction.call_count == 0
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_TIMER,
{ATTR_ENTITY_ID: "fan.living_room", dyson.ATTR_TIMER: 60},
True,
)
device.enable_sleep_timer.assert_called_with(60)
await hass.services.async_call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_TIMER,
{ATTR_ENTITY_ID: "fan.living_room", dyson.ATTR_TIMER: 0},
True,
)
assert device.disable_sleep_timer.call_count == 1 | [
"async",
"def",
"test_purecool_set_timer",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_TIMER",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.bed_room\"",
",",
"dyson",
".",
"ATTR_TIMER",
":",
"60",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"enable_frontal_direction",
".",
"call_count",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_TIMER",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"dyson",
".",
"ATTR_TIMER",
":",
"60",
"}",
",",
"True",
",",
")",
"device",
".",
"enable_sleep_timer",
".",
"assert_called_with",
"(",
"60",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_TIMER",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"fan.living_room\"",
",",
"dyson",
".",
"ATTR_TIMER",
":",
"0",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"disable_sleep_timer",
".",
"call_count",
"==",
"1"
] | [
720,
0
] | [
748,
53
] | python | da | ['da', 'da', 'en'] | True |
test_purecool_update_state | (devices, login, hass) | Test state update. | Test state update. | async def test_purecool_update_state(devices, login, hass):
"""Test state update."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
event = {
"msg": "CURRENT-STATE",
"product-state": {
"fpwr": "OFF",
"fdir": "OFF",
"auto": "OFF",
"oscs": "ON",
"oson": "ON",
"nmod": "OFF",
"rhtm": "ON",
"fnst": "FAN",
"ercd": "11E1",
"wacd": "NONE",
"nmdv": "0004",
"fnsp": "0002",
"bril": "0002",
"corf": "ON",
"cflr": "0085",
"hflr": "0095",
"sltm": "OFF",
"osal": "0045",
"osau": "0095",
"ancp": "CUST",
},
}
device.state = DysonPureCoolV2State(json.dumps(event))
for call in device.add_message_listener.call_args_list:
callback = call[0][0]
if type(callback.__self__) == dyson.DysonPureCoolDevice:
callback(device.state)
await hass.async_block_till_done()
fan_state = hass.states.get("fan.living_room")
attributes = fan_state.attributes
assert fan_state.state == "off"
assert attributes[dyson.ATTR_NIGHT_MODE] is False
assert attributes[dyson.ATTR_AUTO_MODE] is False
assert attributes[dyson.ATTR_ANGLE_LOW] == 45
assert attributes[dyson.ATTR_ANGLE_HIGH] == 95
assert attributes[dyson.ATTR_FLOW_DIRECTION_FRONT] is False
assert attributes[dyson.ATTR_TIMER] == "OFF"
assert attributes[dyson.ATTR_HEPA_FILTER] == 95
assert attributes[dyson.ATTR_CARBON_FILTER] == 85
assert attributes[dyson.ATTR_DYSON_SPEED] == int(FanSpeed.FAN_SPEED_2.value)
assert attributes[ATTR_SPEED] is SPEED_LOW
assert attributes[ATTR_OSCILLATING] is False
assert attributes[dyson.ATTR_DYSON_SPEED_LIST] == _get_supported_speeds() | [
"async",
"def",
"test_purecool_update_state",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"event",
"=",
"{",
"\"msg\"",
":",
"\"CURRENT-STATE\"",
",",
"\"product-state\"",
":",
"{",
"\"fpwr\"",
":",
"\"OFF\"",
",",
"\"fdir\"",
":",
"\"OFF\"",
",",
"\"auto\"",
":",
"\"OFF\"",
",",
"\"oscs\"",
":",
"\"ON\"",
",",
"\"oson\"",
":",
"\"ON\"",
",",
"\"nmod\"",
":",
"\"OFF\"",
",",
"\"rhtm\"",
":",
"\"ON\"",
",",
"\"fnst\"",
":",
"\"FAN\"",
",",
"\"ercd\"",
":",
"\"11E1\"",
",",
"\"wacd\"",
":",
"\"NONE\"",
",",
"\"nmdv\"",
":",
"\"0004\"",
",",
"\"fnsp\"",
":",
"\"0002\"",
",",
"\"bril\"",
":",
"\"0002\"",
",",
"\"corf\"",
":",
"\"ON\"",
",",
"\"cflr\"",
":",
"\"0085\"",
",",
"\"hflr\"",
":",
"\"0095\"",
",",
"\"sltm\"",
":",
"\"OFF\"",
",",
"\"osal\"",
":",
"\"0045\"",
",",
"\"osau\"",
":",
"\"0095\"",
",",
"\"ancp\"",
":",
"\"CUST\"",
",",
"}",
",",
"}",
"device",
".",
"state",
"=",
"DysonPureCoolV2State",
"(",
"json",
".",
"dumps",
"(",
"event",
")",
")",
"for",
"call",
"in",
"device",
".",
"add_message_listener",
".",
"call_args_list",
":",
"callback",
"=",
"call",
"[",
"0",
"]",
"[",
"0",
"]",
"if",
"type",
"(",
"callback",
".",
"__self__",
")",
"==",
"dyson",
".",
"DysonPureCoolDevice",
":",
"callback",
"(",
"device",
".",
"state",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"fan_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"fan.living_room\"",
")",
"attributes",
"=",
"fan_state",
".",
"attributes",
"assert",
"fan_state",
".",
"state",
"==",
"\"off\"",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_NIGHT_MODE",
"]",
"is",
"False",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_AUTO_MODE",
"]",
"is",
"False",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_ANGLE_LOW",
"]",
"==",
"45",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_ANGLE_HIGH",
"]",
"==",
"95",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_FLOW_DIRECTION_FRONT",
"]",
"is",
"False",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_TIMER",
"]",
"==",
"\"OFF\"",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_HEPA_FILTER",
"]",
"==",
"95",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_CARBON_FILTER",
"]",
"==",
"85",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_DYSON_SPEED",
"]",
"==",
"int",
"(",
"FanSpeed",
".",
"FAN_SPEED_2",
".",
"value",
")",
"assert",
"attributes",
"[",
"ATTR_SPEED",
"]",
"is",
"SPEED_LOW",
"assert",
"attributes",
"[",
"ATTR_OSCILLATING",
"]",
"is",
"False",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_DYSON_SPEED_LIST",
"]",
"==",
"_get_supported_speeds",
"(",
")"
] | [
756,
0
] | [
809,
77
] | python | en | ['en', 'co', 'en'] | True |
test_purecool_update_state_filter_inv | (devices, login, hass) | Test state TP06 carbon filter state. | Test state TP06 carbon filter state. | async def test_purecool_update_state_filter_inv(devices, login, hass):
"""Test state TP06 carbon filter state."""
device = devices.return_value[0]
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
event = {
"msg": "CURRENT-STATE",
"product-state": {
"fpwr": "OFF",
"fdir": "ON",
"auto": "ON",
"oscs": "ON",
"oson": "ON",
"nmod": "ON",
"rhtm": "ON",
"fnst": "FAN",
"ercd": "11E1",
"wacd": "NONE",
"nmdv": "0004",
"fnsp": "0002",
"bril": "0002",
"corf": "ON",
"cflr": "INV",
"hflr": "0075",
"sltm": "OFF",
"osal": "0055",
"osau": "0105",
"ancp": "CUST",
},
}
device.state = DysonPureCoolV2State(json.dumps(event))
for call in device.add_message_listener.call_args_list:
callback = call[0][0]
if type(callback.__self__) == dyson.DysonPureCoolDevice:
callback(device.state)
await hass.async_block_till_done()
fan_state = hass.states.get("fan.living_room")
attributes = fan_state.attributes
assert fan_state.state == "off"
assert attributes[dyson.ATTR_NIGHT_MODE] is True
assert attributes[dyson.ATTR_AUTO_MODE] is True
assert attributes[dyson.ATTR_ANGLE_LOW] == 55
assert attributes[dyson.ATTR_ANGLE_HIGH] == 105
assert attributes[dyson.ATTR_FLOW_DIRECTION_FRONT] is True
assert attributes[dyson.ATTR_TIMER] == "OFF"
assert attributes[dyson.ATTR_HEPA_FILTER] == 75
assert attributes[dyson.ATTR_CARBON_FILTER] == "INV"
assert attributes[dyson.ATTR_DYSON_SPEED] == int(FanSpeed.FAN_SPEED_2.value)
assert attributes[ATTR_SPEED] is SPEED_LOW
assert attributes[ATTR_OSCILLATING] is False
assert attributes[dyson.ATTR_DYSON_SPEED_LIST] == _get_supported_speeds() | [
"async",
"def",
"test_purecool_update_state_filter_inv",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"device",
"=",
"devices",
".",
"return_value",
"[",
"0",
"]",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson",
".",
"DYSON_DOMAIN",
",",
"_get_config",
"(",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"event",
"=",
"{",
"\"msg\"",
":",
"\"CURRENT-STATE\"",
",",
"\"product-state\"",
":",
"{",
"\"fpwr\"",
":",
"\"OFF\"",
",",
"\"fdir\"",
":",
"\"ON\"",
",",
"\"auto\"",
":",
"\"ON\"",
",",
"\"oscs\"",
":",
"\"ON\"",
",",
"\"oson\"",
":",
"\"ON\"",
",",
"\"nmod\"",
":",
"\"ON\"",
",",
"\"rhtm\"",
":",
"\"ON\"",
",",
"\"fnst\"",
":",
"\"FAN\"",
",",
"\"ercd\"",
":",
"\"11E1\"",
",",
"\"wacd\"",
":",
"\"NONE\"",
",",
"\"nmdv\"",
":",
"\"0004\"",
",",
"\"fnsp\"",
":",
"\"0002\"",
",",
"\"bril\"",
":",
"\"0002\"",
",",
"\"corf\"",
":",
"\"ON\"",
",",
"\"cflr\"",
":",
"\"INV\"",
",",
"\"hflr\"",
":",
"\"0075\"",
",",
"\"sltm\"",
":",
"\"OFF\"",
",",
"\"osal\"",
":",
"\"0055\"",
",",
"\"osau\"",
":",
"\"0105\"",
",",
"\"ancp\"",
":",
"\"CUST\"",
",",
"}",
",",
"}",
"device",
".",
"state",
"=",
"DysonPureCoolV2State",
"(",
"json",
".",
"dumps",
"(",
"event",
")",
")",
"for",
"call",
"in",
"device",
".",
"add_message_listener",
".",
"call_args_list",
":",
"callback",
"=",
"call",
"[",
"0",
"]",
"[",
"0",
"]",
"if",
"type",
"(",
"callback",
".",
"__self__",
")",
"==",
"dyson",
".",
"DysonPureCoolDevice",
":",
"callback",
"(",
"device",
".",
"state",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"fan_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"fan.living_room\"",
")",
"attributes",
"=",
"fan_state",
".",
"attributes",
"assert",
"fan_state",
".",
"state",
"==",
"\"off\"",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_NIGHT_MODE",
"]",
"is",
"True",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_AUTO_MODE",
"]",
"is",
"True",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_ANGLE_LOW",
"]",
"==",
"55",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_ANGLE_HIGH",
"]",
"==",
"105",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_FLOW_DIRECTION_FRONT",
"]",
"is",
"True",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_TIMER",
"]",
"==",
"\"OFF\"",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_HEPA_FILTER",
"]",
"==",
"75",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_CARBON_FILTER",
"]",
"==",
"\"INV\"",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_DYSON_SPEED",
"]",
"==",
"int",
"(",
"FanSpeed",
".",
"FAN_SPEED_2",
".",
"value",
")",
"assert",
"attributes",
"[",
"ATTR_SPEED",
"]",
"is",
"SPEED_LOW",
"assert",
"attributes",
"[",
"ATTR_OSCILLATING",
"]",
"is",
"False",
"assert",
"attributes",
"[",
"dyson",
".",
"ATTR_DYSON_SPEED_LIST",
"]",
"==",
"_get_supported_speeds",
"(",
")"
] | [
817,
0
] | [
870,
77
] | python | en | ['en', 'en', 'en'] | True |
test_purecool_component_setup_only_once | (devices, login, hass) | Test if entities are created only once. | Test if entities are created only once. | async def test_purecool_component_setup_only_once(devices, login, hass):
"""Test if entities are created only once."""
config = _get_config()
await async_setup_component(hass, dyson_parent.DOMAIN, config)
await hass.async_block_till_done()
discovery.load_platform(hass, "fan", dyson_parent.DOMAIN, {}, config)
await hass.async_block_till_done()
fans = [
fan
for fan in hass.data[DOMAIN].entities
if fan.platform.platform_name == dyson_parent.DOMAIN
]
assert len(fans) == 1
assert fans[0].device_serial == "XX-XXXXX-XX" | [
"async",
"def",
"test_purecool_component_setup_only_once",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"config",
"=",
"_get_config",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson_parent",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"discovery",
".",
"load_platform",
"(",
"hass",
",",
"\"fan\"",
",",
"dyson_parent",
".",
"DOMAIN",
",",
"{",
"}",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"fans",
"=",
"[",
"fan",
"for",
"fan",
"in",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"entities",
"if",
"fan",
".",
"platform",
".",
"platform_name",
"==",
"dyson_parent",
".",
"DOMAIN",
"]",
"assert",
"len",
"(",
"fans",
")",
"==",
"1",
"assert",
"fans",
"[",
"0",
"]",
".",
"device_serial",
"==",
"\"XX-XXXXX-XX\""
] | [
878,
0
] | [
893,
49
] | python | en | ['en', 'en', 'en'] | True |
MockDysonState.__init__ | (self) | Create new Mock Dyson State. | Create new Mock Dyson State. | def __init__(self):
"""Create new Mock Dyson State."""
pass | [
"def",
"__init__",
"(",
"self",
")",
":",
"pass"
] | [
36,
4
] | [
38,
12
] | python | en | ['en', 'en', 'en'] | True |
MockDysonState.__repr__ | (self) | Mock repr because original one fails since constructor not called. | Mock repr because original one fails since constructor not called. | def __repr__(self):
"""Mock repr because original one fails since constructor not called."""
return "<MockDysonState>" | [
"def",
"__repr__",
"(",
"self",
")",
":",
"return",
"\"<MockDysonState>\""
] | [
40,
4
] | [
42,
33
] | python | en | ['en', 'en', 'en'] | True |
DysonSetupTest.setUp | (self) | Set up things to be run when tests are started. | Set up things to be run when tests are started. | def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup) | [
"def",
"setUp",
"(",
"self",
")",
":",
"# pylint: disable=invalid-name",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"addCleanup",
"(",
"self",
".",
"tear_down_cleanup",
")"
] | [
139,
4
] | [
142,
47
] | python | en | ['en', 'en', 'en'] | True |
DysonSetupTest.tear_down_cleanup | (self) | Stop everything that was started. | Stop everything that was started. | def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop() | [
"def",
"tear_down_cleanup",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"stop",
"(",
")"
] | [
144,
4
] | [
146,
24
] | python | en | ['en', 'en', 'en'] | True |
DysonSetupTest.test_setup_component_with_no_devices | (self) | Test setup component with no devices. | Test setup component with no devices. | def test_setup_component_with_no_devices(self):
"""Test setup component with no devices."""
self.hass.data[dyson.DYSON_DEVICES] = []
add_entities = mock.MagicMock()
dyson.setup_platform(self.hass, None, add_entities, mock.Mock())
add_entities.assert_called_with([]) | [
"def",
"test_setup_component_with_no_devices",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"data",
"[",
"dyson",
".",
"DYSON_DEVICES",
"]",
"=",
"[",
"]",
"add_entities",
"=",
"mock",
".",
"MagicMock",
"(",
")",
"dyson",
".",
"setup_platform",
"(",
"self",
".",
"hass",
",",
"None",
",",
"add_entities",
",",
"mock",
".",
"Mock",
"(",
")",
")",
"add_entities",
".",
"assert_called_with",
"(",
"[",
"]",
")"
] | [
148,
4
] | [
153,
43
] | python | en | ['en', 'en', 'en'] | True |
DysonSetupTest.test_setup_component | (self) | Test setup component with devices. | Test setup component with devices. | def test_setup_component(self):
"""Test setup component with devices."""
def _add_device(devices):
assert len(devices) == 2
assert devices[0].name == "Device_name"
device_fan = _get_device_on()
device_purecool_fan = _get_dyson_purecool_device()
device_non_fan = _get_device_off()
self.hass.data[dyson.DYSON_DEVICES] = [
device_fan,
device_purecool_fan,
device_non_fan,
]
dyson.setup_platform(self.hass, None, _add_device) | [
"def",
"test_setup_component",
"(",
"self",
")",
":",
"def",
"_add_device",
"(",
"devices",
")",
":",
"assert",
"len",
"(",
"devices",
")",
"==",
"2",
"assert",
"devices",
"[",
"0",
"]",
".",
"name",
"==",
"\"Device_name\"",
"device_fan",
"=",
"_get_device_on",
"(",
")",
"device_purecool_fan",
"=",
"_get_dyson_purecool_device",
"(",
")",
"device_non_fan",
"=",
"_get_device_off",
"(",
")",
"self",
".",
"hass",
".",
"data",
"[",
"dyson",
".",
"DYSON_DEVICES",
"]",
"=",
"[",
"device_fan",
",",
"device_purecool_fan",
",",
"device_non_fan",
",",
"]",
"dyson",
".",
"setup_platform",
"(",
"self",
".",
"hass",
",",
"None",
",",
"_add_device",
")"
] | [
155,
4
] | [
171,
58
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.setUp | (self) | Set up things to be run when tests are started. | Set up things to be run when tests are started. | def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup) | [
"def",
"setUp",
"(",
"self",
")",
":",
"# pylint: disable=invalid-name",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"addCleanup",
"(",
"self",
".",
"tear_down_cleanup",
")"
] | [
177,
4
] | [
180,
47
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.tear_down_cleanup | (self) | Stop everything that was started. | Stop everything that was started. | def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop() | [
"def",
"tear_down_cleanup",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"stop",
"(",
")"
] | [
182,
4
] | [
184,
24
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_set_speed | (self) | Test set fan speed. | Test set fan speed. | def test_dyson_set_speed(self):
"""Test set fan speed."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.should_poll
component.set_speed("1")
set_config = device.set_configuration
set_config.assert_called_with(
fan_mode=FanMode.FAN, fan_speed=FanSpeed.FAN_SPEED_1
)
component.set_speed("AUTO")
set_config = device.set_configuration
set_config.assert_called_with(fan_mode=FanMode.AUTO) | [
"def",
"test_dyson_set_speed",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"should_poll",
"component",
".",
"set_speed",
"(",
"\"1\"",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"fan_mode",
"=",
"FanMode",
".",
"FAN",
",",
"fan_speed",
"=",
"FanSpeed",
".",
"FAN_SPEED_1",
")",
"component",
".",
"set_speed",
"(",
"\"AUTO\"",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"fan_mode",
"=",
"FanMode",
".",
"AUTO",
")"
] | [
186,
4
] | [
199,
60
] | python | fy | ['no', 'fy', 'nl'] | False |
DysonTest.test_dyson_turn_on | (self) | Test turn on fan. | Test turn on fan. | def test_dyson_turn_on(self):
"""Test turn on fan."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.should_poll
component.turn_on()
set_config = device.set_configuration
set_config.assert_called_with(fan_mode=FanMode.FAN) | [
"def",
"test_dyson_turn_on",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"should_poll",
"component",
".",
"turn_on",
"(",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"fan_mode",
"=",
"FanMode",
".",
"FAN",
")"
] | [
201,
4
] | [
208,
59
] | python | en | ['en', 'fy', 'en'] | True |
DysonTest.test_dyson_turn_night_mode | (self) | Test turn on fan with night mode. | Test turn on fan with night mode. | def test_dyson_turn_night_mode(self):
"""Test turn on fan with night mode."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.should_poll
component.set_night_mode(True)
set_config = device.set_configuration
set_config.assert_called_with(night_mode=NightMode.NIGHT_MODE_ON)
component.set_night_mode(False)
set_config = device.set_configuration
set_config.assert_called_with(night_mode=NightMode.NIGHT_MODE_OFF) | [
"def",
"test_dyson_turn_night_mode",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"should_poll",
"component",
".",
"set_night_mode",
"(",
"True",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"night_mode",
"=",
"NightMode",
".",
"NIGHT_MODE_ON",
")",
"component",
".",
"set_night_mode",
"(",
"False",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"night_mode",
"=",
"NightMode",
".",
"NIGHT_MODE_OFF",
")"
] | [
210,
4
] | [
221,
74
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_is_night_mode | (self) | Test night mode. | Test night mode. | def test_is_night_mode(self):
"""Test night mode."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.night_mode
device = _get_device_off()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.night_mode | [
"def",
"test_is_night_mode",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"night_mode",
"device",
"=",
"_get_device_off",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"night_mode"
] | [
223,
4
] | [
231,
35
] | python | en | ['en', 'zh', 'en'] | True |
DysonTest.test_dyson_turn_auto_mode | (self) | Test turn on/off fan with auto mode. | Test turn on/off fan with auto mode. | def test_dyson_turn_auto_mode(self):
"""Test turn on/off fan with auto mode."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.should_poll
component.set_auto_mode(True)
set_config = device.set_configuration
set_config.assert_called_with(fan_mode=FanMode.AUTO)
component.set_auto_mode(False)
set_config = device.set_configuration
set_config.assert_called_with(fan_mode=FanMode.FAN) | [
"def",
"test_dyson_turn_auto_mode",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"should_poll",
"component",
".",
"set_auto_mode",
"(",
"True",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"fan_mode",
"=",
"FanMode",
".",
"AUTO",
")",
"component",
".",
"set_auto_mode",
"(",
"False",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"fan_mode",
"=",
"FanMode",
".",
"FAN",
")"
] | [
233,
4
] | [
244,
59
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_is_auto_mode | (self) | Test auto mode. | Test auto mode. | def test_is_auto_mode(self):
"""Test auto mode."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.auto_mode
device = _get_device_auto()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.auto_mode | [
"def",
"test_is_auto_mode",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"auto_mode",
"device",
"=",
"_get_device_auto",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"auto_mode"
] | [
246,
4
] | [
254,
34
] | python | el-Latn | ['en', 'el-Latn', 'it'] | False |
DysonTest.test_dyson_turn_on_speed | (self) | Test turn on fan with specified speed. | Test turn on fan with specified speed. | def test_dyson_turn_on_speed(self):
"""Test turn on fan with specified speed."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.should_poll
component.turn_on("1")
set_config = device.set_configuration
set_config.assert_called_with(
fan_mode=FanMode.FAN, fan_speed=FanSpeed.FAN_SPEED_1
)
component.turn_on("AUTO")
set_config = device.set_configuration
set_config.assert_called_with(fan_mode=FanMode.AUTO) | [
"def",
"test_dyson_turn_on_speed",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"should_poll",
"component",
".",
"turn_on",
"(",
"\"1\"",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"fan_mode",
"=",
"FanMode",
".",
"FAN",
",",
"fan_speed",
"=",
"FanSpeed",
".",
"FAN_SPEED_1",
")",
"component",
".",
"turn_on",
"(",
"\"AUTO\"",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"fan_mode",
"=",
"FanMode",
".",
"AUTO",
")"
] | [
256,
4
] | [
269,
60
] | python | en | ['en', 'fy', 'en'] | True |
DysonTest.test_dyson_turn_off | (self) | Test turn off fan. | Test turn off fan. | def test_dyson_turn_off(self):
"""Test turn off fan."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.should_poll
component.turn_off()
set_config = device.set_configuration
set_config.assert_called_with(fan_mode=FanMode.OFF) | [
"def",
"test_dyson_turn_off",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"should_poll",
"component",
".",
"turn_off",
"(",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"fan_mode",
"=",
"FanMode",
".",
"OFF",
")"
] | [
271,
4
] | [
278,
59
] | python | en | ['en', 'fy', 'en'] | True |
DysonTest.test_dyson_oscillate_off | (self) | Test turn off oscillation. | Test turn off oscillation. | def test_dyson_oscillate_off(self):
"""Test turn off oscillation."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
component.oscillate(False)
set_config = device.set_configuration
set_config.assert_called_with(oscillation=Oscillation.OSCILLATION_OFF) | [
"def",
"test_dyson_oscillate_off",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"component",
".",
"oscillate",
"(",
"False",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"oscillation",
"=",
"Oscillation",
".",
"OSCILLATION_OFF",
")"
] | [
280,
4
] | [
286,
78
] | python | en | ['en', 'fi', 'en'] | True |
DysonTest.test_dyson_oscillate_on | (self) | Test turn on oscillation. | Test turn on oscillation. | def test_dyson_oscillate_on(self):
"""Test turn on oscillation."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
component.oscillate(True)
set_config = device.set_configuration
set_config.assert_called_with(oscillation=Oscillation.OSCILLATION_ON) | [
"def",
"test_dyson_oscillate_on",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"component",
".",
"oscillate",
"(",
"True",
")",
"set_config",
"=",
"device",
".",
"set_configuration",
"set_config",
".",
"assert_called_with",
"(",
"oscillation",
"=",
"Oscillation",
".",
"OSCILLATION_ON",
")"
] | [
288,
4
] | [
294,
77
] | python | en | ['en', 'fi', 'en'] | True |
DysonTest.test_dyson_oscillate_value_on | (self) | Test get oscillation value on. | Test get oscillation value on. | def test_dyson_oscillate_value_on(self):
"""Test get oscillation value on."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.oscillating | [
"def",
"test_dyson_oscillate_value_on",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"oscillating"
] | [
296,
4
] | [
300,
36
] | python | en | ['en', 'da', 'en'] | True |
DysonTest.test_dyson_oscillate_value_off | (self) | Test get oscillation value off. | Test get oscillation value off. | def test_dyson_oscillate_value_off(self):
"""Test get oscillation value off."""
device = _get_device_off()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.oscillating | [
"def",
"test_dyson_oscillate_value_off",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_off",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"oscillating"
] | [
302,
4
] | [
306,
40
] | python | en | ['en', 'da', 'en'] | True |
DysonTest.test_dyson_on | (self) | Test device is on. | Test device is on. | def test_dyson_on(self):
"""Test device is on."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.is_on | [
"def",
"test_dyson_on",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"is_on"
] | [
308,
4
] | [
312,
30
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_off | (self) | Test device is off. | Test device is off. | def test_dyson_off(self):
"""Test device is off."""
device = _get_device_off()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.is_on
device = _get_device_with_no_state()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert not component.is_on | [
"def",
"test_dyson_off",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_off",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"is_on",
"device",
"=",
"_get_device_with_no_state",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"not",
"component",
".",
"is_on"
] | [
314,
4
] | [
322,
34
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_get_speed | (self) | Test get device speed. | Test get device speed. | def test_dyson_get_speed(self):
"""Test get device speed."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.speed == 1
device = _get_device_off()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.speed == 4
device = _get_device_with_no_state()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.speed is None
device = _get_device_auto()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.speed == "AUTO" | [
"def",
"test_dyson_get_speed",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"speed",
"==",
"1",
"device",
"=",
"_get_device_off",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"speed",
"==",
"4",
"device",
"=",
"_get_device_with_no_state",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"speed",
"is",
"None",
"device",
"=",
"_get_device_auto",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"speed",
"==",
"\"AUTO\""
] | [
324,
4
] | [
340,
40
] | python | de | ['nl', 'de', 'en'] | False |
DysonTest.test_dyson_get_direction | (self) | Test get device direction. | Test get device direction. | def test_dyson_get_direction(self):
"""Test get device direction."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.current_direction is None | [
"def",
"test_dyson_get_direction",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"current_direction",
"is",
"None"
] | [
342,
4
] | [
346,
50
] | python | en | ['nl', 'en', 'en'] | True |
DysonTest.test_dyson_get_speed_list | (self) | Test get speeds list. | Test get speeds list. | def test_dyson_get_speed_list(self):
"""Test get speeds list."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert len(component.speed_list) == 11 | [
"def",
"test_dyson_get_speed_list",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"len",
"(",
"component",
".",
"speed_list",
")",
"==",
"11"
] | [
348,
4
] | [
352,
46
] | python | de | ['nl', 'de', 'en'] | False |
DysonTest.test_dyson_supported_features | (self) | Test supported features. | Test supported features. | def test_dyson_supported_features(self):
"""Test supported features."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
assert component.supported_features == 3 | [
"def",
"test_dyson_supported_features",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"assert",
"component",
".",
"supported_features",
"==",
"3"
] | [
354,
4
] | [
358,
48
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_on_message | (self) | Test when message is received. | Test when message is received. | def test_on_message(self):
"""Test when message is received."""
device = _get_device_on()
component = dyson.DysonPureCoolLinkDevice(self.hass, device)
component.entity_id = "entity_id"
component.schedule_update_ha_state = mock.Mock()
component.on_message(MockDysonState())
component.schedule_update_ha_state.assert_called_with() | [
"def",
"test_on_message",
"(",
"self",
")",
":",
"device",
"=",
"_get_device_on",
"(",
")",
"component",
"=",
"dyson",
".",
"DysonPureCoolLinkDevice",
"(",
"self",
".",
"hass",
",",
"device",
")",
"component",
".",
"entity_id",
"=",
"\"entity_id\"",
"component",
".",
"schedule_update_ha_state",
"=",
"mock",
".",
"Mock",
"(",
")",
"component",
".",
"on_message",
"(",
"MockDysonState",
"(",
")",
")",
"component",
".",
"schedule_update_ha_state",
".",
"assert_called_with",
"(",
")"
] | [
360,
4
] | [
367,
63
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_service_set_night_mode | (self) | Test set night mode service. | Test set night mode service. | def test_service_set_night_mode(self):
"""Test set night mode service."""
dyson_device = mock.MagicMock()
self.hass.data[DYSON_DEVICES] = []
dyson_device.entity_id = "fan.living_room"
self.hass.data[dyson.DYSON_FAN_DEVICES] = [dyson_device]
dyson.setup_platform(self.hass, None, mock.MagicMock(), mock.MagicMock())
self.hass.services.call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_NIGHT_MODE,
{"entity_id": "fan.bed_room", "night_mode": True},
True,
)
assert dyson_device.set_night_mode.call_count == 0
self.hass.services.call(
dyson.DYSON_DOMAIN,
dyson.SERVICE_SET_NIGHT_MODE,
{"entity_id": "fan.living_room", "night_mode": True},
True,
)
dyson_device.set_night_mode.assert_called_with(True) | [
"def",
"test_service_set_night_mode",
"(",
"self",
")",
":",
"dyson_device",
"=",
"mock",
".",
"MagicMock",
"(",
")",
"self",
".",
"hass",
".",
"data",
"[",
"DYSON_DEVICES",
"]",
"=",
"[",
"]",
"dyson_device",
".",
"entity_id",
"=",
"\"fan.living_room\"",
"self",
".",
"hass",
".",
"data",
"[",
"dyson",
".",
"DYSON_FAN_DEVICES",
"]",
"=",
"[",
"dyson_device",
"]",
"dyson",
".",
"setup_platform",
"(",
"self",
".",
"hass",
",",
"None",
",",
"mock",
".",
"MagicMock",
"(",
")",
",",
"mock",
".",
"MagicMock",
"(",
")",
")",
"self",
".",
"hass",
".",
"services",
".",
"call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_NIGHT_MODE",
",",
"{",
"\"entity_id\"",
":",
"\"fan.bed_room\"",
",",
"\"night_mode\"",
":",
"True",
"}",
",",
"True",
",",
")",
"assert",
"dyson_device",
".",
"set_night_mode",
".",
"call_count",
"==",
"0",
"self",
".",
"hass",
".",
"services",
".",
"call",
"(",
"dyson",
".",
"DYSON_DOMAIN",
",",
"dyson",
".",
"SERVICE_SET_NIGHT_MODE",
",",
"{",
"\"entity_id\"",
":",
"\"fan.living_room\"",
",",
"\"night_mode\"",
":",
"True",
"}",
",",
"True",
",",
")",
"dyson_device",
".",
"set_night_mode",
".",
"assert_called_with",
"(",
"True",
")"
] | [
369,
4
] | [
391,
60
] | python | en | ['en', 'zh', 'en'] | True |
async_setup | (hass, config) | Set up the Mill platform. | Set up the Mill platform. | async def async_setup(hass, config):
"""Set up the Mill platform."""
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"return",
"True"
] | [
3,
0
] | [
5,
15
] | python | en | ['en', 'da', 'en'] | True |
async_setup_entry | (hass, entry) | Set up the Mill heater. | Set up the Mill heater. | async def async_setup_entry(hass, entry):
"""Set up the Mill heater."""
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "climate")
)
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
")",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"entry",
",",
"\"climate\"",
")",
")",
"return",
"True"
] | [
8,
0
] | [
13,
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."""
unload_ok = await hass.config_entries.async_forward_entry_unload(
config_entry, "climate"
)
return unload_ok | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
",",
"config_entry",
")",
":",
"unload_ok",
"=",
"await",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"config_entry",
",",
"\"climate\"",
")",
"return",
"unload_ok"
] | [
16,
0
] | [
21,
20
] | python | en | ['en', 'es', 'en'] | True |
_check_sensor_schema | (conf) | Check sensors and attributes are valid. | Check sensors and attributes are valid. | def _check_sensor_schema(conf):
"""Check sensors and attributes are valid."""
try:
valid = [s.name for s in pysma.Sensors()]
except (ImportError, AttributeError):
return conf
customs = list(conf[CONF_CUSTOM])
for sensor in conf[CONF_SENSORS]:
if sensor in customs:
_LOGGER.warning(
"All custom sensors will be added automatically, no need to include them in sensors: %s",
sensor,
)
elif sensor not in valid:
raise vol.Invalid(f"{sensor} does not exist")
return conf | [
"def",
"_check_sensor_schema",
"(",
"conf",
")",
":",
"try",
":",
"valid",
"=",
"[",
"s",
".",
"name",
"for",
"s",
"in",
"pysma",
".",
"Sensors",
"(",
")",
"]",
"except",
"(",
"ImportError",
",",
"AttributeError",
")",
":",
"return",
"conf",
"customs",
"=",
"list",
"(",
"conf",
"[",
"CONF_CUSTOM",
"]",
")",
"for",
"sensor",
"in",
"conf",
"[",
"CONF_SENSORS",
"]",
":",
"if",
"sensor",
"in",
"customs",
":",
"_LOGGER",
".",
"warning",
"(",
"\"All custom sensors will be added automatically, no need to include them in sensors: %s\"",
",",
"sensor",
",",
")",
"elif",
"sensor",
"not",
"in",
"valid",
":",
"raise",
"vol",
".",
"Invalid",
"(",
"f\"{sensor} does not exist\"",
")",
"return",
"conf"
] | [
35,
0
] | [
52,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up SMA WebConnect sensor. | Set up SMA WebConnect sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up SMA WebConnect sensor."""
# Check config again during load - dependency available
config = _check_sensor_schema(config)
# Init all default sensors
sensor_def = pysma.Sensors()
# Sensor from the custom config
sensor_def.add(
[
pysma.Sensor(o[CONF_KEY], n, o[CONF_UNIT], o[CONF_FACTOR], o.get(CONF_PATH))
for n, o in config[CONF_CUSTOM].items()
]
)
# Use all sensors by default
config_sensors = config[CONF_SENSORS]
hass_sensors = []
used_sensors = []
if isinstance(config_sensors, dict): # will be remove from 0.99
if not config_sensors: # Use all sensors by default
config_sensors = {s.name: [] for s in sensor_def}
# Prepare all Home Assistant sensor entities
for name, attr in config_sensors.items():
sub_sensors = [sensor_def[s] for s in attr]
hass_sensors.append(SMAsensor(sensor_def[name], sub_sensors))
used_sensors.append(name)
used_sensors.extend(attr)
if isinstance(config_sensors, list):
if not config_sensors: # Use all sensors by default
config_sensors = [s.name for s in sensor_def]
used_sensors = list(set(config_sensors + list(config[CONF_CUSTOM])))
for sensor in used_sensors:
hass_sensors.append(SMAsensor(sensor_def[sensor], []))
used_sensors = [sensor_def[s] for s in set(used_sensors)]
async_add_entities(hass_sensors)
# Init the SMA interface
session = async_get_clientsession(hass, verify_ssl=config[CONF_VERIFY_SSL])
grp = config[CONF_GROUP]
protocol = "https" if config[CONF_SSL] else "http"
url = f"{protocol}://{config[CONF_HOST]}"
sma = pysma.SMA(session, url, config[CONF_PASSWORD], group=grp)
# Ensure we logout on shutdown
async def async_close_session(event):
"""Close the session."""
await sma.close_session()
hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, async_close_session)
backoff = 0
backoff_step = 0
async def async_sma(event):
"""Update all the SMA sensors."""
nonlocal backoff, backoff_step
if backoff > 1:
backoff -= 1
return
values = await sma.read(used_sensors)
if not values:
try:
backoff = [1, 1, 1, 6, 30][backoff_step]
backoff_step += 1
except IndexError:
backoff = 60
return
backoff_step = 0
for sensor in hass_sensors:
sensor.async_update_values()
interval = config.get(CONF_SCAN_INTERVAL) or timedelta(seconds=5)
async_track_time_interval(hass, async_sma, interval) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"# Check config again during load - dependency available",
"config",
"=",
"_check_sensor_schema",
"(",
"config",
")",
"# Init all default sensors",
"sensor_def",
"=",
"pysma",
".",
"Sensors",
"(",
")",
"# Sensor from the custom config",
"sensor_def",
".",
"add",
"(",
"[",
"pysma",
".",
"Sensor",
"(",
"o",
"[",
"CONF_KEY",
"]",
",",
"n",
",",
"o",
"[",
"CONF_UNIT",
"]",
",",
"o",
"[",
"CONF_FACTOR",
"]",
",",
"o",
".",
"get",
"(",
"CONF_PATH",
")",
")",
"for",
"n",
",",
"o",
"in",
"config",
"[",
"CONF_CUSTOM",
"]",
".",
"items",
"(",
")",
"]",
")",
"# Use all sensors by default",
"config_sensors",
"=",
"config",
"[",
"CONF_SENSORS",
"]",
"hass_sensors",
"=",
"[",
"]",
"used_sensors",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"config_sensors",
",",
"dict",
")",
":",
"# will be remove from 0.99",
"if",
"not",
"config_sensors",
":",
"# Use all sensors by default",
"config_sensors",
"=",
"{",
"s",
".",
"name",
":",
"[",
"]",
"for",
"s",
"in",
"sensor_def",
"}",
"# Prepare all Home Assistant sensor entities",
"for",
"name",
",",
"attr",
"in",
"config_sensors",
".",
"items",
"(",
")",
":",
"sub_sensors",
"=",
"[",
"sensor_def",
"[",
"s",
"]",
"for",
"s",
"in",
"attr",
"]",
"hass_sensors",
".",
"append",
"(",
"SMAsensor",
"(",
"sensor_def",
"[",
"name",
"]",
",",
"sub_sensors",
")",
")",
"used_sensors",
".",
"append",
"(",
"name",
")",
"used_sensors",
".",
"extend",
"(",
"attr",
")",
"if",
"isinstance",
"(",
"config_sensors",
",",
"list",
")",
":",
"if",
"not",
"config_sensors",
":",
"# Use all sensors by default",
"config_sensors",
"=",
"[",
"s",
".",
"name",
"for",
"s",
"in",
"sensor_def",
"]",
"used_sensors",
"=",
"list",
"(",
"set",
"(",
"config_sensors",
"+",
"list",
"(",
"config",
"[",
"CONF_CUSTOM",
"]",
")",
")",
")",
"for",
"sensor",
"in",
"used_sensors",
":",
"hass_sensors",
".",
"append",
"(",
"SMAsensor",
"(",
"sensor_def",
"[",
"sensor",
"]",
",",
"[",
"]",
")",
")",
"used_sensors",
"=",
"[",
"sensor_def",
"[",
"s",
"]",
"for",
"s",
"in",
"set",
"(",
"used_sensors",
")",
"]",
"async_add_entities",
"(",
"hass_sensors",
")",
"# Init the SMA interface",
"session",
"=",
"async_get_clientsession",
"(",
"hass",
",",
"verify_ssl",
"=",
"config",
"[",
"CONF_VERIFY_SSL",
"]",
")",
"grp",
"=",
"config",
"[",
"CONF_GROUP",
"]",
"protocol",
"=",
"\"https\"",
"if",
"config",
"[",
"CONF_SSL",
"]",
"else",
"\"http\"",
"url",
"=",
"f\"{protocol}://{config[CONF_HOST]}\"",
"sma",
"=",
"pysma",
".",
"SMA",
"(",
"session",
",",
"url",
",",
"config",
"[",
"CONF_PASSWORD",
"]",
",",
"group",
"=",
"grp",
")",
"# Ensure we logout on shutdown",
"async",
"def",
"async_close_session",
"(",
"event",
")",
":",
"\"\"\"Close the session.\"\"\"",
"await",
"sma",
".",
"close_session",
"(",
")",
"hass",
".",
"bus",
".",
"async_listen",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"async_close_session",
")",
"backoff",
"=",
"0",
"backoff_step",
"=",
"0",
"async",
"def",
"async_sma",
"(",
"event",
")",
":",
"\"\"\"Update all the SMA sensors.\"\"\"",
"nonlocal",
"backoff",
",",
"backoff_step",
"if",
"backoff",
">",
"1",
":",
"backoff",
"-=",
"1",
"return",
"values",
"=",
"await",
"sma",
".",
"read",
"(",
"used_sensors",
")",
"if",
"not",
"values",
":",
"try",
":",
"backoff",
"=",
"[",
"1",
",",
"1",
",",
"1",
",",
"6",
",",
"30",
"]",
"[",
"backoff_step",
"]",
"backoff_step",
"+=",
"1",
"except",
"IndexError",
":",
"backoff",
"=",
"60",
"return",
"backoff_step",
"=",
"0",
"for",
"sensor",
"in",
"hass_sensors",
":",
"sensor",
".",
"async_update_values",
"(",
")",
"interval",
"=",
"config",
".",
"get",
"(",
"CONF_SCAN_INTERVAL",
")",
"or",
"timedelta",
"(",
"seconds",
"=",
"5",
")",
"async_track_time_interval",
"(",
"hass",
",",
"async_sma",
",",
"interval",
")"
] | [
86,
0
] | [
169,
56
] | python | en | ['en', 'da', 'en'] | True |
SMAsensor.__init__ | (self, pysma_sensor, sub_sensors) | Initialize the sensor. | Initialize the sensor. | def __init__(self, pysma_sensor, sub_sensors):
"""Initialize the sensor."""
self._sensor = pysma_sensor
self._sub_sensors = sub_sensors # Can be remove from 0.99
self._attr = {s.name: "" for s in sub_sensors}
self._state = self._sensor.value | [
"def",
"__init__",
"(",
"self",
",",
"pysma_sensor",
",",
"sub_sensors",
")",
":",
"self",
".",
"_sensor",
"=",
"pysma_sensor",
"self",
".",
"_sub_sensors",
"=",
"sub_sensors",
"# Can be remove from 0.99",
"self",
".",
"_attr",
"=",
"{",
"s",
".",
"name",
":",
"\"\"",
"for",
"s",
"in",
"sub_sensors",
"}",
"self",
".",
"_state",
"=",
"self",
".",
"_sensor",
".",
"value"
] | [
175,
4
] | [
181,
40
] | python | en | ['en', 'en', 'en'] | True |
SMAsensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return self._sensor.name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_sensor",
".",
"name"
] | [
184,
4
] | [
186,
32
] | python | en | ['en', 'mi', 'en'] | True |
SMAsensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
189,
4
] | [
191,
26
] | python | en | ['en', 'en', 'en'] | True |
SMAsensor.unit_of_measurement | (self) | Return the unit the value is expressed in. | Return the unit the value is expressed in. | def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._sensor.unit | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_sensor",
".",
"unit"
] | [
194,
4
] | [
196,
32
] | python | en | ['en', 'en', 'en'] | True |
SMAsensor.device_state_attributes | (self) | Return the state attributes of the sensor. | Return the state attributes of the sensor. | def device_state_attributes(self): # Can be remove from 0.99
"""Return the state attributes of the sensor."""
return self._attr | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"# Can be remove from 0.99",
"return",
"self",
".",
"_attr"
] | [
199,
4
] | [
201,
25
] | python | en | ['en', 'en', 'en'] | True |
SMAsensor.poll | (self) | SMA sensors are updated & don't poll. | SMA sensors are updated & don't poll. | def poll(self):
"""SMA sensors are updated & don't poll."""
return False | [
"def",
"poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
204,
4
] | [
206,
20
] | python | en | ['en', 'en', 'en'] | True |
SMAsensor.async_update_values | (self) | Update this sensor. | Update this sensor. | def async_update_values(self):
"""Update this sensor."""
update = False
for sens in self._sub_sensors: # Can be remove from 0.99
newval = f"{sens.value} {sens.unit}"
if self._attr[sens.name] != newval:
update = True
self._attr[sens.name] = newval
if self._sensor.value != self._state:
update = True
self._state = self._sensor.value
if update:
self.async_write_ha_state() | [
"def",
"async_update_values",
"(",
"self",
")",
":",
"update",
"=",
"False",
"for",
"sens",
"in",
"self",
".",
"_sub_sensors",
":",
"# Can be remove from 0.99",
"newval",
"=",
"f\"{sens.value} {sens.unit}\"",
"if",
"self",
".",
"_attr",
"[",
"sens",
".",
"name",
"]",
"!=",
"newval",
":",
"update",
"=",
"True",
"self",
".",
"_attr",
"[",
"sens",
".",
"name",
"]",
"=",
"newval",
"if",
"self",
".",
"_sensor",
".",
"value",
"!=",
"self",
".",
"_state",
":",
"update",
"=",
"True",
"self",
".",
"_state",
"=",
"self",
".",
"_sensor",
".",
"value",
"if",
"update",
":",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
209,
4
] | [
224,
39
] | python | en | ['en', 'id', 'en'] | True |
SMAsensor.unique_id | (self) | Return a unique identifier for this sensor. | Return a unique identifier for this sensor. | def unique_id(self):
"""Return a unique identifier for this sensor."""
return f"sma-{self._sensor.key}-{self._sensor.name}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"sma-{self._sensor.key}-{self._sensor.name}\""
] | [
227,
4
] | [
229,
60
] | python | en | ['en', 'fr', 'en'] | True |
mock_now | () | Fixture for dtutil.now. | Fixture for dtutil.now. | def mock_now() -> datetime:
"""Fixture for dtutil.now."""
return dt_util.utcnow() | [
"def",
"mock_now",
"(",
")",
"->",
"datetime",
":",
"return",
"dt_util",
".",
"utcnow",
"(",
")"
] | [
73,
0
] | [
75,
27
] | python | da | ['da', 'da', 'en'] | True |
async_turn_on | (
hass: HomeAssistantType, entity_id: Optional[str] = None
) | Turn on specified media player or all. | Turn on specified media player or all. | async def async_turn_on(
hass: HomeAssistantType, entity_id: Optional[str] = None
) -> None:
"""Turn on specified media player or all."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
await hass.services.async_call(MP_DOMAIN, SERVICE_TURN_ON, data) | [
"async",
"def",
"async_turn_on",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entity_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"{",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"MP_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"data",
")"
] | [
78,
0
] | [
83,
68
] | python | en | ['en', 'en', 'en'] | True |
async_turn_off | (
hass: HomeAssistantType, entity_id: Optional[str] = None
) | Turn off specified media player or all. | Turn off specified media player or all. | async def async_turn_off(
hass: HomeAssistantType, entity_id: Optional[str] = None
) -> None:
"""Turn off specified media player or all."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
await hass.services.async_call(MP_DOMAIN, SERVICE_TURN_OFF, data) | [
"async",
"def",
"async_turn_off",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entity_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"{",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"MP_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"data",
")"
] | [
86,
0
] | [
91,
69
] | python | en | ['en', 'en', 'en'] | True |
async_media_pause | (
hass: HomeAssistantType, entity_id: Optional[str] = None
) | Send the media player the command for pause. | Send the media player the command for pause. | async def async_media_pause(
hass: HomeAssistantType, entity_id: Optional[str] = None
) -> None:
"""Send the media player the command for pause."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
await hass.services.async_call(MP_DOMAIN, SERVICE_MEDIA_PAUSE, data) | [
"async",
"def",
"async_media_pause",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entity_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"{",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"MP_DOMAIN",
",",
"SERVICE_MEDIA_PAUSE",
",",
"data",
")"
] | [
94,
0
] | [
99,
72
] | python | en | ['en', 'en', 'en'] | True |
async_media_play | (
hass: HomeAssistantType, entity_id: Optional[str] = None
) | Send the media player the command for play/pause. | Send the media player the command for play/pause. | async def async_media_play(
hass: HomeAssistantType, entity_id: Optional[str] = None
) -> None:
"""Send the media player the command for play/pause."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
await hass.services.async_call(MP_DOMAIN, SERVICE_MEDIA_PLAY, data) | [
"async",
"def",
"async_media_play",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entity_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"{",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"MP_DOMAIN",
",",
"SERVICE_MEDIA_PLAY",
",",
"data",
")"
] | [
102,
0
] | [
107,
71
] | python | en | ['en', 'en', 'en'] | True |
async_media_stop | (
hass: HomeAssistantType, entity_id: Optional[str] = None
) | Send the media player the command for stop. | Send the media player the command for stop. | async def async_media_stop(
hass: HomeAssistantType, entity_id: Optional[str] = None
) -> None:
"""Send the media player the command for stop."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
await hass.services.async_call(MP_DOMAIN, SERVICE_MEDIA_STOP, data) | [
"async",
"def",
"async_media_stop",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entity_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"{",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"MP_DOMAIN",
",",
"SERVICE_MEDIA_STOP",
",",
"data",
")"
] | [
110,
0
] | [
115,
71
] | python | en | ['en', 'en', 'en'] | True |
async_media_next_track | (
hass: HomeAssistantType, entity_id: Optional[str] = None
) | Send the media player the command for next track. | Send the media player the command for next track. | async def async_media_next_track(
hass: HomeAssistantType, entity_id: Optional[str] = None
) -> None:
"""Send the media player the command for next track."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
await hass.services.async_call(MP_DOMAIN, SERVICE_MEDIA_NEXT_TRACK, data) | [
"async",
"def",
"async_media_next_track",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entity_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"{",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"MP_DOMAIN",
",",
"SERVICE_MEDIA_NEXT_TRACK",
",",
"data",
")"
] | [
118,
0
] | [
123,
77
] | python | en | ['en', 'en', 'en'] | True |
async_media_previous_track | (
hass: HomeAssistantType, entity_id: Optional[str] = None
) | Send the media player the command for prev track. | Send the media player the command for prev track. | async def async_media_previous_track(
hass: HomeAssistantType, entity_id: Optional[str] = None
) -> None:
"""Send the media player the command for prev track."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
await hass.services.async_call(MP_DOMAIN, SERVICE_MEDIA_PREVIOUS_TRACK, data) | [
"async",
"def",
"async_media_previous_track",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entity_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"{",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"MP_DOMAIN",
",",
"SERVICE_MEDIA_PREVIOUS_TRACK",
",",
"data",
")"
] | [
126,
0
] | [
131,
81
] | python | en | ['en', 'en', 'en'] | True |
async_play_media | (
hass: HomeAssistantType,
media_type: str,
media_id: str,
entity_id: Optional[str] = None,
enqueue: Optional[str] = None,
) | Send the media player the command for playing media. | Send the media player the command for playing media. | async def async_play_media(
hass: HomeAssistantType,
media_type: str,
media_id: str,
entity_id: Optional[str] = None,
enqueue: Optional[str] = None,
) -> None:
"""Send the media player the command for playing media."""
data = {ATTR_MEDIA_CONTENT_TYPE: media_type, ATTR_MEDIA_CONTENT_ID: media_id}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
if enqueue:
data[ATTR_MEDIA_ENQUEUE] = enqueue
await hass.services.async_call(MP_DOMAIN, SERVICE_PLAY_MEDIA, data) | [
"async",
"def",
"async_play_media",
"(",
"hass",
":",
"HomeAssistantType",
",",
"media_type",
":",
"str",
",",
"media_id",
":",
"str",
",",
"entity_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"enqueue",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
")",
"->",
"None",
":",
"data",
"=",
"{",
"ATTR_MEDIA_CONTENT_TYPE",
":",
"media_type",
",",
"ATTR_MEDIA_CONTENT_ID",
":",
"media_id",
"}",
"if",
"entity_id",
":",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"=",
"entity_id",
"if",
"enqueue",
":",
"data",
"[",
"ATTR_MEDIA_ENQUEUE",
"]",
"=",
"enqueue",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"MP_DOMAIN",
",",
"SERVICE_PLAY_MEDIA",
",",
"data",
")"
] | [
134,
0
] | [
150,
71
] | python | en | ['en', 'en', 'en'] | True |
test_setup | (
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) | Test setup with basic config. | Test setup with basic config. | async def test_setup(
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test setup with basic config."""
await setup_integration(hass, aioclient_mock)
assert hass.states.get(MAIN_ENTITY_ID)
assert hass.states.get(CLIENT_ENTITY_ID)
assert hass.states.get(UNAVAILABLE_ENTITY_ID) | [
"async",
"def",
"test_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"MAIN_ENTITY_ID",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"CLIENT_ENTITY_ID",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"UNAVAILABLE_ENTITY_ID",
")"
] | [
153,
0
] | [
160,
49
] | python | en | ['en', 'zu', 'en'] | True |
test_unique_id | (
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) | Test unique id. | Test unique id. | async def test_unique_id(
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test unique id."""
await setup_integration(hass, aioclient_mock)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
main = entity_registry.async_get(MAIN_ENTITY_ID)
assert main.device_class == DEVICE_CLASS_RECEIVER
assert main.unique_id == "028877455858"
client = entity_registry.async_get(CLIENT_ENTITY_ID)
assert client.device_class == DEVICE_CLASS_RECEIVER
assert client.unique_id == "2CA17D1CD30X"
unavailable_client = entity_registry.async_get(UNAVAILABLE_ENTITY_ID)
assert unavailable_client.device_class == DEVICE_CLASS_RECEIVER
assert unavailable_client.unique_id == "9XXXXXXXXXX9" | [
"async",
"def",
"test_unique_id",
"(",
"hass",
":",
"HomeAssistantType",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"main",
"=",
"entity_registry",
".",
"async_get",
"(",
"MAIN_ENTITY_ID",
")",
"assert",
"main",
".",
"device_class",
"==",
"DEVICE_CLASS_RECEIVER",
"assert",
"main",
".",
"unique_id",
"==",
"\"028877455858\"",
"client",
"=",
"entity_registry",
".",
"async_get",
"(",
"CLIENT_ENTITY_ID",
")",
"assert",
"client",
".",
"device_class",
"==",
"DEVICE_CLASS_RECEIVER",
"assert",
"client",
".",
"unique_id",
"==",
"\"2CA17D1CD30X\"",
"unavailable_client",
"=",
"entity_registry",
".",
"async_get",
"(",
"UNAVAILABLE_ENTITY_ID",
")",
"assert",
"unavailable_client",
".",
"device_class",
"==",
"DEVICE_CLASS_RECEIVER",
"assert",
"unavailable_client",
".",
"unique_id",
"==",
"\"9XXXXXXXXXX9\""
] | [
163,
0
] | [
181,
57
] | python | en | ['fr', 'la', 'en'] | False |
test_supported_features | (
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) | Test supported features. | Test supported features. | async def test_supported_features(
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test supported features."""
await setup_integration(hass, aioclient_mock)
# Features supported for main DVR
state = hass.states.get(MAIN_ENTITY_ID)
assert (
SUPPORT_PAUSE
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_PLAY_MEDIA
| SUPPORT_STOP
| SUPPORT_NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_PLAY
== state.attributes.get("supported_features")
)
# Feature supported for clients.
state = hass.states.get(CLIENT_ENTITY_ID)
assert (
SUPPORT_PAUSE
| SUPPORT_PLAY_MEDIA
| SUPPORT_STOP
| SUPPORT_NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_PLAY
== state.attributes.get("supported_features")
) | [
"async",
"def",
"test_supported_features",
"(",
"hass",
":",
"HomeAssistantType",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"# Features supported for main DVR",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"MAIN_ENTITY_ID",
")",
"assert",
"(",
"SUPPORT_PAUSE",
"|",
"SUPPORT_TURN_ON",
"|",
"SUPPORT_TURN_OFF",
"|",
"SUPPORT_PLAY_MEDIA",
"|",
"SUPPORT_STOP",
"|",
"SUPPORT_NEXT_TRACK",
"|",
"SUPPORT_PREVIOUS_TRACK",
"|",
"SUPPORT_PLAY",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"supported_features\"",
")",
")",
"# Feature supported for clients.",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"CLIENT_ENTITY_ID",
")",
"assert",
"(",
"SUPPORT_PAUSE",
"|",
"SUPPORT_PLAY_MEDIA",
"|",
"SUPPORT_STOP",
"|",
"SUPPORT_NEXT_TRACK",
"|",
"SUPPORT_PREVIOUS_TRACK",
"|",
"SUPPORT_PLAY",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"supported_features\"",
")",
")"
] | [
184,
0
] | [
214,
5
] | python | en | ['en', 'en', 'en'] | True |
test_check_attributes | (
hass: HomeAssistantType,
mock_now: dt_util.dt.datetime,
aioclient_mock: AiohttpClientMocker,
) | Test attributes. | Test attributes. | async def test_check_attributes(
hass: HomeAssistantType,
mock_now: dt_util.dt.datetime,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test attributes."""
await setup_integration(hass, aioclient_mock)
state = hass.states.get(MAIN_ENTITY_ID)
assert state.state == STATE_PLAYING
assert state.attributes.get(ATTR_MEDIA_CONTENT_ID) == "17016356"
assert state.attributes.get(ATTR_MEDIA_CONTENT_TYPE) == MEDIA_TYPE_MOVIE
assert state.attributes.get(ATTR_MEDIA_DURATION) == 7200
assert state.attributes.get(ATTR_MEDIA_POSITION) == 4437
assert state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT)
assert state.attributes.get(ATTR_MEDIA_TITLE) == "Snow Bride"
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) is None
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "{} ({})".format("HALLHD", "312")
assert state.attributes.get(ATTR_INPUT_SOURCE) == "312"
assert not state.attributes.get(ATTR_MEDIA_CURRENTLY_RECORDING)
assert state.attributes.get(ATTR_MEDIA_RATING) == "TV-G"
assert not state.attributes.get(ATTR_MEDIA_RECORDED)
assert state.attributes.get(ATTR_MEDIA_START_TIME) == datetime(
2020, 3, 21, 13, 0, tzinfo=dt_util.UTC
)
state = hass.states.get(CLIENT_ENTITY_ID)
assert state.state == STATE_PLAYING
assert state.attributes.get(ATTR_MEDIA_CONTENT_ID) == "4405732"
assert state.attributes.get(ATTR_MEDIA_CONTENT_TYPE) == MEDIA_TYPE_TVSHOW
assert state.attributes.get(ATTR_MEDIA_DURATION) == 1791
assert state.attributes.get(ATTR_MEDIA_POSITION) == 263
assert state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT)
assert state.attributes.get(ATTR_MEDIA_TITLE) == "Tyler's Ultimate"
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) == "Spaghetti and Clam Sauce"
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "{} ({})".format("FOODHD", "231")
assert state.attributes.get(ATTR_INPUT_SOURCE) == "231"
assert not state.attributes.get(ATTR_MEDIA_CURRENTLY_RECORDING)
assert state.attributes.get(ATTR_MEDIA_RATING) == "No Rating"
assert state.attributes.get(ATTR_MEDIA_RECORDED)
assert state.attributes.get(ATTR_MEDIA_START_TIME) == datetime(
2010, 7, 5, 15, 0, 8, tzinfo=dt_util.UTC
)
state = hass.states.get(MUSIC_ENTITY_ID)
assert state.state == STATE_PLAYING
assert state.attributes.get(ATTR_MEDIA_CONTENT_ID) == "76917562"
assert state.attributes.get(ATTR_MEDIA_CONTENT_TYPE) == MEDIA_TYPE_MUSIC
assert state.attributes.get(ATTR_MEDIA_DURATION) == 86400
assert state.attributes.get(ATTR_MEDIA_POSITION) == 15050
assert state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT)
assert state.attributes.get(ATTR_MEDIA_TITLE) == "Sparkle In Your Eyes"
assert state.attributes.get(ATTR_MEDIA_ARTIST) == "Gerald Albright"
assert state.attributes.get(ATTR_MEDIA_ALBUM_NAME) == "Slam Dunk (2014)"
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) is None
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "{} ({})".format("MCSJ", "851")
assert state.attributes.get(ATTR_INPUT_SOURCE) == "851"
assert not state.attributes.get(ATTR_MEDIA_CURRENTLY_RECORDING)
assert state.attributes.get(ATTR_MEDIA_RATING) == "TV-PG"
assert not state.attributes.get(ATTR_MEDIA_RECORDED)
assert state.attributes.get(ATTR_MEDIA_START_TIME) == datetime(
2020, 3, 21, 10, 0, 0, tzinfo=dt_util.UTC
)
state = hass.states.get(STANDBY_ENTITY_ID)
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_MEDIA_CONTENT_ID) is None
assert state.attributes.get(ATTR_MEDIA_CONTENT_TYPE) is None
assert state.attributes.get(ATTR_MEDIA_DURATION) is None
assert state.attributes.get(ATTR_MEDIA_POSITION) is None
assert state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT) is None
assert state.attributes.get(ATTR_MEDIA_TITLE) is None
assert state.attributes.get(ATTR_MEDIA_ARTIST) is None
assert state.attributes.get(ATTR_MEDIA_ALBUM_NAME) is None
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) is None
assert state.attributes.get(ATTR_MEDIA_CHANNEL) is None
assert state.attributes.get(ATTR_INPUT_SOURCE) is None
assert not state.attributes.get(ATTR_MEDIA_CURRENTLY_RECORDING)
assert state.attributes.get(ATTR_MEDIA_RATING) is None
assert not state.attributes.get(ATTR_MEDIA_RECORDED)
state = hass.states.get(RESTRICTED_ENTITY_ID)
assert state.state == STATE_PLAYING
assert state.attributes.get(ATTR_MEDIA_CONTENT_ID) is None
assert state.attributes.get(ATTR_MEDIA_CONTENT_TYPE) is None
assert state.attributes.get(ATTR_MEDIA_DURATION) is None
assert state.attributes.get(ATTR_MEDIA_POSITION) is None
assert state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT) is None
assert state.attributes.get(ATTR_MEDIA_TITLE) is None
assert state.attributes.get(ATTR_MEDIA_ARTIST) is None
assert state.attributes.get(ATTR_MEDIA_ALBUM_NAME) is None
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) is None
assert state.attributes.get(ATTR_MEDIA_CHANNEL) is None
assert state.attributes.get(ATTR_INPUT_SOURCE) is None
assert not state.attributes.get(ATTR_MEDIA_CURRENTLY_RECORDING)
assert state.attributes.get(ATTR_MEDIA_RATING) is None
assert not state.attributes.get(ATTR_MEDIA_RECORDED)
state = hass.states.get(UNAVAILABLE_ENTITY_ID)
assert state.state == STATE_UNAVAILABLE | [
"async",
"def",
"test_check_attributes",
"(",
"hass",
":",
"HomeAssistantType",
",",
"mock_now",
":",
"dt_util",
".",
"dt",
".",
"datetime",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
",",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"MAIN_ENTITY_ID",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_PLAYING",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_ID",
")",
"==",
"\"17016356\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_TYPE",
")",
"==",
"MEDIA_TYPE_MOVIE",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_DURATION",
")",
"==",
"7200",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION",
")",
"==",
"4437",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION_UPDATED_AT",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_TITLE",
")",
"==",
"\"Snow Bride\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_SERIES_TITLE",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CHANNEL",
")",
"==",
"\"{} ({})\"",
".",
"format",
"(",
"\"HALLHD\"",
",",
"\"312\"",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_INPUT_SOURCE",
")",
"==",
"\"312\"",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CURRENTLY_RECORDING",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RATING",
")",
"==",
"\"TV-G\"",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RECORDED",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_START_TIME",
")",
"==",
"datetime",
"(",
"2020",
",",
"3",
",",
"21",
",",
"13",
",",
"0",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"CLIENT_ENTITY_ID",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_PLAYING",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_ID",
")",
"==",
"\"4405732\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_TYPE",
")",
"==",
"MEDIA_TYPE_TVSHOW",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_DURATION",
")",
"==",
"1791",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION",
")",
"==",
"263",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION_UPDATED_AT",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_TITLE",
")",
"==",
"\"Tyler's Ultimate\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_SERIES_TITLE",
")",
"==",
"\"Spaghetti and Clam Sauce\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CHANNEL",
")",
"==",
"\"{} ({})\"",
".",
"format",
"(",
"\"FOODHD\"",
",",
"\"231\"",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_INPUT_SOURCE",
")",
"==",
"\"231\"",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CURRENTLY_RECORDING",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RATING",
")",
"==",
"\"No Rating\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RECORDED",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_START_TIME",
")",
"==",
"datetime",
"(",
"2010",
",",
"7",
",",
"5",
",",
"15",
",",
"0",
",",
"8",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"MUSIC_ENTITY_ID",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_PLAYING",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_ID",
")",
"==",
"\"76917562\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_TYPE",
")",
"==",
"MEDIA_TYPE_MUSIC",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_DURATION",
")",
"==",
"86400",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION",
")",
"==",
"15050",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION_UPDATED_AT",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_TITLE",
")",
"==",
"\"Sparkle In Your Eyes\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_ARTIST",
")",
"==",
"\"Gerald Albright\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_ALBUM_NAME",
")",
"==",
"\"Slam Dunk (2014)\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_SERIES_TITLE",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CHANNEL",
")",
"==",
"\"{} ({})\"",
".",
"format",
"(",
"\"MCSJ\"",
",",
"\"851\"",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_INPUT_SOURCE",
")",
"==",
"\"851\"",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CURRENTLY_RECORDING",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RATING",
")",
"==",
"\"TV-PG\"",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RECORDED",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_START_TIME",
")",
"==",
"datetime",
"(",
"2020",
",",
"3",
",",
"21",
",",
"10",
",",
"0",
",",
"0",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"STANDBY_ENTITY_ID",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_ID",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_TYPE",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_DURATION",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION_UPDATED_AT",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_TITLE",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_ARTIST",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_ALBUM_NAME",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_SERIES_TITLE",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CHANNEL",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_INPUT_SOURCE",
")",
"is",
"None",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CURRENTLY_RECORDING",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RATING",
")",
"is",
"None",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RECORDED",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"RESTRICTED_ENTITY_ID",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_PLAYING",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_ID",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CONTENT_TYPE",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_DURATION",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION_UPDATED_AT",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_TITLE",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_ARTIST",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_ALBUM_NAME",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_SERIES_TITLE",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CHANNEL",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_INPUT_SOURCE",
")",
"is",
"None",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_CURRENTLY_RECORDING",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RATING",
")",
"is",
"None",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_RECORDED",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"UNAVAILABLE_ENTITY_ID",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_UNAVAILABLE"
] | [
217,
0
] | [
321,
43
] | python | en | ['en', 'la', 'en'] | False |
test_attributes_paused | (
hass: HomeAssistantType,
mock_now: dt_util.dt.datetime,
aioclient_mock: AiohttpClientMocker,
) | Test attributes while paused. | Test attributes while paused. | async def test_attributes_paused(
hass: HomeAssistantType,
mock_now: dt_util.dt.datetime,
aioclient_mock: AiohttpClientMocker,
):
"""Test attributes while paused."""
await setup_integration(hass, aioclient_mock)
state = hass.states.get(CLIENT_ENTITY_ID)
last_updated = state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT)
# Test to make sure that ATTR_MEDIA_POSITION_UPDATED_AT is not
# updated if TV is paused.
with patch(
"homeassistant.util.dt.utcnow", return_value=mock_now + timedelta(minutes=5)
):
await async_media_pause(hass, CLIENT_ENTITY_ID)
await hass.async_block_till_done()
state = hass.states.get(CLIENT_ENTITY_ID)
assert state.state == STATE_PAUSED
assert state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT) == last_updated | [
"async",
"def",
"test_attributes_paused",
"(",
"hass",
":",
"HomeAssistantType",
",",
"mock_now",
":",
"dt_util",
".",
"dt",
".",
"datetime",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
",",
")",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"CLIENT_ENTITY_ID",
")",
"last_updated",
"=",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION_UPDATED_AT",
")",
"# Test to make sure that ATTR_MEDIA_POSITION_UPDATED_AT is not",
"# updated if TV is paused.",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"mock_now",
"+",
"timedelta",
"(",
"minutes",
"=",
"5",
")",
")",
":",
"await",
"async_media_pause",
"(",
"hass",
",",
"CLIENT_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"CLIENT_ENTITY_ID",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_PAUSED",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_MEDIA_POSITION_UPDATED_AT",
")",
"==",
"last_updated"
] | [
324,
0
] | [
345,
79
] | python | en | ['en', 'en', 'en'] | True |
test_main_services | (
hass: HomeAssistantType,
mock_now: dt_util.dt.datetime,
aioclient_mock: AiohttpClientMocker,
) | Test the different services. | Test the different services. | async def test_main_services(
hass: HomeAssistantType,
mock_now: dt_util.dt.datetime,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test the different services."""
await setup_integration(hass, aioclient_mock)
with patch("directv.DIRECTV.remote") as remote_mock:
await async_turn_off(hass, MAIN_ENTITY_ID)
await hass.async_block_till_done()
remote_mock.assert_called_once_with("poweroff", "0")
with patch("directv.DIRECTV.remote") as remote_mock:
await async_turn_on(hass, MAIN_ENTITY_ID)
await hass.async_block_till_done()
remote_mock.assert_called_once_with("poweron", "0")
with patch("directv.DIRECTV.remote") as remote_mock:
await async_media_pause(hass, MAIN_ENTITY_ID)
await hass.async_block_till_done()
remote_mock.assert_called_once_with("pause", "0")
with patch("directv.DIRECTV.remote") as remote_mock:
await async_media_play(hass, MAIN_ENTITY_ID)
await hass.async_block_till_done()
remote_mock.assert_called_once_with("play", "0")
with patch("directv.DIRECTV.remote") as remote_mock:
await async_media_next_track(hass, MAIN_ENTITY_ID)
await hass.async_block_till_done()
remote_mock.assert_called_once_with("ffwd", "0")
with patch("directv.DIRECTV.remote") as remote_mock:
await async_media_previous_track(hass, MAIN_ENTITY_ID)
await hass.async_block_till_done()
remote_mock.assert_called_once_with("rew", "0")
with patch("directv.DIRECTV.remote") as remote_mock:
await async_media_stop(hass, MAIN_ENTITY_ID)
await hass.async_block_till_done()
remote_mock.assert_called_once_with("stop", "0")
with patch("directv.DIRECTV.tune") as tune_mock:
await async_play_media(hass, "channel", 312, MAIN_ENTITY_ID)
await hass.async_block_till_done()
tune_mock.assert_called_once_with("312", "0") | [
"async",
"def",
"test_main_services",
"(",
"hass",
":",
"HomeAssistantType",
",",
"mock_now",
":",
"dt_util",
".",
"dt",
".",
"datetime",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
",",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"with",
"patch",
"(",
"\"directv.DIRECTV.remote\"",
")",
"as",
"remote_mock",
":",
"await",
"async_turn_off",
"(",
"hass",
",",
"MAIN_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"remote_mock",
".",
"assert_called_once_with",
"(",
"\"poweroff\"",
",",
"\"0\"",
")",
"with",
"patch",
"(",
"\"directv.DIRECTV.remote\"",
")",
"as",
"remote_mock",
":",
"await",
"async_turn_on",
"(",
"hass",
",",
"MAIN_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"remote_mock",
".",
"assert_called_once_with",
"(",
"\"poweron\"",
",",
"\"0\"",
")",
"with",
"patch",
"(",
"\"directv.DIRECTV.remote\"",
")",
"as",
"remote_mock",
":",
"await",
"async_media_pause",
"(",
"hass",
",",
"MAIN_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"remote_mock",
".",
"assert_called_once_with",
"(",
"\"pause\"",
",",
"\"0\"",
")",
"with",
"patch",
"(",
"\"directv.DIRECTV.remote\"",
")",
"as",
"remote_mock",
":",
"await",
"async_media_play",
"(",
"hass",
",",
"MAIN_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"remote_mock",
".",
"assert_called_once_with",
"(",
"\"play\"",
",",
"\"0\"",
")",
"with",
"patch",
"(",
"\"directv.DIRECTV.remote\"",
")",
"as",
"remote_mock",
":",
"await",
"async_media_next_track",
"(",
"hass",
",",
"MAIN_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"remote_mock",
".",
"assert_called_once_with",
"(",
"\"ffwd\"",
",",
"\"0\"",
")",
"with",
"patch",
"(",
"\"directv.DIRECTV.remote\"",
")",
"as",
"remote_mock",
":",
"await",
"async_media_previous_track",
"(",
"hass",
",",
"MAIN_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"remote_mock",
".",
"assert_called_once_with",
"(",
"\"rew\"",
",",
"\"0\"",
")",
"with",
"patch",
"(",
"\"directv.DIRECTV.remote\"",
")",
"as",
"remote_mock",
":",
"await",
"async_media_stop",
"(",
"hass",
",",
"MAIN_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"remote_mock",
".",
"assert_called_once_with",
"(",
"\"stop\"",
",",
"\"0\"",
")",
"with",
"patch",
"(",
"\"directv.DIRECTV.tune\"",
")",
"as",
"tune_mock",
":",
"await",
"async_play_media",
"(",
"hass",
",",
"\"channel\"",
",",
"312",
",",
"MAIN_ENTITY_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"tune_mock",
".",
"assert_called_once_with",
"(",
"\"312\"",
",",
"\"0\"",
")"
] | [
348,
0
] | [
394,
53
] | python | en | ['en', 'en', 'en'] | True |
run | (args) | Handle Home Assistant auth provider script. | Handle Home Assistant auth provider script. | def run(args):
"""Handle Home Assistant auth provider script."""
parser = argparse.ArgumentParser(description="Manage Home Assistant users")
parser.add_argument("--script", choices=["auth"])
parser.add_argument(
"-c",
"--config",
default=get_default_config_dir(),
help="Directory that contains the Home Assistant configuration",
)
subparsers = parser.add_subparsers(dest="func")
subparsers.required = True
parser_list = subparsers.add_parser("list")
parser_list.set_defaults(func=list_users)
parser_add = subparsers.add_parser("add")
parser_add.add_argument("username", type=str)
parser_add.add_argument("password", type=str)
parser_add.set_defaults(func=add_user)
parser_validate_login = subparsers.add_parser("validate")
parser_validate_login.add_argument("username", type=str)
parser_validate_login.add_argument("password", type=str)
parser_validate_login.set_defaults(func=validate_login)
parser_change_pw = subparsers.add_parser("change_password")
parser_change_pw.add_argument("username", type=str)
parser_change_pw.add_argument("new_password", type=str)
parser_change_pw.set_defaults(func=change_password)
asyncio.set_event_loop_policy(runner.HassEventLoopPolicy(False))
asyncio.run(run_command(parser.parse_args(args))) | [
"def",
"run",
"(",
"args",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"\"Manage Home Assistant users\"",
")",
"parser",
".",
"add_argument",
"(",
"\"--script\"",
",",
"choices",
"=",
"[",
"\"auth\"",
"]",
")",
"parser",
".",
"add_argument",
"(",
"\"-c\"",
",",
"\"--config\"",
",",
"default",
"=",
"get_default_config_dir",
"(",
")",
",",
"help",
"=",
"\"Directory that contains the Home Assistant configuration\"",
",",
")",
"subparsers",
"=",
"parser",
".",
"add_subparsers",
"(",
"dest",
"=",
"\"func\"",
")",
"subparsers",
".",
"required",
"=",
"True",
"parser_list",
"=",
"subparsers",
".",
"add_parser",
"(",
"\"list\"",
")",
"parser_list",
".",
"set_defaults",
"(",
"func",
"=",
"list_users",
")",
"parser_add",
"=",
"subparsers",
".",
"add_parser",
"(",
"\"add\"",
")",
"parser_add",
".",
"add_argument",
"(",
"\"username\"",
",",
"type",
"=",
"str",
")",
"parser_add",
".",
"add_argument",
"(",
"\"password\"",
",",
"type",
"=",
"str",
")",
"parser_add",
".",
"set_defaults",
"(",
"func",
"=",
"add_user",
")",
"parser_validate_login",
"=",
"subparsers",
".",
"add_parser",
"(",
"\"validate\"",
")",
"parser_validate_login",
".",
"add_argument",
"(",
"\"username\"",
",",
"type",
"=",
"str",
")",
"parser_validate_login",
".",
"add_argument",
"(",
"\"password\"",
",",
"type",
"=",
"str",
")",
"parser_validate_login",
".",
"set_defaults",
"(",
"func",
"=",
"validate_login",
")",
"parser_change_pw",
"=",
"subparsers",
".",
"add_parser",
"(",
"\"change_password\"",
")",
"parser_change_pw",
".",
"add_argument",
"(",
"\"username\"",
",",
"type",
"=",
"str",
")",
"parser_change_pw",
".",
"add_argument",
"(",
"\"new_password\"",
",",
"type",
"=",
"str",
")",
"parser_change_pw",
".",
"set_defaults",
"(",
"func",
"=",
"change_password",
")",
"asyncio",
".",
"set_event_loop_policy",
"(",
"runner",
".",
"HassEventLoopPolicy",
"(",
"False",
")",
")",
"asyncio",
".",
"run",
"(",
"run_command",
"(",
"parser",
".",
"parse_args",
"(",
"args",
")",
")",
")"
] | [
15,
0
] | [
47,
53
] | python | en | ['fr', 'en', 'en'] | True |
run_command | (args) | Run the command. | Run the command. | async def run_command(args):
"""Run the command."""
hass = HomeAssistant()
hass.config.config_dir = os.path.join(os.getcwd(), args.config)
hass.auth = await auth_manager_from_config(hass, [{"type": "homeassistant"}], [])
provider = hass.auth.auth_providers[0]
await provider.async_initialize()
await args.func(hass, provider, args)
# Triggers save on used storage helpers with delay (core auth)
logging.getLogger("homeassistant.core").setLevel(logging.WARNING)
await hass.async_stop() | [
"async",
"def",
"run_command",
"(",
"args",
")",
":",
"hass",
"=",
"HomeAssistant",
"(",
")",
"hass",
".",
"config",
".",
"config_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"args",
".",
"config",
")",
"hass",
".",
"auth",
"=",
"await",
"auth_manager_from_config",
"(",
"hass",
",",
"[",
"{",
"\"type\"",
":",
"\"homeassistant\"",
"}",
"]",
",",
"[",
"]",
")",
"provider",
"=",
"hass",
".",
"auth",
".",
"auth_providers",
"[",
"0",
"]",
"await",
"provider",
".",
"async_initialize",
"(",
")",
"await",
"args",
".",
"func",
"(",
"hass",
",",
"provider",
",",
"args",
")",
"# Triggers save on used storage helpers with delay (core auth)",
"logging",
".",
"getLogger",
"(",
"\"homeassistant.core\"",
")",
".",
"setLevel",
"(",
"logging",
".",
"WARNING",
")",
"await",
"hass",
".",
"async_stop",
"(",
")"
] | [
50,
0
] | [
62,
27
] | python | en | ['en', 'it', '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.