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 |
---|---|---|---|---|---|---|---|---|---|---|---|
async_get_triggers | (hass: HomeAssistant, device_id: str) | List device triggers for Vacuum devices. | List device triggers for Vacuum devices. | async def async_get_triggers(hass: HomeAssistant, device_id: str) -> List[dict]:
"""List device triggers for Vacuum devices."""
registry = await entity_registry.async_get_registry(hass)
triggers = []
# Get all the integrations entities for this device
for entry in entity_registry.async_entries_for_device(registry, device_id):
if entry.domain != DOMAIN:
continue
triggers.append(
{
CONF_PLATFORM: "device",
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "cleaning",
}
)
triggers.append(
{
CONF_PLATFORM: "device",
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "docked",
}
)
return triggers | [
"async",
"def",
"async_get_triggers",
"(",
"hass",
":",
"HomeAssistant",
",",
"device_id",
":",
"str",
")",
"->",
"List",
"[",
"dict",
"]",
":",
"registry",
"=",
"await",
"entity_registry",
".",
"async_get_registry",
"(",
"hass",
")",
"triggers",
"=",
"[",
"]",
"# Get all the integrations entities for this device",
"for",
"entry",
"in",
"entity_registry",
".",
"async_entries_for_device",
"(",
"registry",
",",
"device_id",
")",
":",
"if",
"entry",
".",
"domain",
"!=",
"DOMAIN",
":",
"continue",
"triggers",
".",
"append",
"(",
"{",
"CONF_PLATFORM",
":",
"\"device\"",
",",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"cleaning\"",
",",
"}",
")",
"triggers",
".",
"append",
"(",
"{",
"CONF_PLATFORM",
":",
"\"device\"",
",",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"docked\"",
",",
"}",
")",
"return",
"triggers"
] | [
31,
0
] | [
60,
19
] | python | en | ['de', 'en', 'en'] | True |
async_attach_trigger | (
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: dict,
) | Attach a trigger. | Attach a trigger. | async def async_attach_trigger(
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: dict,
) -> CALLBACK_TYPE:
"""Attach a trigger."""
config = TRIGGER_SCHEMA(config)
if config[CONF_TYPE] == "cleaning":
from_state = [state for state in STATES if state != STATE_CLEANING]
to_state = STATE_CLEANING
else:
from_state = [state for state in STATES if state != STATE_DOCKED]
to_state = STATE_DOCKED
state_config = {
CONF_PLATFORM: "state",
CONF_ENTITY_ID: config[CONF_ENTITY_ID],
state_trigger.CONF_FROM: from_state,
state_trigger.CONF_TO: to_state,
}
state_config = state_trigger.TRIGGER_SCHEMA(state_config)
return await state_trigger.async_attach_trigger(
hass, state_config, action, automation_info, platform_type="device"
) | [
"async",
"def",
"async_attach_trigger",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"ConfigType",
",",
"action",
":",
"AutomationActionType",
",",
"automation_info",
":",
"dict",
",",
")",
"->",
"CALLBACK_TYPE",
":",
"config",
"=",
"TRIGGER_SCHEMA",
"(",
"config",
")",
"if",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"cleaning\"",
":",
"from_state",
"=",
"[",
"state",
"for",
"state",
"in",
"STATES",
"if",
"state",
"!=",
"STATE_CLEANING",
"]",
"to_state",
"=",
"STATE_CLEANING",
"else",
":",
"from_state",
"=",
"[",
"state",
"for",
"state",
"in",
"STATES",
"if",
"state",
"!=",
"STATE_DOCKED",
"]",
"to_state",
"=",
"STATE_DOCKED",
"state_config",
"=",
"{",
"CONF_PLATFORM",
":",
"\"state\"",
",",
"CONF_ENTITY_ID",
":",
"config",
"[",
"CONF_ENTITY_ID",
"]",
",",
"state_trigger",
".",
"CONF_FROM",
":",
"from_state",
",",
"state_trigger",
".",
"CONF_TO",
":",
"to_state",
",",
"}",
"state_config",
"=",
"state_trigger",
".",
"TRIGGER_SCHEMA",
"(",
"state_config",
")",
"return",
"await",
"state_trigger",
".",
"async_attach_trigger",
"(",
"hass",
",",
"state_config",
",",
"action",
",",
"automation_info",
",",
"platform_type",
"=",
"\"device\"",
")"
] | [
63,
0
] | [
88,
5
] | python | en | ['en', 'lb', 'en'] | True |
async_setup_platform | (
hass: HomeAssistantType, config: dict, async_add_entities, discovery_info=None
) | Set up from legacy configuration file. Obsolete. | Set up from legacy configuration file. Obsolete. | async def async_setup_platform(
hass: HomeAssistantType, config: dict, async_add_entities, discovery_info=None
) -> None:
"""Set up from legacy configuration file. Obsolete."""
_LOGGER.error(
"Configuring Songpal through media_player platform is no longer supported. Convert to songpal platform or UI configuration"
) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config",
":",
"dict",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
"->",
"None",
":",
"_LOGGER",
".",
"error",
"(",
"\"Configuring Songpal through media_player platform is no longer supported. Convert to songpal platform or UI configuration\"",
")"
] | [
54,
0
] | [
60,
5
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (
hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities
) | Set up songpal media player. | Set up songpal media player. | async def async_setup_entry(
hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities
) -> None:
"""Set up songpal media player."""
name = config_entry.data[CONF_NAME]
endpoint = config_entry.data[CONF_ENDPOINT]
device = Device(endpoint)
try:
async with async_timeout.timeout(
10
): # set timeout to avoid blocking the setup process
await device.get_supported_methods()
except (SongpalException, asyncio.TimeoutError) as ex:
_LOGGER.warning("[%s(%s)] Unable to connect", name, endpoint)
_LOGGER.debug("Unable to get methods from songpal: %s", ex)
raise PlatformNotReady from ex
songpal_entity = SongpalEntity(name, device)
async_add_entities([songpal_entity], True)
platform = entity_platform.current_platform.get()
platform.async_register_entity_service(
SET_SOUND_SETTING,
{vol.Required(PARAM_NAME): cv.string, vol.Required(PARAM_VALUE): cv.string},
"async_set_sound_setting",
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config_entry",
":",
"ConfigEntry",
",",
"async_add_entities",
")",
"->",
"None",
":",
"name",
"=",
"config_entry",
".",
"data",
"[",
"CONF_NAME",
"]",
"endpoint",
"=",
"config_entry",
".",
"data",
"[",
"CONF_ENDPOINT",
"]",
"device",
"=",
"Device",
"(",
"endpoint",
")",
"try",
":",
"async",
"with",
"async_timeout",
".",
"timeout",
"(",
"10",
")",
":",
"# set timeout to avoid blocking the setup process",
"await",
"device",
".",
"get_supported_methods",
"(",
")",
"except",
"(",
"SongpalException",
",",
"asyncio",
".",
"TimeoutError",
")",
"as",
"ex",
":",
"_LOGGER",
".",
"warning",
"(",
"\"[%s(%s)] Unable to connect\"",
",",
"name",
",",
"endpoint",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Unable to get methods from songpal: %s\"",
",",
"ex",
")",
"raise",
"PlatformNotReady",
"from",
"ex",
"songpal_entity",
"=",
"SongpalEntity",
"(",
"name",
",",
"device",
")",
"async_add_entities",
"(",
"[",
"songpal_entity",
"]",
",",
"True",
")",
"platform",
"=",
"entity_platform",
".",
"current_platform",
".",
"get",
"(",
")",
"platform",
".",
"async_register_entity_service",
"(",
"SET_SOUND_SETTING",
",",
"{",
"vol",
".",
"Required",
"(",
"PARAM_NAME",
")",
":",
"cv",
".",
"string",
",",
"vol",
".",
"Required",
"(",
"PARAM_VALUE",
")",
":",
"cv",
".",
"string",
"}",
",",
"\"async_set_sound_setting\"",
",",
")"
] | [
63,
0
] | [
89,
5
] | python | en | ['en', 'fil', 'en'] | True |
SongpalEntity.should_poll | (self) | Return True if the device should be polled. | Return True if the device should be polled. | def should_poll(self):
"""Return True if the device should be polled."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
116,
4
] | [
118,
20
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.async_added_to_hass | (self) | Run when entity is added to hass. | Run when entity is added to hass. | async def async_added_to_hass(self):
"""Run when entity is added to hass."""
await self.async_activate_websocket() | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"self",
".",
"async_activate_websocket",
"(",
")"
] | [
120,
4
] | [
122,
45
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.async_will_remove_from_hass | (self) | Run when entity will be removed from hass. | Run when entity will be removed from hass. | async def async_will_remove_from_hass(self):
"""Run when entity will be removed from hass."""
await self._dev.stop_listen_notifications() | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"await",
"self",
".",
"_dev",
".",
"stop_listen_notifications",
"(",
")"
] | [
124,
4
] | [
126,
51
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.async_activate_websocket | (self) | Activate websocket for listening if wanted. | Activate websocket for listening if wanted. | async def async_activate_websocket(self):
"""Activate websocket for listening if wanted."""
_LOGGER.info("Activating websocket connection")
async def _volume_changed(volume: VolumeChange):
_LOGGER.debug("Volume changed: %s", volume)
self._volume = volume.volume
self._is_muted = volume.mute
self.async_write_ha_state()
async def _source_changed(content: ContentChange):
_LOGGER.debug("Source changed: %s", content)
if content.is_input:
self._active_source = self._sources[content.uri]
_LOGGER.debug("New active source: %s", self._active_source)
self.async_write_ha_state()
else:
_LOGGER.debug("Got non-handled content change: %s", content)
async def _power_changed(power: PowerChange):
_LOGGER.debug("Power changed: %s", power)
self._state = power.status
self.async_write_ha_state()
async def _try_reconnect(connect: ConnectChange):
_LOGGER.warning(
"[%s(%s)] Got disconnected, trying to reconnect",
self.name,
self._dev.endpoint,
)
_LOGGER.debug("Disconnected: %s", connect.exception)
self._available = False
self.async_write_ha_state()
# Try to reconnect forever, a successful reconnect will initialize
# the websocket connection again.
delay = INITIAL_RETRY_DELAY
while not self._available:
_LOGGER.debug("Trying to reconnect in %s seconds", delay)
await asyncio.sleep(delay)
try:
await self._dev.get_supported_methods()
except SongpalException as ex:
_LOGGER.debug("Failed to reconnect: %s", ex)
delay = min(2 * delay, 300)
else:
# We need to inform HA about the state in case we are coming
# back from a disconnected state.
await self.async_update_ha_state(force_refresh=True)
self.hass.loop.create_task(self._dev.listen_notifications())
_LOGGER.warning(
"[%s(%s)] Connection reestablished", self.name, self._dev.endpoint
)
self._dev.on_notification(VolumeChange, _volume_changed)
self._dev.on_notification(ContentChange, _source_changed)
self._dev.on_notification(PowerChange, _power_changed)
self._dev.on_notification(ConnectChange, _try_reconnect)
async def handle_stop(event):
await self._dev.stop_listen_notifications()
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, handle_stop)
self.hass.loop.create_task(self._dev.listen_notifications()) | [
"async",
"def",
"async_activate_websocket",
"(",
"self",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Activating websocket connection\"",
")",
"async",
"def",
"_volume_changed",
"(",
"volume",
":",
"VolumeChange",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Volume changed: %s\"",
",",
"volume",
")",
"self",
".",
"_volume",
"=",
"volume",
".",
"volume",
"self",
".",
"_is_muted",
"=",
"volume",
".",
"mute",
"self",
".",
"async_write_ha_state",
"(",
")",
"async",
"def",
"_source_changed",
"(",
"content",
":",
"ContentChange",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Source changed: %s\"",
",",
"content",
")",
"if",
"content",
".",
"is_input",
":",
"self",
".",
"_active_source",
"=",
"self",
".",
"_sources",
"[",
"content",
".",
"uri",
"]",
"_LOGGER",
".",
"debug",
"(",
"\"New active source: %s\"",
",",
"self",
".",
"_active_source",
")",
"self",
".",
"async_write_ha_state",
"(",
")",
"else",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Got non-handled content change: %s\"",
",",
"content",
")",
"async",
"def",
"_power_changed",
"(",
"power",
":",
"PowerChange",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Power changed: %s\"",
",",
"power",
")",
"self",
".",
"_state",
"=",
"power",
".",
"status",
"self",
".",
"async_write_ha_state",
"(",
")",
"async",
"def",
"_try_reconnect",
"(",
"connect",
":",
"ConnectChange",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"[%s(%s)] Got disconnected, trying to reconnect\"",
",",
"self",
".",
"name",
",",
"self",
".",
"_dev",
".",
"endpoint",
",",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Disconnected: %s\"",
",",
"connect",
".",
"exception",
")",
"self",
".",
"_available",
"=",
"False",
"self",
".",
"async_write_ha_state",
"(",
")",
"# Try to reconnect forever, a successful reconnect will initialize",
"# the websocket connection again.",
"delay",
"=",
"INITIAL_RETRY_DELAY",
"while",
"not",
"self",
".",
"_available",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Trying to reconnect in %s seconds\"",
",",
"delay",
")",
"await",
"asyncio",
".",
"sleep",
"(",
"delay",
")",
"try",
":",
"await",
"self",
".",
"_dev",
".",
"get_supported_methods",
"(",
")",
"except",
"SongpalException",
"as",
"ex",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Failed to reconnect: %s\"",
",",
"ex",
")",
"delay",
"=",
"min",
"(",
"2",
"*",
"delay",
",",
"300",
")",
"else",
":",
"# We need to inform HA about the state in case we are coming",
"# back from a disconnected state.",
"await",
"self",
".",
"async_update_ha_state",
"(",
"force_refresh",
"=",
"True",
")",
"self",
".",
"hass",
".",
"loop",
".",
"create_task",
"(",
"self",
".",
"_dev",
".",
"listen_notifications",
"(",
")",
")",
"_LOGGER",
".",
"warning",
"(",
"\"[%s(%s)] Connection reestablished\"",
",",
"self",
".",
"name",
",",
"self",
".",
"_dev",
".",
"endpoint",
")",
"self",
".",
"_dev",
".",
"on_notification",
"(",
"VolumeChange",
",",
"_volume_changed",
")",
"self",
".",
"_dev",
".",
"on_notification",
"(",
"ContentChange",
",",
"_source_changed",
")",
"self",
".",
"_dev",
".",
"on_notification",
"(",
"PowerChange",
",",
"_power_changed",
")",
"self",
".",
"_dev",
".",
"on_notification",
"(",
"ConnectChange",
",",
"_try_reconnect",
")",
"async",
"def",
"handle_stop",
"(",
"event",
")",
":",
"await",
"self",
".",
"_dev",
".",
"stop_listen_notifications",
"(",
")",
"self",
".",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"handle_stop",
")",
"self",
".",
"hass",
".",
"loop",
".",
"create_task",
"(",
"self",
".",
"_dev",
".",
"listen_notifications",
"(",
")",
")"
] | [
128,
4
] | [
194,
68
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.name | (self) | Return name of the device. | Return name of the device. | def name(self):
"""Return name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
197,
4
] | [
199,
25
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self):
"""Return a unique ID."""
return self._sysinfo.macAddr | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_sysinfo",
".",
"macAddr"
] | [
202,
4
] | [
204,
36
] | python | ca | ['fr', 'ca', 'en'] | False |
SongpalEntity.device_info | (self) | Return the device info. | Return the device info. | def device_info(self):
"""Return the device info."""
return {
"connections": {(dr.CONNECTION_NETWORK_MAC, self._sysinfo.macAddr)},
"identifiers": {(DOMAIN, self.unique_id)},
"manufacturer": "Sony Corporation",
"name": self.name,
"sw_version": self._sysinfo.version,
"model": self._model,
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"connections\"",
":",
"{",
"(",
"dr",
".",
"CONNECTION_NETWORK_MAC",
",",
"self",
".",
"_sysinfo",
".",
"macAddr",
")",
"}",
",",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"unique_id",
")",
"}",
",",
"\"manufacturer\"",
":",
"\"Sony Corporation\"",
",",
"\"name\"",
":",
"self",
".",
"name",
",",
"\"sw_version\"",
":",
"self",
".",
"_sysinfo",
".",
"version",
",",
"\"model\"",
":",
"self",
".",
"_model",
",",
"}"
] | [
207,
4
] | [
216,
9
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.available | (self) | Return availability of the device. | Return availability of the device. | def available(self):
"""Return availability of the device."""
return self._available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_available"
] | [
219,
4
] | [
221,
30
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.async_set_sound_setting | (self, name, value) | Change a setting on the device. | Change a setting on the device. | async def async_set_sound_setting(self, name, value):
"""Change a setting on the device."""
_LOGGER.debug("Calling set_sound_setting with %s: %s", name, value)
await self._dev.set_sound_settings(name, value) | [
"async",
"def",
"async_set_sound_setting",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Calling set_sound_setting with %s: %s\"",
",",
"name",
",",
"value",
")",
"await",
"self",
".",
"_dev",
".",
"set_sound_settings",
"(",
"name",
",",
"value",
")"
] | [
223,
4
] | [
226,
55
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.async_update | (self) | Fetch updates from the device. | Fetch updates from the device. | async def async_update(self):
"""Fetch updates from the device."""
try:
if self._sysinfo is None:
self._sysinfo = await self._dev.get_system_info()
if self._model is None:
interface_info = await self._dev.get_interface_information()
self._model = interface_info.modelName
volumes = await self._dev.get_volume_information()
if not volumes:
_LOGGER.error("Got no volume controls, bailing out")
self._available = False
return
if len(volumes) > 1:
_LOGGER.debug("Got %s volume controls, using the first one", volumes)
volume = volumes[0]
_LOGGER.debug("Current volume: %s", volume)
self._volume_max = volume.maxVolume
self._volume_min = volume.minVolume
self._volume = volume.volume
self._volume_control = volume
self._is_muted = self._volume_control.is_muted
status = await self._dev.get_power()
self._state = status.status
_LOGGER.debug("Got state: %s", status)
inputs = await self._dev.get_inputs()
_LOGGER.debug("Got ins: %s", inputs)
self._sources = OrderedDict()
for input_ in inputs:
self._sources[input_.uri] = input_
if input_.active:
self._active_source = input_
_LOGGER.debug("Active source: %s", self._active_source)
self._available = True
except SongpalException as ex:
_LOGGER.error("Unable to update: %s", ex)
self._available = False | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"_sysinfo",
"is",
"None",
":",
"self",
".",
"_sysinfo",
"=",
"await",
"self",
".",
"_dev",
".",
"get_system_info",
"(",
")",
"if",
"self",
".",
"_model",
"is",
"None",
":",
"interface_info",
"=",
"await",
"self",
".",
"_dev",
".",
"get_interface_information",
"(",
")",
"self",
".",
"_model",
"=",
"interface_info",
".",
"modelName",
"volumes",
"=",
"await",
"self",
".",
"_dev",
".",
"get_volume_information",
"(",
")",
"if",
"not",
"volumes",
":",
"_LOGGER",
".",
"error",
"(",
"\"Got no volume controls, bailing out\"",
")",
"self",
".",
"_available",
"=",
"False",
"return",
"if",
"len",
"(",
"volumes",
")",
">",
"1",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Got %s volume controls, using the first one\"",
",",
"volumes",
")",
"volume",
"=",
"volumes",
"[",
"0",
"]",
"_LOGGER",
".",
"debug",
"(",
"\"Current volume: %s\"",
",",
"volume",
")",
"self",
".",
"_volume_max",
"=",
"volume",
".",
"maxVolume",
"self",
".",
"_volume_min",
"=",
"volume",
".",
"minVolume",
"self",
".",
"_volume",
"=",
"volume",
".",
"volume",
"self",
".",
"_volume_control",
"=",
"volume",
"self",
".",
"_is_muted",
"=",
"self",
".",
"_volume_control",
".",
"is_muted",
"status",
"=",
"await",
"self",
".",
"_dev",
".",
"get_power",
"(",
")",
"self",
".",
"_state",
"=",
"status",
".",
"status",
"_LOGGER",
".",
"debug",
"(",
"\"Got state: %s\"",
",",
"status",
")",
"inputs",
"=",
"await",
"self",
".",
"_dev",
".",
"get_inputs",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Got ins: %s\"",
",",
"inputs",
")",
"self",
".",
"_sources",
"=",
"OrderedDict",
"(",
")",
"for",
"input_",
"in",
"inputs",
":",
"self",
".",
"_sources",
"[",
"input_",
".",
"uri",
"]",
"=",
"input_",
"if",
"input_",
".",
"active",
":",
"self",
".",
"_active_source",
"=",
"input_",
"_LOGGER",
".",
"debug",
"(",
"\"Active source: %s\"",
",",
"self",
".",
"_active_source",
")",
"self",
".",
"_available",
"=",
"True",
"except",
"SongpalException",
"as",
"ex",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unable to update: %s\"",
",",
"ex",
")",
"self",
".",
"_available",
"=",
"False"
] | [
228,
4
] | [
275,
35
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.async_select_source | (self, source) | Select source. | Select source. | async def async_select_source(self, source):
"""Select source."""
for out in self._sources.values():
if out.title == source:
await out.activate()
return
_LOGGER.error("Unable to find output: %s", source) | [
"async",
"def",
"async_select_source",
"(",
"self",
",",
"source",
")",
":",
"for",
"out",
"in",
"self",
".",
"_sources",
".",
"values",
"(",
")",
":",
"if",
"out",
".",
"title",
"==",
"source",
":",
"await",
"out",
".",
"activate",
"(",
")",
"return",
"_LOGGER",
".",
"error",
"(",
"\"Unable to find output: %s\"",
",",
"source",
")"
] | [
277,
4
] | [
284,
58
] | python | ceb | ['fr', 'ceb', 'en'] | False |
SongpalEntity.source_list | (self) | Return list of available sources. | Return list of available sources. | def source_list(self):
"""Return list of available sources."""
return [src.title for src in self._sources.values()] | [
"def",
"source_list",
"(",
"self",
")",
":",
"return",
"[",
"src",
".",
"title",
"for",
"src",
"in",
"self",
".",
"_sources",
".",
"values",
"(",
")",
"]"
] | [
287,
4
] | [
289,
60
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.state | (self) | Return current state. | Return current state. | def state(self):
"""Return current state."""
if self._state:
return STATE_ON
return STATE_OFF | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
":",
"return",
"STATE_ON",
"return",
"STATE_OFF"
] | [
292,
4
] | [
296,
24
] | python | en | ['en', 'co', 'en'] | True |
SongpalEntity.source | (self) | Return currently active source. | Return currently active source. | def source(self):
"""Return currently active source."""
# Avoid a KeyError when _active_source is not (yet) populated
return getattr(self._active_source, "title", None) | [
"def",
"source",
"(",
"self",
")",
":",
"# Avoid a KeyError when _active_source is not (yet) populated",
"return",
"getattr",
"(",
"self",
".",
"_active_source",
",",
"\"title\"",
",",
"None",
")"
] | [
299,
4
] | [
302,
58
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.volume_level | (self) | Return volume level. | Return volume level. | def volume_level(self):
"""Return volume level."""
volume = self._volume / self._volume_max
return volume | [
"def",
"volume_level",
"(",
"self",
")",
":",
"volume",
"=",
"self",
".",
"_volume",
"/",
"self",
".",
"_volume_max",
"return",
"volume"
] | [
305,
4
] | [
308,
21
] | python | en | ['nl', 'no', 'en'] | False |
SongpalEntity.async_set_volume_level | (self, volume) | Set volume level. | Set volume level. | async def async_set_volume_level(self, volume):
"""Set volume level."""
volume = int(volume * self._volume_max)
_LOGGER.debug("Setting volume to %s", volume)
return await self._volume_control.set_volume(volume) | [
"async",
"def",
"async_set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"volume",
"=",
"int",
"(",
"volume",
"*",
"self",
".",
"_volume_max",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Setting volume to %s\"",
",",
"volume",
")",
"return",
"await",
"self",
".",
"_volume_control",
".",
"set_volume",
"(",
"volume",
")"
] | [
310,
4
] | [
314,
60
] | python | en | ['fr', 'sr', 'en'] | False |
SongpalEntity.async_volume_up | (self) | Set volume up. | Set volume up. | async def async_volume_up(self):
"""Set volume up."""
return await self._volume_control.set_volume(self._volume + 1) | [
"async",
"def",
"async_volume_up",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"_volume_control",
".",
"set_volume",
"(",
"self",
".",
"_volume",
"+",
"1",
")"
] | [
316,
4
] | [
318,
70
] | python | da | ['nl', 'da', 'en'] | False |
SongpalEntity.async_volume_down | (self) | Set volume down. | Set volume down. | async def async_volume_down(self):
"""Set volume down."""
return await self._volume_control.set_volume(self._volume - 1) | [
"async",
"def",
"async_volume_down",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"_volume_control",
".",
"set_volume",
"(",
"self",
".",
"_volume",
"-",
"1",
")"
] | [
320,
4
] | [
322,
70
] | python | de | ['nl', 'de', 'en'] | False |
SongpalEntity.async_turn_on | (self) | Turn the device on. | Turn the device on. | async def async_turn_on(self):
"""Turn the device on."""
return await self._dev.set_power(True) | [
"async",
"def",
"async_turn_on",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"_dev",
".",
"set_power",
"(",
"True",
")"
] | [
324,
4
] | [
326,
46
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.async_turn_off | (self) | Turn the device off. | Turn the device off. | async def async_turn_off(self):
"""Turn the device off."""
return await self._dev.set_power(False) | [
"async",
"def",
"async_turn_off",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"_dev",
".",
"set_power",
"(",
"False",
")"
] | [
328,
4
] | [
330,
47
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.async_mute_volume | (self, mute) | Mute or unmute the device. | Mute or unmute the device. | async def async_mute_volume(self, mute):
"""Mute or unmute the device."""
_LOGGER.debug("Set mute: %s", mute)
return await self._volume_control.set_mute(mute) | [
"async",
"def",
"async_mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Set mute: %s\"",
",",
"mute",
")",
"return",
"await",
"self",
".",
"_volume_control",
".",
"set_mute",
"(",
"mute",
")"
] | [
332,
4
] | [
335,
56
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.is_volume_muted | (self) | Return whether the device is muted. | Return whether the device is muted. | def is_volume_muted(self):
"""Return whether the device is muted."""
return self._is_muted | [
"def",
"is_volume_muted",
"(",
"self",
")",
":",
"return",
"self",
".",
"_is_muted"
] | [
338,
4
] | [
340,
29
] | python | en | ['en', 'en', 'en'] | True |
SongpalEntity.supported_features | (self) | Return supported features. | Return supported features. | def supported_features(self):
"""Return supported features."""
return SUPPORT_SONGPAL | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_SONGPAL"
] | [
343,
4
] | [
345,
30
] | python | en | ['en', 'en', 'en'] | True |
device_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass) | [
"def",
"device_reg",
"(",
"hass",
")",
":",
"return",
"mock_device_registry",
"(",
"hass",
")"
] | [
18,
0
] | [
20,
37
] | python | en | ['en', 'fy', 'en'] | True |
entity_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass) | [
"def",
"entity_reg",
"(",
"hass",
")",
":",
"return",
"mock_registry",
"(",
"hass",
")"
] | [
24,
0
] | [
26,
30
] | python | en | ['en', 'fy', 'en'] | True |
calls | (hass) | Track calls to a mock service. | Track calls to a mock service. | def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") | [
"def",
"calls",
"(",
"hass",
")",
":",
"return",
"async_mock_service",
"(",
"hass",
",",
"\"test\"",
",",
"\"automation\"",
")"
] | [
30,
0
] | [
32,
57
] | python | en | ['en', 'en', 'en'] | True |
test_get_triggers | (hass, device_reg, entity_reg) | Test we get the expected triggers from a arcam_fmj. | Test we get the expected triggers from a arcam_fmj. | async def test_get_triggers(hass, device_reg, entity_reg):
"""Test we get the expected triggers from a arcam_fmj."""
config_entry = MockConfigEntry(domain=DOMAIN, data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
identifiers={(DOMAIN, "host", 1234)},
)
entity_reg.async_get_or_create(
"media_player", DOMAIN, "5678", device_id=device_entry.id
)
expected_triggers = [
{
"platform": "device",
"domain": DOMAIN,
"type": "turn_on",
"device_id": device_entry.id,
"entity_id": "media_player.arcam_fmj_5678",
},
]
triggers = await async_get_device_automations(hass, "trigger", device_entry.id)
assert_lists_same(triggers, expected_triggers) | [
"async",
"def",
"test_get_triggers",
"(",
"hass",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"identifiers",
"=",
"{",
"(",
"DOMAIN",
",",
"\"host\"",
",",
"1234",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"\"media_player\"",
",",
"DOMAIN",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"expected_triggers",
"=",
"[",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"turn_on\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"\"media_player.arcam_fmj_5678\"",
",",
"}",
",",
"]",
"triggers",
"=",
"await",
"async_get_device_automations",
"(",
"hass",
",",
"\"trigger\"",
",",
"device_entry",
".",
"id",
")",
"assert_lists_same",
"(",
"triggers",
",",
"expected_triggers",
")"
] | [
35,
0
] | [
56,
50
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_turn_on_request | (hass, calls, player_setup, state) | Test for turn_on and turn_off triggers firing. | Test for turn_on and turn_off triggers firing. | async def test_if_fires_on_turn_on_request(hass, calls, player_setup, state):
"""Test for turn_on and turn_off triggers firing."""
state.get_power.return_value = None
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": player_setup,
"type": "turn_on",
},
"action": {
"service": "test.automation",
"data_template": {"some": "{{ trigger.entity_id }}"},
},
}
]
},
)
await hass.services.async_call(
"media_player",
"turn_on",
{"entity_id": player_setup},
blocking=True,
)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == player_setup | [
"async",
"def",
"test_if_fires_on_turn_on_request",
"(",
"hass",
",",
"calls",
",",
"player_setup",
",",
"state",
")",
":",
"state",
".",
"get_power",
".",
"return_value",
"=",
"None",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"[",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"player_setup",
",",
"\"type\"",
":",
"\"turn_on\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"{{ trigger.entity_id }}\"",
"}",
",",
"}",
",",
"}",
"]",
"}",
",",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"media_player\"",
",",
"\"turn_on\"",
",",
"{",
"\"entity_id\"",
":",
"player_setup",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"player_setup"
] | [
59,
0
] | [
94,
48
] | python | en | ['en', 'en', 'en'] | True |
_async_reproduce_state | (
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) | Reproduce a single state. | Reproduce a single state. | async def _async_reproduce_state(
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce a single state."""
cur_state = hass.states.get(state.entity_id)
if cur_state is None:
_LOGGER.warning("Unable to find entity %s", state.entity_id)
return
if state.state not in VALID_STATES:
_LOGGER.warning(
"Invalid state specified for %s: %s", state.entity_id, state.state
)
return
# Return if we are already at the right state.
if (
cur_state.state == state.state
and cur_state.attributes.get(ATTR_CURRENT_POSITION)
== state.attributes.get(ATTR_CURRENT_POSITION)
and cur_state.attributes.get(ATTR_CURRENT_TILT_POSITION)
== state.attributes.get(ATTR_CURRENT_TILT_POSITION)
):
return
service_data = {ATTR_ENTITY_ID: state.entity_id}
service_data_tilting = {ATTR_ENTITY_ID: state.entity_id}
if not (
cur_state.state == state.state
and cur_state.attributes.get(ATTR_CURRENT_POSITION)
== state.attributes.get(ATTR_CURRENT_POSITION)
):
# Open/Close
if state.state in [STATE_CLOSED, STATE_CLOSING]:
service = SERVICE_CLOSE_COVER
elif state.state in [STATE_OPEN, STATE_OPENING]:
if (
ATTR_CURRENT_POSITION in cur_state.attributes
and ATTR_CURRENT_POSITION in state.attributes
):
service = SERVICE_SET_COVER_POSITION
service_data[ATTR_POSITION] = state.attributes[ATTR_CURRENT_POSITION]
else:
service = SERVICE_OPEN_COVER
await hass.services.async_call(
DOMAIN, service, service_data, context=context, blocking=True
)
if (
ATTR_CURRENT_TILT_POSITION in state.attributes
and ATTR_CURRENT_TILT_POSITION in cur_state.attributes
and cur_state.attributes.get(ATTR_CURRENT_TILT_POSITION)
!= state.attributes.get(ATTR_CURRENT_TILT_POSITION)
):
# Tilt position
if state.attributes.get(ATTR_CURRENT_TILT_POSITION) == 100:
service_tilting = SERVICE_OPEN_COVER_TILT
elif state.attributes.get(ATTR_CURRENT_TILT_POSITION) == 0:
service_tilting = SERVICE_CLOSE_COVER_TILT
else:
service_tilting = SERVICE_SET_COVER_TILT_POSITION
service_data_tilting[ATTR_TILT_POSITION] = state.attributes[
ATTR_CURRENT_TILT_POSITION
]
await hass.services.async_call(
DOMAIN,
service_tilting,
service_data_tilting,
context=context,
blocking=True,
) | [
"async",
"def",
"_async_reproduce_state",
"(",
"hass",
":",
"HomeAssistantType",
",",
"state",
":",
"State",
",",
"*",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
"=",
"None",
",",
"reproduce_options",
":",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
"=",
"None",
",",
")",
"->",
"None",
":",
"cur_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"state",
".",
"entity_id",
")",
"if",
"cur_state",
"is",
"None",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Unable to find entity %s\"",
",",
"state",
".",
"entity_id",
")",
"return",
"if",
"state",
".",
"state",
"not",
"in",
"VALID_STATES",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Invalid state specified for %s: %s\"",
",",
"state",
".",
"entity_id",
",",
"state",
".",
"state",
")",
"return",
"# Return if we are already at the right state.",
"if",
"(",
"cur_state",
".",
"state",
"==",
"state",
".",
"state",
"and",
"cur_state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_POSITION",
")",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_POSITION",
")",
"and",
"cur_state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_TILT_POSITION",
")",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_TILT_POSITION",
")",
")",
":",
"return",
"service_data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"state",
".",
"entity_id",
"}",
"service_data_tilting",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"state",
".",
"entity_id",
"}",
"if",
"not",
"(",
"cur_state",
".",
"state",
"==",
"state",
".",
"state",
"and",
"cur_state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_POSITION",
")",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_POSITION",
")",
")",
":",
"# Open/Close",
"if",
"state",
".",
"state",
"in",
"[",
"STATE_CLOSED",
",",
"STATE_CLOSING",
"]",
":",
"service",
"=",
"SERVICE_CLOSE_COVER",
"elif",
"state",
".",
"state",
"in",
"[",
"STATE_OPEN",
",",
"STATE_OPENING",
"]",
":",
"if",
"(",
"ATTR_CURRENT_POSITION",
"in",
"cur_state",
".",
"attributes",
"and",
"ATTR_CURRENT_POSITION",
"in",
"state",
".",
"attributes",
")",
":",
"service",
"=",
"SERVICE_SET_COVER_POSITION",
"service_data",
"[",
"ATTR_POSITION",
"]",
"=",
"state",
".",
"attributes",
"[",
"ATTR_CURRENT_POSITION",
"]",
"else",
":",
"service",
"=",
"SERVICE_OPEN_COVER",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"service",
",",
"service_data",
",",
"context",
"=",
"context",
",",
"blocking",
"=",
"True",
")",
"if",
"(",
"ATTR_CURRENT_TILT_POSITION",
"in",
"state",
".",
"attributes",
"and",
"ATTR_CURRENT_TILT_POSITION",
"in",
"cur_state",
".",
"attributes",
"and",
"cur_state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_TILT_POSITION",
")",
"!=",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_TILT_POSITION",
")",
")",
":",
"# Tilt position",
"if",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_TILT_POSITION",
")",
"==",
"100",
":",
"service_tilting",
"=",
"SERVICE_OPEN_COVER_TILT",
"elif",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CURRENT_TILT_POSITION",
")",
"==",
"0",
":",
"service_tilting",
"=",
"SERVICE_CLOSE_COVER_TILT",
"else",
":",
"service_tilting",
"=",
"SERVICE_SET_COVER_TILT_POSITION",
"service_data_tilting",
"[",
"ATTR_TILT_POSITION",
"]",
"=",
"state",
".",
"attributes",
"[",
"ATTR_CURRENT_TILT_POSITION",
"]",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"service_tilting",
",",
"service_data_tilting",
",",
"context",
"=",
"context",
",",
"blocking",
"=",
"True",
",",
")"
] | [
34,
0
] | [
112,
9
] | python | en | ['en', 'en', 'en'] | True |
async_reproduce_states | (
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) | Reproduce Cover states. | Reproduce Cover states. | async def async_reproduce_states(
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce Cover states."""
# Reproduce states in parallel.
await asyncio.gather(
*(
_async_reproduce_state(
hass, state, context=context, reproduce_options=reproduce_options
)
for state in states
)
) | [
"async",
"def",
"async_reproduce_states",
"(",
"hass",
":",
"HomeAssistantType",
",",
"states",
":",
"Iterable",
"[",
"State",
"]",
",",
"*",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
"=",
"None",
",",
"reproduce_options",
":",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
"=",
"None",
",",
")",
"->",
"None",
":",
"# Reproduce states in parallel.",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"(",
"_async_reproduce_state",
"(",
"hass",
",",
"state",
",",
"context",
"=",
"context",
",",
"reproduce_options",
"=",
"reproduce_options",
")",
"for",
"state",
"in",
"states",
")",
")"
] | [
115,
0
] | [
131,
5
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, config) | Set up the ComfoConnect bridge. | Set up the ComfoConnect bridge. | def setup(hass, config):
"""Set up the ComfoConnect bridge."""
conf = config[DOMAIN]
host = conf[CONF_HOST]
name = conf[CONF_NAME]
token = conf[CONF_TOKEN]
user_agent = conf[CONF_USER_AGENT]
pin = conf[CONF_PIN]
# Run discovery on the configured ip
bridges = Bridge.discover(host)
if not bridges:
_LOGGER.error("Could not connect to ComfoConnect bridge on %s", host)
return False
bridge = bridges[0]
_LOGGER.info("Bridge found: %s (%s)", bridge.uuid.hex(), bridge.host)
# Setup ComfoConnect Bridge
ccb = ComfoConnectBridge(hass, bridge, name, token, user_agent, pin)
hass.data[DOMAIN] = ccb
# Start connection with bridge
ccb.connect()
# Schedule disconnect on shutdown
def _shutdown(_event):
ccb.disconnect()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown)
# Load platforms
discovery.load_platform(hass, "fan", DOMAIN, {}, config)
return True | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"conf",
"=",
"config",
"[",
"DOMAIN",
"]",
"host",
"=",
"conf",
"[",
"CONF_HOST",
"]",
"name",
"=",
"conf",
"[",
"CONF_NAME",
"]",
"token",
"=",
"conf",
"[",
"CONF_TOKEN",
"]",
"user_agent",
"=",
"conf",
"[",
"CONF_USER_AGENT",
"]",
"pin",
"=",
"conf",
"[",
"CONF_PIN",
"]",
"# Run discovery on the configured ip",
"bridges",
"=",
"Bridge",
".",
"discover",
"(",
"host",
")",
"if",
"not",
"bridges",
":",
"_LOGGER",
".",
"error",
"(",
"\"Could not connect to ComfoConnect bridge on %s\"",
",",
"host",
")",
"return",
"False",
"bridge",
"=",
"bridges",
"[",
"0",
"]",
"_LOGGER",
".",
"info",
"(",
"\"Bridge found: %s (%s)\"",
",",
"bridge",
".",
"uuid",
".",
"hex",
"(",
")",
",",
"bridge",
".",
"host",
")",
"# Setup ComfoConnect Bridge",
"ccb",
"=",
"ComfoConnectBridge",
"(",
"hass",
",",
"bridge",
",",
"name",
",",
"token",
",",
"user_agent",
",",
"pin",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"ccb",
"# Start connection with bridge",
"ccb",
".",
"connect",
"(",
")",
"# Schedule disconnect on shutdown",
"def",
"_shutdown",
"(",
"_event",
")",
":",
"ccb",
".",
"disconnect",
"(",
")",
"hass",
".",
"bus",
".",
"listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"_shutdown",
")",
"# Load platforms",
"discovery",
".",
"load_platform",
"(",
"hass",
",",
"\"fan\"",
",",
"DOMAIN",
",",
"{",
"}",
",",
"config",
")",
"return",
"True"
] | [
50,
0
] | [
84,
15
] | python | en | ['en', 'fr', 'en'] | True |
ComfoConnectBridge.__init__ | (self, hass, bridge, name, token, friendly_name, pin) | Initialize the ComfoConnect bridge. | Initialize the ComfoConnect bridge. | def __init__(self, hass, bridge, name, token, friendly_name, pin):
"""Initialize the ComfoConnect bridge."""
self.data = {}
self.name = name
self.hass = hass
self.unique_id = bridge.uuid.hex()
self.comfoconnect = ComfoConnect(
bridge=bridge,
local_uuid=bytes.fromhex(token),
local_devicename=friendly_name,
pin=pin,
)
self.comfoconnect.callback_sensor = self.sensor_callback | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"bridge",
",",
"name",
",",
"token",
",",
"friendly_name",
",",
"pin",
")",
":",
"self",
".",
"data",
"=",
"{",
"}",
"self",
".",
"name",
"=",
"name",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"unique_id",
"=",
"bridge",
".",
"uuid",
".",
"hex",
"(",
")",
"self",
".",
"comfoconnect",
"=",
"ComfoConnect",
"(",
"bridge",
"=",
"bridge",
",",
"local_uuid",
"=",
"bytes",
".",
"fromhex",
"(",
"token",
")",
",",
"local_devicename",
"=",
"friendly_name",
",",
"pin",
"=",
"pin",
",",
")",
"self",
".",
"comfoconnect",
".",
"callback_sensor",
"=",
"self",
".",
"sensor_callback"
] | [
90,
4
] | [
103,
64
] | python | en | ['en', 'fr', 'en'] | True |
ComfoConnectBridge.connect | (self) | Connect with the bridge. | Connect with the bridge. | def connect(self):
"""Connect with the bridge."""
_LOGGER.debug("Connecting with bridge")
self.comfoconnect.connect(True) | [
"def",
"connect",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Connecting with bridge\"",
")",
"self",
".",
"comfoconnect",
".",
"connect",
"(",
"True",
")"
] | [
105,
4
] | [
108,
39
] | python | en | ['en', 'en', 'en'] | True |
ComfoConnectBridge.disconnect | (self) | Disconnect from the bridge. | Disconnect from the bridge. | def disconnect(self):
"""Disconnect from the bridge."""
_LOGGER.debug("Disconnecting from bridge")
self.comfoconnect.disconnect() | [
"def",
"disconnect",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Disconnecting from bridge\"",
")",
"self",
".",
"comfoconnect",
".",
"disconnect",
"(",
")"
] | [
110,
4
] | [
113,
38
] | python | en | ['en', 'en', 'en'] | True |
ComfoConnectBridge.sensor_callback | (self, var, value) | Notify listeners that we have received an update. | Notify listeners that we have received an update. | def sensor_callback(self, var, value):
"""Notify listeners that we have received an update."""
_LOGGER.debug("Received update for %s: %s", var, value)
dispatcher_send(
self.hass, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED.format(var), value
) | [
"def",
"sensor_callback",
"(",
"self",
",",
"var",
",",
"value",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Received update for %s: %s\"",
",",
"var",
",",
"value",
")",
"dispatcher_send",
"(",
"self",
".",
"hass",
",",
"SIGNAL_COMFOCONNECT_UPDATE_RECEIVED",
".",
"format",
"(",
"var",
")",
",",
"value",
")"
] | [
115,
4
] | [
120,
9
] | python | en | ['en', 'en', 'en'] | True |
CloudClient.__init__ | (
self,
hass: HomeAssistantType,
prefs: CloudPreferences,
websession: aiohttp.ClientSession,
alexa_user_config: Dict[str, Any],
google_user_config: Dict[str, Any],
) | Initialize client interface to Cloud. | Initialize client interface to Cloud. | def __init__(
self,
hass: HomeAssistantType,
prefs: CloudPreferences,
websession: aiohttp.ClientSession,
alexa_user_config: Dict[str, Any],
google_user_config: Dict[str, Any],
):
"""Initialize client interface to Cloud."""
self._hass = hass
self._prefs = prefs
self._websession = websession
self.google_user_config = google_user_config
self.alexa_user_config = alexa_user_config
self._alexa_config = None
self._google_config = None | [
"def",
"__init__",
"(",
"self",
",",
"hass",
":",
"HomeAssistantType",
",",
"prefs",
":",
"CloudPreferences",
",",
"websession",
":",
"aiohttp",
".",
"ClientSession",
",",
"alexa_user_config",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
",",
"google_user_config",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
",",
")",
":",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"_prefs",
"=",
"prefs",
"self",
".",
"_websession",
"=",
"websession",
"self",
".",
"google_user_config",
"=",
"google_user_config",
"self",
".",
"alexa_user_config",
"=",
"alexa_user_config",
"self",
".",
"_alexa_config",
"=",
"None",
"self",
".",
"_google_config",
"=",
"None"
] | [
29,
4
] | [
44,
34
] | python | en | ['en', 'en', 'en'] | True |
CloudClient.base_path | (self) | Return path to base dir. | Return path to base dir. | def base_path(self) -> Path:
"""Return path to base dir."""
return Path(self._hass.config.config_dir) | [
"def",
"base_path",
"(",
"self",
")",
"->",
"Path",
":",
"return",
"Path",
"(",
"self",
".",
"_hass",
".",
"config",
".",
"config_dir",
")"
] | [
47,
4
] | [
49,
49
] | python | en | ['en', 'gd', 'en'] | True |
CloudClient.prefs | (self) | Return Cloud preferences. | Return Cloud preferences. | def prefs(self) -> CloudPreferences:
"""Return Cloud preferences."""
return self._prefs | [
"def",
"prefs",
"(",
"self",
")",
"->",
"CloudPreferences",
":",
"return",
"self",
".",
"_prefs"
] | [
52,
4
] | [
54,
26
] | python | en | ['nl', 'fr', 'en'] | False |
CloudClient.loop | (self) | Return client loop. | Return client loop. | def loop(self) -> asyncio.BaseEventLoop:
"""Return client loop."""
return self._hass.loop | [
"def",
"loop",
"(",
"self",
")",
"->",
"asyncio",
".",
"BaseEventLoop",
":",
"return",
"self",
".",
"_hass",
".",
"loop"
] | [
57,
4
] | [
59,
30
] | python | af | ['fr', 'af', 'en'] | False |
CloudClient.websession | (self) | Return client session for aiohttp. | Return client session for aiohttp. | def websession(self) -> aiohttp.ClientSession:
"""Return client session for aiohttp."""
return self._websession | [
"def",
"websession",
"(",
"self",
")",
"->",
"aiohttp",
".",
"ClientSession",
":",
"return",
"self",
".",
"_websession"
] | [
62,
4
] | [
64,
31
] | python | en | ['en', 'en', 'en'] | True |
CloudClient.aiohttp_runner | (self) | Return client webinterface aiohttp application. | Return client webinterface aiohttp application. | def aiohttp_runner(self) -> aiohttp.web.AppRunner:
"""Return client webinterface aiohttp application."""
return self._hass.http.runner | [
"def",
"aiohttp_runner",
"(",
"self",
")",
"->",
"aiohttp",
".",
"web",
".",
"AppRunner",
":",
"return",
"self",
".",
"_hass",
".",
"http",
".",
"runner"
] | [
67,
4
] | [
69,
37
] | python | en | ['en', 'lb', 'en'] | True |
CloudClient.cloudhooks | (self) | Return list of cloudhooks. | Return list of cloudhooks. | def cloudhooks(self) -> Dict[str, Dict[str, str]]:
"""Return list of cloudhooks."""
return self._prefs.cloudhooks | [
"def",
"cloudhooks",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Dict",
"[",
"str",
",",
"str",
"]",
"]",
":",
"return",
"self",
".",
"_prefs",
".",
"cloudhooks"
] | [
72,
4
] | [
74,
37
] | python | en | ['en', 'et', 'en'] | True |
CloudClient.remote_autostart | (self) | Return true if we want start a remote connection. | Return true if we want start a remote connection. | def remote_autostart(self) -> bool:
"""Return true if we want start a remote connection."""
return self._prefs.remote_enabled | [
"def",
"remote_autostart",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_prefs",
".",
"remote_enabled"
] | [
77,
4
] | [
79,
41
] | python | en | ['en', 'en', 'en'] | True |
CloudClient.alexa_config | (self) | Return Alexa config. | Return Alexa config. | def alexa_config(self) -> alexa_config.AlexaConfig:
"""Return Alexa config."""
if self._alexa_config is None:
assert self.cloud is not None
self._alexa_config = alexa_config.AlexaConfig(
self._hass, self.alexa_user_config, self._prefs, self.cloud
)
return self._alexa_config | [
"def",
"alexa_config",
"(",
"self",
")",
"->",
"alexa_config",
".",
"AlexaConfig",
":",
"if",
"self",
".",
"_alexa_config",
"is",
"None",
":",
"assert",
"self",
".",
"cloud",
"is",
"not",
"None",
"self",
".",
"_alexa_config",
"=",
"alexa_config",
".",
"AlexaConfig",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"alexa_user_config",
",",
"self",
".",
"_prefs",
",",
"self",
".",
"cloud",
")",
"return",
"self",
".",
"_alexa_config"
] | [
82,
4
] | [
90,
33
] | python | ca | ['ro', 'ca', 'en'] | False |
CloudClient.get_google_config | (self) | Return Google config. | Return Google config. | async def get_google_config(self) -> google_config.CloudGoogleConfig:
"""Return Google config."""
if not self._google_config:
assert self.cloud is not None
cloud_user = await self._prefs.get_cloud_user()
self._google_config = google_config.CloudGoogleConfig(
self._hass, self.google_user_config, cloud_user, self._prefs, self.cloud
)
await self._google_config.async_initialize()
return self._google_config | [
"async",
"def",
"get_google_config",
"(",
"self",
")",
"->",
"google_config",
".",
"CloudGoogleConfig",
":",
"if",
"not",
"self",
".",
"_google_config",
":",
"assert",
"self",
".",
"cloud",
"is",
"not",
"None",
"cloud_user",
"=",
"await",
"self",
".",
"_prefs",
".",
"get_cloud_user",
"(",
")",
"self",
".",
"_google_config",
"=",
"google_config",
".",
"CloudGoogleConfig",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"google_user_config",
",",
"cloud_user",
",",
"self",
".",
"_prefs",
",",
"self",
".",
"cloud",
")",
"await",
"self",
".",
"_google_config",
".",
"async_initialize",
"(",
")",
"return",
"self",
".",
"_google_config"
] | [
92,
4
] | [
104,
34
] | python | en | ['en', 'da', 'en'] | True |
CloudClient.logged_in | (self) | When user logs in. | When user logs in. | async def logged_in(self) -> None:
"""When user logs in."""
await self.prefs.async_set_username(self.cloud.username)
async def enable_alexa(_):
"""Enable Alexa."""
try:
await self.alexa_config.async_enable_proactive_mode()
except aiohttp.ClientError as err: # If no internet available yet
if self._hass.is_running:
logging.getLogger(__package__).warning(
"Unable to activate Alexa Report State: %s. Retrying in 30 seconds",
err,
)
async_call_later(self._hass, 30, enable_alexa)
except alexa_errors.NoTokenAvailable:
pass
async def enable_google(_):
"""Enable Google."""
gconf = await self.get_google_config()
gconf.async_enable_local_sdk()
if gconf.should_report_state:
gconf.async_enable_report_state()
tasks = []
if self.alexa_config.enabled and self.alexa_config.should_report_state:
tasks.append(enable_alexa)
if self._prefs.google_enabled:
tasks.append(enable_google)
if tasks:
await asyncio.gather(*[task(None) for task in tasks]) | [
"async",
"def",
"logged_in",
"(",
"self",
")",
"->",
"None",
":",
"await",
"self",
".",
"prefs",
".",
"async_set_username",
"(",
"self",
".",
"cloud",
".",
"username",
")",
"async",
"def",
"enable_alexa",
"(",
"_",
")",
":",
"\"\"\"Enable Alexa.\"\"\"",
"try",
":",
"await",
"self",
".",
"alexa_config",
".",
"async_enable_proactive_mode",
"(",
")",
"except",
"aiohttp",
".",
"ClientError",
"as",
"err",
":",
"# If no internet available yet",
"if",
"self",
".",
"_hass",
".",
"is_running",
":",
"logging",
".",
"getLogger",
"(",
"__package__",
")",
".",
"warning",
"(",
"\"Unable to activate Alexa Report State: %s. Retrying in 30 seconds\"",
",",
"err",
",",
")",
"async_call_later",
"(",
"self",
".",
"_hass",
",",
"30",
",",
"enable_alexa",
")",
"except",
"alexa_errors",
".",
"NoTokenAvailable",
":",
"pass",
"async",
"def",
"enable_google",
"(",
"_",
")",
":",
"\"\"\"Enable Google.\"\"\"",
"gconf",
"=",
"await",
"self",
".",
"get_google_config",
"(",
")",
"gconf",
".",
"async_enable_local_sdk",
"(",
")",
"if",
"gconf",
".",
"should_report_state",
":",
"gconf",
".",
"async_enable_report_state",
"(",
")",
"tasks",
"=",
"[",
"]",
"if",
"self",
".",
"alexa_config",
".",
"enabled",
"and",
"self",
".",
"alexa_config",
".",
"should_report_state",
":",
"tasks",
".",
"append",
"(",
"enable_alexa",
")",
"if",
"self",
".",
"_prefs",
".",
"google_enabled",
":",
"tasks",
".",
"append",
"(",
"enable_google",
")",
"if",
"tasks",
":",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"task",
"(",
"None",
")",
"for",
"task",
"in",
"tasks",
"]",
")"
] | [
106,
4
] | [
142,
65
] | python | en | ['en', 'fy', 'en'] | True |
CloudClient.cleanups | (self) | Cleanup some stuff after logout. | Cleanup some stuff after logout. | async def cleanups(self) -> None:
"""Cleanup some stuff after logout."""
await self.prefs.async_set_username(None)
self._google_config = None | [
"async",
"def",
"cleanups",
"(",
"self",
")",
"->",
"None",
":",
"await",
"self",
".",
"prefs",
".",
"async_set_username",
"(",
"None",
")",
"self",
".",
"_google_config",
"=",
"None"
] | [
144,
4
] | [
148,
34
] | python | en | ['en', 'en', 'en'] | True |
CloudClient.user_message | (self, identifier: str, title: str, message: str) | Create a message for user to UI. | Create a message for user to UI. | def user_message(self, identifier: str, title: str, message: str) -> None:
"""Create a message for user to UI."""
self._hass.components.persistent_notification.async_create(
message, title, identifier
) | [
"def",
"user_message",
"(",
"self",
",",
"identifier",
":",
"str",
",",
"title",
":",
"str",
",",
"message",
":",
"str",
")",
"->",
"None",
":",
"self",
".",
"_hass",
".",
"components",
".",
"persistent_notification",
".",
"async_create",
"(",
"message",
",",
"title",
",",
"identifier",
")"
] | [
151,
4
] | [
155,
9
] | python | en | ['en', 'en', 'en'] | True |
CloudClient.dispatcher_message | (self, identifier: str, data: Any = None) | Match cloud notification to dispatcher. | Match cloud notification to dispatcher. | def dispatcher_message(self, identifier: str, data: Any = None) -> None:
"""Match cloud notification to dispatcher."""
if identifier.startswith("remote_"):
async_dispatcher_send(self._hass, DISPATCHER_REMOTE_UPDATE, data) | [
"def",
"dispatcher_message",
"(",
"self",
",",
"identifier",
":",
"str",
",",
"data",
":",
"Any",
"=",
"None",
")",
"->",
"None",
":",
"if",
"identifier",
".",
"startswith",
"(",
"\"remote_\"",
")",
":",
"async_dispatcher_send",
"(",
"self",
".",
"_hass",
",",
"DISPATCHER_REMOTE_UPDATE",
",",
"data",
")"
] | [
158,
4
] | [
161,
77
] | python | en | ['en', 'lb', 'en'] | True |
CloudClient.async_alexa_message | (self, payload: Dict[Any, Any]) | Process cloud alexa message to client. | Process cloud alexa message to client. | async def async_alexa_message(self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
"""Process cloud alexa message to client."""
cloud_user = await self._prefs.get_cloud_user()
return await alexa_sh.async_handle_message(
self._hass,
self.alexa_config,
payload,
context=Context(user_id=cloud_user),
enabled=self._prefs.alexa_enabled,
) | [
"async",
"def",
"async_alexa_message",
"(",
"self",
",",
"payload",
":",
"Dict",
"[",
"Any",
",",
"Any",
"]",
")",
"->",
"Dict",
"[",
"Any",
",",
"Any",
"]",
":",
"cloud_user",
"=",
"await",
"self",
".",
"_prefs",
".",
"get_cloud_user",
"(",
")",
"return",
"await",
"alexa_sh",
".",
"async_handle_message",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"alexa_config",
",",
"payload",
",",
"context",
"=",
"Context",
"(",
"user_id",
"=",
"cloud_user",
")",
",",
"enabled",
"=",
"self",
".",
"_prefs",
".",
"alexa_enabled",
",",
")"
] | [
163,
4
] | [
172,
9
] | python | en | ['en', 'en', 'en'] | True |
CloudClient.async_google_message | (self, payload: Dict[Any, Any]) | Process cloud google message to client. | Process cloud google message to client. | async def async_google_message(self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
"""Process cloud google message to client."""
if not self._prefs.google_enabled:
return ga.turned_off_response(payload)
gconf = await self.get_google_config()
return await ga.async_handle_message(
self._hass, gconf, gconf.cloud_user, payload, gc.SOURCE_CLOUD
) | [
"async",
"def",
"async_google_message",
"(",
"self",
",",
"payload",
":",
"Dict",
"[",
"Any",
",",
"Any",
"]",
")",
"->",
"Dict",
"[",
"Any",
",",
"Any",
"]",
":",
"if",
"not",
"self",
".",
"_prefs",
".",
"google_enabled",
":",
"return",
"ga",
".",
"turned_off_response",
"(",
"payload",
")",
"gconf",
"=",
"await",
"self",
".",
"get_google_config",
"(",
")",
"return",
"await",
"ga",
".",
"async_handle_message",
"(",
"self",
".",
"_hass",
",",
"gconf",
",",
"gconf",
".",
"cloud_user",
",",
"payload",
",",
"gc",
".",
"SOURCE_CLOUD",
")"
] | [
174,
4
] | [
183,
9
] | python | en | ['en', 'fr', 'en'] | True |
CloudClient.async_webhook_message | (self, payload: Dict[Any, Any]) | Process cloud webhook message to client. | Process cloud webhook message to client. | async def async_webhook_message(self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
"""Process cloud webhook message to client."""
cloudhook_id = payload["cloudhook_id"]
found = None
for cloudhook in self._prefs.cloudhooks.values():
if cloudhook["cloudhook_id"] == cloudhook_id:
found = cloudhook
break
if found is None:
return {"status": HTTP_OK}
request = MockRequest(
content=payload["body"].encode("utf-8"),
headers=payload["headers"],
method=payload["method"],
query_string=payload["query"],
mock_source=DOMAIN,
)
response = await self._hass.components.webhook.async_handle_webhook(
found["webhook_id"], request
)
response_dict = utils.aiohttp_serialize_response(response)
body = response_dict.get("body")
return {
"body": body,
"status": response_dict["status"],
"headers": {"Content-Type": response.content_type},
} | [
"async",
"def",
"async_webhook_message",
"(",
"self",
",",
"payload",
":",
"Dict",
"[",
"Any",
",",
"Any",
"]",
")",
"->",
"Dict",
"[",
"Any",
",",
"Any",
"]",
":",
"cloudhook_id",
"=",
"payload",
"[",
"\"cloudhook_id\"",
"]",
"found",
"=",
"None",
"for",
"cloudhook",
"in",
"self",
".",
"_prefs",
".",
"cloudhooks",
".",
"values",
"(",
")",
":",
"if",
"cloudhook",
"[",
"\"cloudhook_id\"",
"]",
"==",
"cloudhook_id",
":",
"found",
"=",
"cloudhook",
"break",
"if",
"found",
"is",
"None",
":",
"return",
"{",
"\"status\"",
":",
"HTTP_OK",
"}",
"request",
"=",
"MockRequest",
"(",
"content",
"=",
"payload",
"[",
"\"body\"",
"]",
".",
"encode",
"(",
"\"utf-8\"",
")",
",",
"headers",
"=",
"payload",
"[",
"\"headers\"",
"]",
",",
"method",
"=",
"payload",
"[",
"\"method\"",
"]",
",",
"query_string",
"=",
"payload",
"[",
"\"query\"",
"]",
",",
"mock_source",
"=",
"DOMAIN",
",",
")",
"response",
"=",
"await",
"self",
".",
"_hass",
".",
"components",
".",
"webhook",
".",
"async_handle_webhook",
"(",
"found",
"[",
"\"webhook_id\"",
"]",
",",
"request",
")",
"response_dict",
"=",
"utils",
".",
"aiohttp_serialize_response",
"(",
"response",
")",
"body",
"=",
"response_dict",
".",
"get",
"(",
"\"body\"",
")",
"return",
"{",
"\"body\"",
":",
"body",
",",
"\"status\"",
":",
"response_dict",
"[",
"\"status\"",
"]",
",",
"\"headers\"",
":",
"{",
"\"Content-Type\"",
":",
"response",
".",
"content_type",
"}",
",",
"}"
] | [
185,
4
] | [
217,
9
] | python | en | ['en', 'en', 'en'] | True |
CloudClient.async_cloudhooks_update | (self, data: Dict[str, Dict[str, str]]) | Update local list of cloudhooks. | Update local list of cloudhooks. | async def async_cloudhooks_update(self, data: Dict[str, Dict[str, str]]) -> None:
"""Update local list of cloudhooks."""
await self._prefs.async_update(cloudhooks=data) | [
"async",
"def",
"async_cloudhooks_update",
"(",
"self",
",",
"data",
":",
"Dict",
"[",
"str",
",",
"Dict",
"[",
"str",
",",
"str",
"]",
"]",
")",
"->",
"None",
":",
"await",
"self",
".",
"_prefs",
".",
"async_update",
"(",
"cloudhooks",
"=",
"data",
")"
] | [
219,
4
] | [
221,
55
] | python | en | ['en', 'en', 'en'] | True |
zigpy_app_controller | () | Zigpy ApplicationController fixture. | Zigpy ApplicationController fixture. | def zigpy_app_controller():
"""Zigpy ApplicationController fixture."""
app = MagicMock(spec_set=ControllerApplication)
app.startup = AsyncMock()
app.shutdown = AsyncMock()
groups = zigpy.group.Groups(app)
groups.add_group(FIXTURE_GRP_ID, FIXTURE_GRP_NAME, suppress_event=True)
app.configure_mock(groups=groups)
type(app).ieee = PropertyMock()
app.ieee.return_value = zigpy.types.EUI64.convert("00:15:8d:00:02:32:4f:32")
type(app).nwk = PropertyMock(return_value=zigpy.types.NWK(0x0000))
type(app).devices = PropertyMock(return_value={})
return app | [
"def",
"zigpy_app_controller",
"(",
")",
":",
"app",
"=",
"MagicMock",
"(",
"spec_set",
"=",
"ControllerApplication",
")",
"app",
".",
"startup",
"=",
"AsyncMock",
"(",
")",
"app",
".",
"shutdown",
"=",
"AsyncMock",
"(",
")",
"groups",
"=",
"zigpy",
".",
"group",
".",
"Groups",
"(",
"app",
")",
"groups",
".",
"add_group",
"(",
"FIXTURE_GRP_ID",
",",
"FIXTURE_GRP_NAME",
",",
"suppress_event",
"=",
"True",
")",
"app",
".",
"configure_mock",
"(",
"groups",
"=",
"groups",
")",
"type",
"(",
"app",
")",
".",
"ieee",
"=",
"PropertyMock",
"(",
")",
"app",
".",
"ieee",
".",
"return_value",
"=",
"zigpy",
".",
"types",
".",
"EUI64",
".",
"convert",
"(",
"\"00:15:8d:00:02:32:4f:32\"",
")",
"type",
"(",
"app",
")",
".",
"nwk",
"=",
"PropertyMock",
"(",
"return_value",
"=",
"zigpy",
".",
"types",
".",
"NWK",
"(",
"0x0000",
")",
")",
"type",
"(",
"app",
")",
".",
"devices",
"=",
"PropertyMock",
"(",
"return_value",
"=",
"{",
"}",
")",
"return",
"app"
] | [
24,
0
] | [
36,
14
] | python | de | ['de', 'nl', 'en'] | False |
config_entry_fixture | (hass) | Fixture representing a config entry. | Fixture representing a config entry. | async def config_entry_fixture(hass):
"""Fixture representing a config entry."""
entry = MockConfigEntry(
version=2,
domain=zha_const.DOMAIN,
data={
zigpy.config.CONF_DEVICE: {zigpy.config.CONF_DEVICE_PATH: "/dev/ttyUSB0"},
zha_const.CONF_RADIO_TYPE: "ezsp",
},
)
entry.add_to_hass(hass)
return entry | [
"async",
"def",
"config_entry_fixture",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"version",
"=",
"2",
",",
"domain",
"=",
"zha_const",
".",
"DOMAIN",
",",
"data",
"=",
"{",
"zigpy",
".",
"config",
".",
"CONF_DEVICE",
":",
"{",
"zigpy",
".",
"config",
".",
"CONF_DEVICE_PATH",
":",
"\"/dev/ttyUSB0\"",
"}",
",",
"zha_const",
".",
"CONF_RADIO_TYPE",
":",
"\"ezsp\"",
",",
"}",
",",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"return",
"entry"
] | [
40,
0
] | [
51,
16
] | python | en | ['en', 'en', 'en'] | True |
setup_zha | (hass, config_entry, zigpy_app_controller) | Set up ZHA component. | Set up ZHA component. | def setup_zha(hass, config_entry, zigpy_app_controller):
"""Set up ZHA component."""
zha_config = {zha_const.CONF_ENABLE_QUIRKS: False}
p1 = patch(
"bellows.zigbee.application.ControllerApplication.new",
return_value=zigpy_app_controller,
)
async def _setup(config=None):
config = config or {}
with p1:
status = await async_setup_component(
hass, zha_const.DOMAIN, {zha_const.DOMAIN: {**zha_config, **config}}
)
assert status is True
await hass.async_block_till_done()
return _setup | [
"def",
"setup_zha",
"(",
"hass",
",",
"config_entry",
",",
"zigpy_app_controller",
")",
":",
"zha_config",
"=",
"{",
"zha_const",
".",
"CONF_ENABLE_QUIRKS",
":",
"False",
"}",
"p1",
"=",
"patch",
"(",
"\"bellows.zigbee.application.ControllerApplication.new\"",
",",
"return_value",
"=",
"zigpy_app_controller",
",",
")",
"async",
"def",
"_setup",
"(",
"config",
"=",
"None",
")",
":",
"config",
"=",
"config",
"or",
"{",
"}",
"with",
"p1",
":",
"status",
"=",
"await",
"async_setup_component",
"(",
"hass",
",",
"zha_const",
".",
"DOMAIN",
",",
"{",
"zha_const",
".",
"DOMAIN",
":",
"{",
"*",
"*",
"zha_config",
",",
"*",
"*",
"config",
"}",
"}",
")",
"assert",
"status",
"is",
"True",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"return",
"_setup"
] | [
55,
0
] | [
73,
17
] | python | en | ['en', 'fr', 'en'] | True |
channel | () | Channel mock factory fixture. | Channel mock factory fixture. | def channel():
"""Channel mock factory fixture."""
def channel(name: str, cluster_id: int, endpoint_id: int = 1):
ch = MagicMock()
ch.name = name
ch.generic_id = f"channel_0x{cluster_id:04x}"
ch.id = f"{endpoint_id}:0x{cluster_id:04x}"
ch.async_configure = AsyncMock()
ch.async_initialize = AsyncMock()
return ch
return channel | [
"def",
"channel",
"(",
")",
":",
"def",
"channel",
"(",
"name",
":",
"str",
",",
"cluster_id",
":",
"int",
",",
"endpoint_id",
":",
"int",
"=",
"1",
")",
":",
"ch",
"=",
"MagicMock",
"(",
")",
"ch",
".",
"name",
"=",
"name",
"ch",
".",
"generic_id",
"=",
"f\"channel_0x{cluster_id:04x}\"",
"ch",
".",
"id",
"=",
"f\"{endpoint_id}:0x{cluster_id:04x}\"",
"ch",
".",
"async_configure",
"=",
"AsyncMock",
"(",
")",
"ch",
".",
"async_initialize",
"=",
"AsyncMock",
"(",
")",
"return",
"ch",
"return",
"channel"
] | [
77,
0
] | [
89,
18
] | python | en | ['en', 'fy', 'en'] | True |
zigpy_device_mock | (zigpy_app_controller) | Make a fake device using the specified cluster classes. | Make a fake device using the specified cluster classes. | def zigpy_device_mock(zigpy_app_controller):
"""Make a fake device using the specified cluster classes."""
def _mock_dev(
endpoints,
ieee="00:0d:6f:00:0a:90:69:e7",
manufacturer="FakeManufacturer",
model="FakeModel",
node_descriptor=b"\x02@\x807\x10\x7fd\x00\x00*d\x00\x00",
nwk=0xB79C,
patch_cluster=True,
):
"""Make a fake device using the specified cluster classes."""
device = FakeDevice(
zigpy_app_controller, ieee, manufacturer, model, node_descriptor, nwk=nwk
)
for epid, ep in endpoints.items():
endpoint = FakeEndpoint(manufacturer, model, epid)
endpoint.device = device
device.endpoints[epid] = endpoint
endpoint.device_type = ep["device_type"]
profile_id = ep.get("profile_id")
if profile_id:
endpoint.profile_id = profile_id
for cluster_id in ep.get("in_clusters", []):
endpoint.add_input_cluster(cluster_id, _patch_cluster=patch_cluster)
for cluster_id in ep.get("out_clusters", []):
endpoint.add_output_cluster(cluster_id, _patch_cluster=patch_cluster)
return device
return _mock_dev | [
"def",
"zigpy_device_mock",
"(",
"zigpy_app_controller",
")",
":",
"def",
"_mock_dev",
"(",
"endpoints",
",",
"ieee",
"=",
"\"00:0d:6f:00:0a:90:69:e7\"",
",",
"manufacturer",
"=",
"\"FakeManufacturer\"",
",",
"model",
"=",
"\"FakeModel\"",
",",
"node_descriptor",
"=",
"b\"\\x02@\\x807\\x10\\x7fd\\x00\\x00*d\\x00\\x00\"",
",",
"nwk",
"=",
"0xB79C",
",",
"patch_cluster",
"=",
"True",
",",
")",
":",
"\"\"\"Make a fake device using the specified cluster classes.\"\"\"",
"device",
"=",
"FakeDevice",
"(",
"zigpy_app_controller",
",",
"ieee",
",",
"manufacturer",
",",
"model",
",",
"node_descriptor",
",",
"nwk",
"=",
"nwk",
")",
"for",
"epid",
",",
"ep",
"in",
"endpoints",
".",
"items",
"(",
")",
":",
"endpoint",
"=",
"FakeEndpoint",
"(",
"manufacturer",
",",
"model",
",",
"epid",
")",
"endpoint",
".",
"device",
"=",
"device",
"device",
".",
"endpoints",
"[",
"epid",
"]",
"=",
"endpoint",
"endpoint",
".",
"device_type",
"=",
"ep",
"[",
"\"device_type\"",
"]",
"profile_id",
"=",
"ep",
".",
"get",
"(",
"\"profile_id\"",
")",
"if",
"profile_id",
":",
"endpoint",
".",
"profile_id",
"=",
"profile_id",
"for",
"cluster_id",
"in",
"ep",
".",
"get",
"(",
"\"in_clusters\"",
",",
"[",
"]",
")",
":",
"endpoint",
".",
"add_input_cluster",
"(",
"cluster_id",
",",
"_patch_cluster",
"=",
"patch_cluster",
")",
"for",
"cluster_id",
"in",
"ep",
".",
"get",
"(",
"\"out_clusters\"",
",",
"[",
"]",
")",
":",
"endpoint",
".",
"add_output_cluster",
"(",
"cluster_id",
",",
"_patch_cluster",
"=",
"patch_cluster",
")",
"return",
"device",
"return",
"_mock_dev"
] | [
93,
0
] | [
126,
20
] | python | en | ['en', 'en', 'en'] | True |
zha_device_joined | (hass, setup_zha) | Return a newly joined ZHA device. | Return a newly joined ZHA device. | def zha_device_joined(hass, setup_zha):
"""Return a newly joined ZHA device."""
async def _zha_device(zigpy_dev):
await setup_zha()
zha_gateway = get_zha_gateway(hass)
await zha_gateway.async_device_initialized(zigpy_dev)
await hass.async_block_till_done()
return zha_gateway.get_device(zigpy_dev.ieee)
return _zha_device | [
"def",
"zha_device_joined",
"(",
"hass",
",",
"setup_zha",
")",
":",
"async",
"def",
"_zha_device",
"(",
"zigpy_dev",
")",
":",
"await",
"setup_zha",
"(",
")",
"zha_gateway",
"=",
"get_zha_gateway",
"(",
"hass",
")",
"await",
"zha_gateway",
".",
"async_device_initialized",
"(",
"zigpy_dev",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"return",
"zha_gateway",
".",
"get_device",
"(",
"zigpy_dev",
".",
"ieee",
")",
"return",
"_zha_device"
] | [
130,
0
] | [
140,
22
] | python | en | ['en', 'en', 'en'] | True |
zha_device_restored | (hass, zigpy_app_controller, setup_zha, hass_storage) | Return a restored ZHA device. | Return a restored ZHA device. | def zha_device_restored(hass, zigpy_app_controller, setup_zha, hass_storage):
"""Return a restored ZHA device."""
async def _zha_device(zigpy_dev, last_seen=None):
zigpy_app_controller.devices[zigpy_dev.ieee] = zigpy_dev
if last_seen is not None:
hass_storage[f"{DOMAIN}.storage"] = {
"key": f"{DOMAIN}.storage",
"version": 1,
"data": {
"devices": [
{
"ieee": str(zigpy_dev.ieee),
"last_seen": last_seen,
"name": f"{zigpy_dev.manufacturer} {zigpy_dev.model}",
}
],
},
}
await setup_zha()
zha_gateway = hass.data[zha_const.DATA_ZHA][zha_const.DATA_ZHA_GATEWAY]
return zha_gateway.get_device(zigpy_dev.ieee)
return _zha_device | [
"def",
"zha_device_restored",
"(",
"hass",
",",
"zigpy_app_controller",
",",
"setup_zha",
",",
"hass_storage",
")",
":",
"async",
"def",
"_zha_device",
"(",
"zigpy_dev",
",",
"last_seen",
"=",
"None",
")",
":",
"zigpy_app_controller",
".",
"devices",
"[",
"zigpy_dev",
".",
"ieee",
"]",
"=",
"zigpy_dev",
"if",
"last_seen",
"is",
"not",
"None",
":",
"hass_storage",
"[",
"f\"{DOMAIN}.storage\"",
"]",
"=",
"{",
"\"key\"",
":",
"f\"{DOMAIN}.storage\"",
",",
"\"version\"",
":",
"1",
",",
"\"data\"",
":",
"{",
"\"devices\"",
":",
"[",
"{",
"\"ieee\"",
":",
"str",
"(",
"zigpy_dev",
".",
"ieee",
")",
",",
"\"last_seen\"",
":",
"last_seen",
",",
"\"name\"",
":",
"f\"{zigpy_dev.manufacturer} {zigpy_dev.model}\"",
",",
"}",
"]",
",",
"}",
",",
"}",
"await",
"setup_zha",
"(",
")",
"zha_gateway",
"=",
"hass",
".",
"data",
"[",
"zha_const",
".",
"DATA_ZHA",
"]",
"[",
"zha_const",
".",
"DATA_ZHA_GATEWAY",
"]",
"return",
"zha_gateway",
".",
"get_device",
"(",
"zigpy_dev",
".",
"ieee",
")",
"return",
"_zha_device"
] | [
144,
0
] | [
169,
22
] | python | en | ['en', 'co', 'en'] | True |
zha_device_joined_restored | (request) | Join or restore ZHA device. | Join or restore ZHA device. | def zha_device_joined_restored(request):
"""Join or restore ZHA device."""
named_method = request.getfixturevalue(request.param)
named_method.name = request.param
return named_method | [
"def",
"zha_device_joined_restored",
"(",
"request",
")",
":",
"named_method",
"=",
"request",
".",
"getfixturevalue",
"(",
"request",
".",
"param",
")",
"named_method",
".",
"name",
"=",
"request",
".",
"param",
"return",
"named_method"
] | [
173,
0
] | [
177,
23
] | python | en | ['en', 'en', 'en'] | True |
zha_device_mock | (hass, zigpy_device_mock) | Return a zha Device factory. | Return a zha Device factory. | def zha_device_mock(hass, zigpy_device_mock):
"""Return a zha Device factory."""
def _zha_device(
endpoints=None,
ieee="00:11:22:33:44:55:66:77",
manufacturer="mock manufacturer",
model="mock model",
node_desc=b"\x02@\x807\x10\x7fd\x00\x00*d\x00\x00",
patch_cluster=True,
):
if endpoints is None:
endpoints = {
1: {
"in_clusters": [0, 1, 8, 768],
"out_clusters": [0x19],
"device_type": 0x0105,
},
2: {
"in_clusters": [0],
"out_clusters": [6, 8, 0x19, 768],
"device_type": 0x0810,
},
}
zigpy_device = zigpy_device_mock(
endpoints, ieee, manufacturer, model, node_desc, patch_cluster=patch_cluster
)
zha_device = zha_core_device.ZHADevice(hass, zigpy_device, MagicMock())
return zha_device
return _zha_device | [
"def",
"zha_device_mock",
"(",
"hass",
",",
"zigpy_device_mock",
")",
":",
"def",
"_zha_device",
"(",
"endpoints",
"=",
"None",
",",
"ieee",
"=",
"\"00:11:22:33:44:55:66:77\"",
",",
"manufacturer",
"=",
"\"mock manufacturer\"",
",",
"model",
"=",
"\"mock model\"",
",",
"node_desc",
"=",
"b\"\\x02@\\x807\\x10\\x7fd\\x00\\x00*d\\x00\\x00\"",
",",
"patch_cluster",
"=",
"True",
",",
")",
":",
"if",
"endpoints",
"is",
"None",
":",
"endpoints",
"=",
"{",
"1",
":",
"{",
"\"in_clusters\"",
":",
"[",
"0",
",",
"1",
",",
"8",
",",
"768",
"]",
",",
"\"out_clusters\"",
":",
"[",
"0x19",
"]",
",",
"\"device_type\"",
":",
"0x0105",
",",
"}",
",",
"2",
":",
"{",
"\"in_clusters\"",
":",
"[",
"0",
"]",
",",
"\"out_clusters\"",
":",
"[",
"6",
",",
"8",
",",
"0x19",
",",
"768",
"]",
",",
"\"device_type\"",
":",
"0x0810",
",",
"}",
",",
"}",
"zigpy_device",
"=",
"zigpy_device_mock",
"(",
"endpoints",
",",
"ieee",
",",
"manufacturer",
",",
"model",
",",
"node_desc",
",",
"patch_cluster",
"=",
"patch_cluster",
")",
"zha_device",
"=",
"zha_core_device",
".",
"ZHADevice",
"(",
"hass",
",",
"zigpy_device",
",",
"MagicMock",
"(",
")",
")",
"return",
"zha_device",
"return",
"_zha_device"
] | [
181,
0
] | [
211,
22
] | python | br | ['br', 'zh-Latn', 'en'] | False |
hass_disable_services | (hass) | Mock service register. | Mock service register. | def hass_disable_services(hass):
"""Mock service register."""
with patch.object(hass.services, "async_register"), patch.object(
hass.services, "has_service", return_value=True
):
yield hass | [
"def",
"hass_disable_services",
"(",
"hass",
")",
":",
"with",
"patch",
".",
"object",
"(",
"hass",
".",
"services",
",",
"\"async_register\"",
")",
",",
"patch",
".",
"object",
"(",
"hass",
".",
"services",
",",
"\"has_service\"",
",",
"return_value",
"=",
"True",
")",
":",
"yield",
"hass"
] | [
215,
0
] | [
220,
18
] | python | en | ['en', 'da', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Ombi sensor platform. | Set up the Ombi sensor platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Ombi sensor platform."""
if discovery_info is None:
return
sensors = []
ombi = hass.data[DOMAIN]["instance"]
for sensor in SENSOR_TYPES:
sensor_label = sensor
sensor_type = SENSOR_TYPES[sensor]["type"]
sensor_icon = SENSOR_TYPES[sensor]["icon"]
sensors.append(OmbiSensor(sensor_label, sensor_type, ombi, sensor_icon))
add_entities(sensors, True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"sensors",
"=",
"[",
"]",
"ombi",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"\"instance\"",
"]",
"for",
"sensor",
"in",
"SENSOR_TYPES",
":",
"sensor_label",
"=",
"sensor",
"sensor_type",
"=",
"SENSOR_TYPES",
"[",
"sensor",
"]",
"[",
"\"type\"",
"]",
"sensor_icon",
"=",
"SENSOR_TYPES",
"[",
"sensor",
"]",
"[",
"\"icon\"",
"]",
"sensors",
".",
"append",
"(",
"OmbiSensor",
"(",
"sensor_label",
",",
"sensor_type",
",",
"ombi",
",",
"sensor_icon",
")",
")",
"add_entities",
"(",
"sensors",
",",
"True",
")"
] | [
15,
0
] | [
30,
31
] | python | en | ['en', 'da', 'en'] | True |
OmbiSensor.__init__ | (self, label, sensor_type, ombi, icon) | Initialize the sensor. | Initialize the sensor. | def __init__(self, label, sensor_type, ombi, icon):
"""Initialize the sensor."""
self._state = None
self._label = label
self._type = sensor_type
self._ombi = ombi
self._icon = icon | [
"def",
"__init__",
"(",
"self",
",",
"label",
",",
"sensor_type",
",",
"ombi",
",",
"icon",
")",
":",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_label",
"=",
"label",
"self",
".",
"_type",
"=",
"sensor_type",
"self",
".",
"_ombi",
"=",
"ombi",
"self",
".",
"_icon",
"=",
"icon"
] | [
36,
4
] | [
42,
25
] | python | en | ['en', 'en', 'en'] | True |
OmbiSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"Ombi {self._type}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"Ombi {self._type}\""
] | [
45,
4
] | [
47,
35
] | python | en | ['en', 'mi', 'en'] | True |
OmbiSensor.icon | (self) | Return the icon to use in the frontend. | Return the icon to use in the frontend. | def icon(self):
"""Return the icon to use in the frontend."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
50,
4
] | [
52,
25
] | python | en | ['en', 'en', 'en'] | True |
OmbiSensor.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"
] | [
55,
4
] | [
57,
26
] | python | en | ['en', 'en', 'en'] | True |
OmbiSensor.update | (self) | Update the sensor. | Update the sensor. | def update(self):
"""Update the sensor."""
try:
if self._label == "movies":
self._state = self._ombi.movie_requests
elif self._label == "tv":
self._state = self._ombi.tv_requests
elif self._label == "music":
self._state = self._ombi.music_requests
elif self._label == "pending":
self._state = self._ombi.total_requests["pending"]
elif self._label == "approved":
self._state = self._ombi.total_requests["approved"]
elif self._label == "available":
self._state = self._ombi.total_requests["available"]
except OmbiError as err:
_LOGGER.warning("Unable to update Ombi sensor: %s", err)
self._state = None | [
"def",
"update",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"_label",
"==",
"\"movies\"",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_ombi",
".",
"movie_requests",
"elif",
"self",
".",
"_label",
"==",
"\"tv\"",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_ombi",
".",
"tv_requests",
"elif",
"self",
".",
"_label",
"==",
"\"music\"",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_ombi",
".",
"music_requests",
"elif",
"self",
".",
"_label",
"==",
"\"pending\"",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_ombi",
".",
"total_requests",
"[",
"\"pending\"",
"]",
"elif",
"self",
".",
"_label",
"==",
"\"approved\"",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_ombi",
".",
"total_requests",
"[",
"\"approved\"",
"]",
"elif",
"self",
".",
"_label",
"==",
"\"available\"",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_ombi",
".",
"total_requests",
"[",
"\"available\"",
"]",
"except",
"OmbiError",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Unable to update Ombi sensor: %s\"",
",",
"err",
")",
"self",
".",
"_state",
"=",
"None"
] | [
59,
4
] | [
76,
30
] | python | en | ['en', 'nl', 'en'] | True |
device_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass) | [
"def",
"device_reg",
"(",
"hass",
")",
":",
"return",
"mock_device_registry",
"(",
"hass",
")"
] | [
24,
0
] | [
26,
37
] | python | en | ['en', 'fy', 'en'] | True |
entity_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass) | [
"def",
"entity_reg",
"(",
"hass",
")",
":",
"return",
"mock_registry",
"(",
"hass",
")"
] | [
30,
0
] | [
32,
30
] | python | en | ['en', 'fy', 'en'] | True |
calls | (hass) | Track calls to a mock service. | Track calls to a mock service. | def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") | [
"def",
"calls",
"(",
"hass",
")",
":",
"return",
"async_mock_service",
"(",
"hass",
",",
"\"test\"",
",",
"\"automation\"",
")"
] | [
36,
0
] | [
38,
57
] | python | en | ['en', 'en', 'en'] | True |
test_get_conditions | (hass, device_reg, entity_reg) | Test we get the expected conditions from a light. | Test we get the expected conditions from a light. | async def test_get_conditions(hass, device_reg, entity_reg):
"""Test we get the expected conditions from a light."""
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [
{
"condition": "device",
"domain": DOMAIN,
"type": "is_off",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_5678",
},
{
"condition": "device",
"domain": DOMAIN,
"type": "is_on",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_5678",
},
]
conditions = await async_get_device_automations(hass, "condition", device_entry.id)
assert conditions == expected_conditions | [
"async",
"def",
"test_get_conditions",
"(",
"hass",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"DOMAIN",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"expected_conditions",
"=",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"is_off\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_5678\"",
",",
"}",
",",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"is_on\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_5678\"",
",",
"}",
",",
"]",
"conditions",
"=",
"await",
"async_get_device_automations",
"(",
"hass",
",",
"\"condition\"",
",",
"device_entry",
".",
"id",
")",
"assert",
"conditions",
"==",
"expected_conditions"
] | [
41,
0
] | [
67,
44
] | python | en | ['en', 'en', 'en'] | True |
test_get_condition_capabilities | (hass, device_reg, entity_reg) | Test we get the expected capabilities from a light condition. | Test we get the expected capabilities from a light condition. | async def test_get_condition_capabilities(hass, device_reg, entity_reg):
"""Test we get the expected capabilities from a light condition."""
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = {
"extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"}
]
}
conditions = await async_get_device_automations(hass, "condition", device_entry.id)
for condition in conditions:
capabilities = await async_get_device_automation_capabilities(
hass, "condition", condition
)
assert capabilities == expected_capabilities | [
"async",
"def",
"test_get_condition_capabilities",
"(",
"hass",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"DOMAIN",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"expected_capabilities",
"=",
"{",
"\"extra_fields\"",
":",
"[",
"{",
"\"name\"",
":",
"\"for\"",
",",
"\"optional\"",
":",
"True",
",",
"\"type\"",
":",
"\"positive_time_period_dict\"",
"}",
"]",
"}",
"conditions",
"=",
"await",
"async_get_device_automations",
"(",
"hass",
",",
"\"condition\"",
",",
"device_entry",
".",
"id",
")",
"for",
"condition",
"in",
"conditions",
":",
"capabilities",
"=",
"await",
"async_get_device_automation_capabilities",
"(",
"hass",
",",
"\"condition\"",
",",
"condition",
")",
"assert",
"capabilities",
"==",
"expected_capabilities"
] | [
70,
0
] | [
89,
52
] | python | en | ['en', 'en', 'en'] | True |
test_if_state | (hass, calls) | Test for turn_on and turn_off conditions. | Test for turn_on and turn_off conditions. | async def test_if_state(hass, calls):
"""Test for turn_on and turn_off conditions."""
platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {"platform": "event", "event_type": "test_event1"},
"condition": [
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": ent1.entity_id,
"type": "is_on",
}
],
"action": {
"service": "test.automation",
"data_template": {
"some": "is_on {{ trigger.%s }}"
% "}} - {{ trigger.".join(("platform", "event.event_type"))
},
},
},
{
"trigger": {"platform": "event", "event_type": "test_event2"},
"condition": [
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": ent1.entity_id,
"type": "is_off",
}
],
"action": {
"service": "test.automation",
"data_template": {
"some": "is_off {{ trigger.%s }}"
% "}} - {{ trigger.".join(("platform", "event.event_type"))
},
},
},
]
},
)
await hass.async_block_till_done()
assert hass.states.get(ent1.entity_id).state == STATE_ON
assert len(calls) == 0
hass.bus.async_fire("test_event1")
hass.bus.async_fire("test_event2")
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == "is_on event - test_event1"
hass.states.async_set(ent1.entity_id, STATE_OFF)
hass.bus.async_fire("test_event1")
hass.bus.async_fire("test_event2")
await hass.async_block_till_done()
assert len(calls) == 2
assert calls[1].data["some"] == "is_off event - test_event2" | [
"async",
"def",
"test_if_state",
"(",
"hass",
",",
"calls",
")",
":",
"platform",
"=",
"getattr",
"(",
"hass",
".",
"components",
",",
"f\"test.{DOMAIN}\"",
")",
"platform",
".",
"init",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"CONF_PLATFORM",
":",
"\"test\"",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"ent1",
",",
"ent2",
",",
"ent3",
"=",
"platform",
".",
"ENTITIES",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"[",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"condition\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"ent1",
".",
"entity_id",
",",
"\"type\"",
":",
"\"is_on\"",
",",
"}",
"]",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"is_on {{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"event.event_type\"",
")",
")",
"}",
",",
"}",
",",
"}",
",",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event2\"",
"}",
",",
"\"condition\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"ent1",
".",
"entity_id",
",",
"\"type\"",
":",
"\"is_off\"",
",",
"}",
"]",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"is_off {{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"event.event_type\"",
")",
")",
"}",
",",
"}",
",",
"}",
",",
"]",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"ent1",
".",
"entity_id",
")",
".",
"state",
"==",
"STATE_ON",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event2\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"is_on event - test_event1\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"ent1",
".",
"entity_id",
",",
"STATE_OFF",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event2\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"2",
"assert",
"calls",
"[",
"1",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"is_off event - test_event2\""
] | [
92,
0
] | [
163,
64
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_for_condition | (hass, calls) | Test for firing if condition is on with delay. | Test for firing if condition is on with delay. | async def test_if_fires_on_for_condition(hass, calls):
"""Test for firing if condition is on with delay."""
point1 = dt_util.utcnow()
point2 = point1 + timedelta(seconds=10)
point3 = point2 + timedelta(seconds=10)
platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES
with patch("homeassistant.core.dt_util.utcnow") as mock_utcnow:
mock_utcnow.return_value = point1
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {"platform": "event", "event_type": "test_event1"},
"condition": {
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": ent1.entity_id,
"type": "is_off",
"for": {"seconds": 5},
},
"action": {
"service": "test.automation",
"data_template": {
"some": "is_off {{ trigger.%s }}"
% "}} - {{ trigger.".join(
("platform", "event.event_type")
)
},
},
}
]
},
)
await hass.async_block_till_done()
assert hass.states.get(ent1.entity_id).state == STATE_ON
assert len(calls) == 0
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 0
# Time travel 10 secs into the future
mock_utcnow.return_value = point2
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 0
hass.states.async_set(ent1.entity_id, STATE_OFF)
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 0
# Time travel 20 secs into the future
mock_utcnow.return_value = point3
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == "is_off event - test_event1" | [
"async",
"def",
"test_if_fires_on_for_condition",
"(",
"hass",
",",
"calls",
")",
":",
"point1",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"point2",
"=",
"point1",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
"point3",
"=",
"point2",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
"platform",
"=",
"getattr",
"(",
"hass",
".",
"components",
",",
"f\"test.{DOMAIN}\"",
")",
"platform",
".",
"init",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"CONF_PLATFORM",
":",
"\"test\"",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"ent1",
",",
"ent2",
",",
"ent3",
"=",
"platform",
".",
"ENTITIES",
"with",
"patch",
"(",
"\"homeassistant.core.dt_util.utcnow\"",
")",
"as",
"mock_utcnow",
":",
"mock_utcnow",
".",
"return_value",
"=",
"point1",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"[",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"condition\"",
":",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"ent1",
".",
"entity_id",
",",
"\"type\"",
":",
"\"is_off\"",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"5",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"is_off {{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"event.event_type\"",
")",
")",
"}",
",",
"}",
",",
"}",
"]",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"ent1",
".",
"entity_id",
")",
".",
"state",
"==",
"STATE_ON",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"# Time travel 10 secs into the future",
"mock_utcnow",
".",
"return_value",
"=",
"point2",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"ent1",
".",
"entity_id",
",",
"STATE_OFF",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"# Time travel 20 secs into the future",
"mock_utcnow",
".",
"return_value",
"=",
"point3",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"is_off event - test_event1\""
] | [
166,
0
] | [
234,
68
] | python | en | ['en', 'en', 'en'] | True |
test_auth_setup | (hass) | Test auth setup for client registration. | Test auth setup for client registration. | async def test_auth_setup(hass):
"""Test auth setup for client registration."""
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
with patch.object(hmip_auth, "get_auth"):
assert await hmip_auth.async_setup() | [
"async",
"def",
"test_auth_setup",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"HMIPC_HAPID",
":",
"\"ABC123\"",
",",
"HMIPC_PIN",
":",
"\"123\"",
",",
"HMIPC_NAME",
":",
"\"hmip\"",
"}",
"hmip_auth",
"=",
"HomematicipAuth",
"(",
"hass",
",",
"config",
")",
"with",
"patch",
".",
"object",
"(",
"hmip_auth",
",",
"\"get_auth\"",
")",
":",
"assert",
"await",
"hmip_auth",
".",
"async_setup",
"(",
")"
] | [
26,
0
] | [
31,
44
] | python | en | ['en', 'fr', 'en'] | True |
test_auth_setup_connection_error | (hass) | Test auth setup connection error behaviour. | Test auth setup connection error behaviour. | async def test_auth_setup_connection_error(hass):
"""Test auth setup connection error behaviour."""
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
with patch.object(hmip_auth, "get_auth", side_effect=HmipcConnectionError):
assert not await hmip_auth.async_setup() | [
"async",
"def",
"test_auth_setup_connection_error",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"HMIPC_HAPID",
":",
"\"ABC123\"",
",",
"HMIPC_PIN",
":",
"\"123\"",
",",
"HMIPC_NAME",
":",
"\"hmip\"",
"}",
"hmip_auth",
"=",
"HomematicipAuth",
"(",
"hass",
",",
"config",
")",
"with",
"patch",
".",
"object",
"(",
"hmip_auth",
",",
"\"get_auth\"",
",",
"side_effect",
"=",
"HmipcConnectionError",
")",
":",
"assert",
"not",
"await",
"hmip_auth",
".",
"async_setup",
"(",
")"
] | [
34,
0
] | [
39,
48
] | python | en | ['en', 'fr', 'en'] | True |
test_auth_auth_check_and_register | (hass) | Test auth client registration. | Test auth client registration. | async def test_auth_auth_check_and_register(hass):
"""Test auth client registration."""
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
hmip_auth.auth = Mock(spec=AsyncAuth)
with patch.object(
hmip_auth.auth, "isRequestAcknowledged", return_value=True
), patch.object(
hmip_auth.auth, "requestAuthToken", return_value="ABC"
), patch.object(
hmip_auth.auth, "confirmAuthToken"
):
assert await hmip_auth.async_checkbutton()
assert await hmip_auth.async_register() == "ABC" | [
"async",
"def",
"test_auth_auth_check_and_register",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"HMIPC_HAPID",
":",
"\"ABC123\"",
",",
"HMIPC_PIN",
":",
"\"123\"",
",",
"HMIPC_NAME",
":",
"\"hmip\"",
"}",
"hmip_auth",
"=",
"HomematicipAuth",
"(",
"hass",
",",
"config",
")",
"hmip_auth",
".",
"auth",
"=",
"Mock",
"(",
"spec",
"=",
"AsyncAuth",
")",
"with",
"patch",
".",
"object",
"(",
"hmip_auth",
".",
"auth",
",",
"\"isRequestAcknowledged\"",
",",
"return_value",
"=",
"True",
")",
",",
"patch",
".",
"object",
"(",
"hmip_auth",
".",
"auth",
",",
"\"requestAuthToken\"",
",",
"return_value",
"=",
"\"ABC\"",
")",
",",
"patch",
".",
"object",
"(",
"hmip_auth",
".",
"auth",
",",
"\"confirmAuthToken\"",
")",
":",
"assert",
"await",
"hmip_auth",
".",
"async_checkbutton",
"(",
")",
"assert",
"await",
"hmip_auth",
".",
"async_register",
"(",
")",
"==",
"\"ABC\""
] | [
42,
0
] | [
56,
56
] | python | de | ['de', 'fr', 'en'] | False |
test_auth_auth_check_and_register_with_exception | (hass) | Test auth client registration. | Test auth client registration. | async def test_auth_auth_check_and_register_with_exception(hass):
"""Test auth client registration."""
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
hmip_auth.auth = Mock(spec=AsyncAuth)
with patch.object(
hmip_auth.auth, "isRequestAcknowledged", side_effect=HmipConnectionError
), patch.object(
hmip_auth.auth, "requestAuthToken", side_effect=HmipConnectionError
):
assert not await hmip_auth.async_checkbutton()
assert await hmip_auth.async_register() is False | [
"async",
"def",
"test_auth_auth_check_and_register_with_exception",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"HMIPC_HAPID",
":",
"\"ABC123\"",
",",
"HMIPC_PIN",
":",
"\"123\"",
",",
"HMIPC_NAME",
":",
"\"hmip\"",
"}",
"hmip_auth",
"=",
"HomematicipAuth",
"(",
"hass",
",",
"config",
")",
"hmip_auth",
".",
"auth",
"=",
"Mock",
"(",
"spec",
"=",
"AsyncAuth",
")",
"with",
"patch",
".",
"object",
"(",
"hmip_auth",
".",
"auth",
",",
"\"isRequestAcknowledged\"",
",",
"side_effect",
"=",
"HmipConnectionError",
")",
",",
"patch",
".",
"object",
"(",
"hmip_auth",
".",
"auth",
",",
"\"requestAuthToken\"",
",",
"side_effect",
"=",
"HmipConnectionError",
")",
":",
"assert",
"not",
"await",
"hmip_auth",
".",
"async_checkbutton",
"(",
")",
"assert",
"await",
"hmip_auth",
".",
"async_register",
"(",
")",
"is",
"False"
] | [
59,
0
] | [
70,
56
] | python | de | ['de', 'fr', 'en'] | False |
test_hap_setup_works | () | Test a successful setup of a accesspoint. | Test a successful setup of a accesspoint. | async def test_hap_setup_works():
"""Test a successful setup of a accesspoint."""
hass = Mock()
entry = Mock()
home = Mock()
entry.data = {HMIPC_HAPID: "ABC123", HMIPC_AUTHTOKEN: "123", HMIPC_NAME: "hmip"}
hap = HomematicipHAP(hass, entry)
with patch.object(hap, "get_hap", return_value=home):
assert await hap.async_setup()
assert hap.home is home
assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 8
assert hass.config_entries.async_forward_entry_setup.mock_calls[0][1] == (
entry,
"alarm_control_panel",
)
assert hass.config_entries.async_forward_entry_setup.mock_calls[1][1] == (
entry,
"binary_sensor",
) | [
"async",
"def",
"test_hap_setup_works",
"(",
")",
":",
"hass",
"=",
"Mock",
"(",
")",
"entry",
"=",
"Mock",
"(",
")",
"home",
"=",
"Mock",
"(",
")",
"entry",
".",
"data",
"=",
"{",
"HMIPC_HAPID",
":",
"\"ABC123\"",
",",
"HMIPC_AUTHTOKEN",
":",
"\"123\"",
",",
"HMIPC_NAME",
":",
"\"hmip\"",
"}",
"hap",
"=",
"HomematicipHAP",
"(",
"hass",
",",
"entry",
")",
"with",
"patch",
".",
"object",
"(",
"hap",
",",
"\"get_hap\"",
",",
"return_value",
"=",
"home",
")",
":",
"assert",
"await",
"hap",
".",
"async_setup",
"(",
")",
"assert",
"hap",
".",
"home",
"is",
"home",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
".",
"mock_calls",
")",
"==",
"8",
"assert",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
".",
"mock_calls",
"[",
"0",
"]",
"[",
"1",
"]",
"==",
"(",
"entry",
",",
"\"alarm_control_panel\"",
",",
")",
"assert",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
".",
"mock_calls",
"[",
"1",
"]",
"[",
"1",
"]",
"==",
"(",
"entry",
",",
"\"binary_sensor\"",
",",
")"
] | [
73,
0
] | [
92,
5
] | python | en | ['en', 'en', 'en'] | True |
test_hap_setup_connection_error | () | Test a failed accesspoint setup. | Test a failed accesspoint setup. | async def test_hap_setup_connection_error():
"""Test a failed accesspoint setup."""
hass = Mock()
entry = Mock()
entry.data = {HMIPC_HAPID: "ABC123", HMIPC_AUTHTOKEN: "123", HMIPC_NAME: "hmip"}
hap = HomematicipHAP(hass, entry)
with patch.object(hap, "get_hap", side_effect=HmipcConnectionError), pytest.raises(
ConfigEntryNotReady
):
assert not await hap.async_setup()
assert not hass.async_add_job.mock_calls
assert not hass.config_entries.flow.async_init.mock_calls | [
"async",
"def",
"test_hap_setup_connection_error",
"(",
")",
":",
"hass",
"=",
"Mock",
"(",
")",
"entry",
"=",
"Mock",
"(",
")",
"entry",
".",
"data",
"=",
"{",
"HMIPC_HAPID",
":",
"\"ABC123\"",
",",
"HMIPC_AUTHTOKEN",
":",
"\"123\"",
",",
"HMIPC_NAME",
":",
"\"hmip\"",
"}",
"hap",
"=",
"HomematicipHAP",
"(",
"hass",
",",
"entry",
")",
"with",
"patch",
".",
"object",
"(",
"hap",
",",
"\"get_hap\"",
",",
"side_effect",
"=",
"HmipcConnectionError",
")",
",",
"pytest",
".",
"raises",
"(",
"ConfigEntryNotReady",
")",
":",
"assert",
"not",
"await",
"hap",
".",
"async_setup",
"(",
")",
"assert",
"not",
"hass",
".",
"async_add_job",
".",
"mock_calls",
"assert",
"not",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
".",
"mock_calls"
] | [
95,
0
] | [
107,
61
] | python | en | ['en', 'ga', 'en'] | True |
test_hap_reset_unloads_entry_if_setup | (hass, default_mock_hap_factory) | Test calling reset while the entry has been setup. | Test calling reset while the entry has been setup. | async def test_hap_reset_unloads_entry_if_setup(hass, default_mock_hap_factory):
"""Test calling reset while the entry has been setup."""
mock_hap = await default_mock_hap_factory.async_get_mock_hap()
assert hass.data[HMIPC_DOMAIN][HAPID] == mock_hap
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
assert len(config_entries) == 1
# hap_reset is called during unload
await hass.config_entries.async_unload(config_entries[0].entry_id)
# entry is unloaded
assert config_entries[0].state == ENTRY_STATE_NOT_LOADED
assert hass.data[HMIPC_DOMAIN] == {} | [
"async",
"def",
"test_hap_reset_unloads_entry_if_setup",
"(",
"hass",
",",
"default_mock_hap_factory",
")",
":",
"mock_hap",
"=",
"await",
"default_mock_hap_factory",
".",
"async_get_mock_hap",
"(",
")",
"assert",
"hass",
".",
"data",
"[",
"HMIPC_DOMAIN",
"]",
"[",
"HAPID",
"]",
"==",
"mock_hap",
"config_entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"HMIPC_DOMAIN",
")",
"assert",
"len",
"(",
"config_entries",
")",
"==",
"1",
"# hap_reset is called during unload",
"await",
"hass",
".",
"config_entries",
".",
"async_unload",
"(",
"config_entries",
"[",
"0",
"]",
".",
"entry_id",
")",
"# entry is unloaded",
"assert",
"config_entries",
"[",
"0",
"]",
".",
"state",
"==",
"ENTRY_STATE_NOT_LOADED",
"assert",
"hass",
".",
"data",
"[",
"HMIPC_DOMAIN",
"]",
"==",
"{",
"}"
] | [
110,
0
] | [
120,
40
] | python | en | ['en', 'en', 'en'] | True |
test_hap_create | (hass, hmip_config_entry, simple_mock_home) | Mock AsyncHome to execute get_hap. | Mock AsyncHome to execute get_hap. | async def test_hap_create(hass, hmip_config_entry, simple_mock_home):
"""Mock AsyncHome to execute get_hap."""
hass.config.components.add(HMIPC_DOMAIN)
hap = HomematicipHAP(hass, hmip_config_entry)
assert hap
with patch.object(hap, "async_connect"):
assert await hap.async_setup() | [
"async",
"def",
"test_hap_create",
"(",
"hass",
",",
"hmip_config_entry",
",",
"simple_mock_home",
")",
":",
"hass",
".",
"config",
".",
"components",
".",
"add",
"(",
"HMIPC_DOMAIN",
")",
"hap",
"=",
"HomematicipHAP",
"(",
"hass",
",",
"hmip_config_entry",
")",
"assert",
"hap",
"with",
"patch",
".",
"object",
"(",
"hap",
",",
"\"async_connect\"",
")",
":",
"assert",
"await",
"hap",
".",
"async_setup",
"(",
")"
] | [
123,
0
] | [
129,
38
] | python | en | ['en', 'en', 'en'] | True |
test_hap_create_exception | (hass, hmip_config_entry, mock_connection_init) | Mock AsyncHome to execute get_hap. | Mock AsyncHome to execute get_hap. | async def test_hap_create_exception(hass, hmip_config_entry, mock_connection_init):
"""Mock AsyncHome to execute get_hap."""
hass.config.components.add(HMIPC_DOMAIN)
hap = HomematicipHAP(hass, hmip_config_entry)
assert hap
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
side_effect=Exception,
):
assert not await hap.async_setup()
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
side_effect=HmipConnectionError,
), pytest.raises(ConfigEntryNotReady):
await hap.async_setup() | [
"async",
"def",
"test_hap_create_exception",
"(",
"hass",
",",
"hmip_config_entry",
",",
"mock_connection_init",
")",
":",
"hass",
".",
"config",
".",
"components",
".",
"add",
"(",
"HMIPC_DOMAIN",
")",
"hap",
"=",
"HomematicipHAP",
"(",
"hass",
",",
"hmip_config_entry",
")",
"assert",
"hap",
"with",
"patch",
"(",
"\"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state\"",
",",
"side_effect",
"=",
"Exception",
",",
")",
":",
"assert",
"not",
"await",
"hap",
".",
"async_setup",
"(",
")",
"with",
"patch",
"(",
"\"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state\"",
",",
"side_effect",
"=",
"HmipConnectionError",
",",
")",
",",
"pytest",
".",
"raises",
"(",
"ConfigEntryNotReady",
")",
":",
"await",
"hap",
".",
"async_setup",
"(",
")"
] | [
132,
0
] | [
149,
31
] | python | en | ['en', 'en', 'en'] | True |
test_auth_create | (hass, simple_mock_auth) | Mock AsyncAuth to execute get_auth. | Mock AsyncAuth to execute get_auth. | async def test_auth_create(hass, simple_mock_auth):
"""Mock AsyncAuth to execute get_auth."""
config = {HMIPC_HAPID: HAPID, HMIPC_PIN: HAPPIN, HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
assert hmip_auth
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncAuth",
return_value=simple_mock_auth,
):
assert await hmip_auth.async_setup()
await hass.async_block_till_done()
assert hmip_auth.auth.pin == HAPPIN | [
"async",
"def",
"test_auth_create",
"(",
"hass",
",",
"simple_mock_auth",
")",
":",
"config",
"=",
"{",
"HMIPC_HAPID",
":",
"HAPID",
",",
"HMIPC_PIN",
":",
"HAPPIN",
",",
"HMIPC_NAME",
":",
"\"hmip\"",
"}",
"hmip_auth",
"=",
"HomematicipAuth",
"(",
"hass",
",",
"config",
")",
"assert",
"hmip_auth",
"with",
"patch",
"(",
"\"homeassistant.components.homematicip_cloud.hap.AsyncAuth\"",
",",
"return_value",
"=",
"simple_mock_auth",
",",
")",
":",
"assert",
"await",
"hmip_auth",
".",
"async_setup",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hmip_auth",
".",
"auth",
".",
"pin",
"==",
"HAPPIN"
] | [
152,
0
] | [
164,
43
] | python | en | ['en', 'en', 'en'] | True |
test_auth_create_exception | (hass, simple_mock_auth) | Mock AsyncAuth to execute get_auth. | Mock AsyncAuth to execute get_auth. | async def test_auth_create_exception(hass, simple_mock_auth):
"""Mock AsyncAuth to execute get_auth."""
config = {HMIPC_HAPID: HAPID, HMIPC_PIN: HAPPIN, HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
simple_mock_auth.connectionRequest.side_effect = HmipConnectionError
assert hmip_auth
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncAuth",
return_value=simple_mock_auth,
):
assert not await hmip_auth.async_setup()
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncAuth",
return_value=simple_mock_auth,
):
assert not await hmip_auth.get_auth(hass, HAPID, HAPPIN) | [
"async",
"def",
"test_auth_create_exception",
"(",
"hass",
",",
"simple_mock_auth",
")",
":",
"config",
"=",
"{",
"HMIPC_HAPID",
":",
"HAPID",
",",
"HMIPC_PIN",
":",
"HAPPIN",
",",
"HMIPC_NAME",
":",
"\"hmip\"",
"}",
"hmip_auth",
"=",
"HomematicipAuth",
"(",
"hass",
",",
"config",
")",
"simple_mock_auth",
".",
"connectionRequest",
".",
"side_effect",
"=",
"HmipConnectionError",
"assert",
"hmip_auth",
"with",
"patch",
"(",
"\"homeassistant.components.homematicip_cloud.hap.AsyncAuth\"",
",",
"return_value",
"=",
"simple_mock_auth",
",",
")",
":",
"assert",
"not",
"await",
"hmip_auth",
".",
"async_setup",
"(",
")",
"with",
"patch",
"(",
"\"homeassistant.components.homematicip_cloud.hap.AsyncAuth\"",
",",
"return_value",
"=",
"simple_mock_auth",
",",
")",
":",
"assert",
"not",
"await",
"hmip_auth",
".",
"get_auth",
"(",
"hass",
",",
"HAPID",
",",
"HAPPIN",
")"
] | [
167,
0
] | [
183,
64
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up Abode lock devices. | Set up Abode lock devices. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Abode lock devices."""
data = hass.data[DOMAIN]
entities = []
for device in data.abode.get_devices(generic_type=CONST.TYPE_LOCK):
entities.append(AbodeLock(data, device))
async_add_entities(entities) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"data",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"entities",
"=",
"[",
"]",
"for",
"device",
"in",
"data",
".",
"abode",
".",
"get_devices",
"(",
"generic_type",
"=",
"CONST",
".",
"TYPE_LOCK",
")",
":",
"entities",
".",
"append",
"(",
"AbodeLock",
"(",
"data",
",",
"device",
")",
")",
"async_add_entities",
"(",
"entities",
")"
] | [
9,
0
] | [
18,
32
] | python | en | ['es', 'en', 'en'] | True |
AbodeLock.lock | (self, **kwargs) | Lock the device. | Lock the device. | def lock(self, **kwargs):
"""Lock the device."""
self._device.lock() | [
"def",
"lock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_device",
".",
"lock",
"(",
")"
] | [
24,
4
] | [
26,
27
] | python | en | ['en', 'en', 'en'] | True |
AbodeLock.unlock | (self, **kwargs) | Unlock the device. | Unlock the device. | def unlock(self, **kwargs):
"""Unlock the device."""
self._device.unlock() | [
"def",
"unlock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_device",
".",
"unlock",
"(",
")"
] | [
28,
4
] | [
30,
29
] | python | en | ['en', 'zh', 'en'] | True |
AbodeLock.is_locked | (self) | Return true if device is on. | Return true if device is on. | def is_locked(self):
"""Return true if device is on."""
return self._device.is_locked | [
"def",
"is_locked",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device",
".",
"is_locked"
] | [
33,
4
] | [
35,
37
] | python | en | ['en', 'fy', 'en'] | True |
async_setup_entry | (
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
) | Set up OVO Energy sensor based on a config entry. | Set up OVO Energy sensor based on a config entry. | async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
) -> None:
"""Set up OVO Energy sensor based on a config entry."""
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
DATA_COORDINATOR
]
client: OVOEnergy = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]
entities = []
if coordinator.data:
if coordinator.data.electricity:
entities.append(OVOEnergyLastElectricityReading(coordinator, client))
entities.append(
OVOEnergyLastElectricityCost(
coordinator,
client,
coordinator.data.electricity[
len(coordinator.data.electricity) - 1
].cost.currency_unit,
)
)
if coordinator.data.gas:
entities.append(OVOEnergyLastGasReading(coordinator, client))
entities.append(
OVOEnergyLastGasCost(
coordinator,
client,
coordinator.data.gas[
len(coordinator.data.gas) - 1
].cost.currency_unit,
)
)
async_add_entities(
entities,
True,
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
",",
"async_add_entities",
")",
"->",
"None",
":",
"coordinator",
":",
"DataUpdateCoordinator",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"DATA_COORDINATOR",
"]",
"client",
":",
"OVOEnergy",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"DATA_CLIENT",
"]",
"entities",
"=",
"[",
"]",
"if",
"coordinator",
".",
"data",
":",
"if",
"coordinator",
".",
"data",
".",
"electricity",
":",
"entities",
".",
"append",
"(",
"OVOEnergyLastElectricityReading",
"(",
"coordinator",
",",
"client",
")",
")",
"entities",
".",
"append",
"(",
"OVOEnergyLastElectricityCost",
"(",
"coordinator",
",",
"client",
",",
"coordinator",
".",
"data",
".",
"electricity",
"[",
"len",
"(",
"coordinator",
".",
"data",
".",
"electricity",
")",
"-",
"1",
"]",
".",
"cost",
".",
"currency_unit",
",",
")",
")",
"if",
"coordinator",
".",
"data",
".",
"gas",
":",
"entities",
".",
"append",
"(",
"OVOEnergyLastGasReading",
"(",
"coordinator",
",",
"client",
")",
")",
"entities",
".",
"append",
"(",
"OVOEnergyLastGasCost",
"(",
"coordinator",
",",
"client",
",",
"coordinator",
".",
"data",
".",
"gas",
"[",
"len",
"(",
"coordinator",
".",
"data",
".",
"gas",
")",
"-",
"1",
"]",
".",
"cost",
".",
"currency_unit",
",",
")",
")",
"async_add_entities",
"(",
"entities",
",",
"True",
",",
")"
] | [
17,
0
] | [
55,
5
] | python | en | ['en', 'en', 'en'] | True |
OVOEnergySensor.__init__ | (
self,
coordinator: DataUpdateCoordinator,
client: OVOEnergy,
key: str,
name: str,
icon: str,
unit_of_measurement: str = "",
) | Initialize OVO Energy sensor. | Initialize OVO Energy sensor. | def __init__(
self,
coordinator: DataUpdateCoordinator,
client: OVOEnergy,
key: str,
name: str,
icon: str,
unit_of_measurement: str = "",
) -> None:
"""Initialize OVO Energy sensor."""
self._unit_of_measurement = unit_of_measurement
super().__init__(coordinator, client, key, name, icon) | [
"def",
"__init__",
"(",
"self",
",",
"coordinator",
":",
"DataUpdateCoordinator",
",",
"client",
":",
"OVOEnergy",
",",
"key",
":",
"str",
",",
"name",
":",
"str",
",",
"icon",
":",
"str",
",",
"unit_of_measurement",
":",
"str",
"=",
"\"\"",
",",
")",
"->",
"None",
":",
"self",
".",
"_unit_of_measurement",
"=",
"unit_of_measurement",
"super",
"(",
")",
".",
"__init__",
"(",
"coordinator",
",",
"client",
",",
"key",
",",
"name",
",",
"icon",
")"
] | [
61,
4
] | [
73,
62
] | python | hu | ['hu', 'pt', 'it'] | False |
OVOEnergySensor.unit_of_measurement | (self) | Return the unit this state is expressed in. | Return the unit this state is expressed in. | def unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
76,
4
] | [
78,
40
] | python | en | ['en', 'en', 'en'] | True |
OVOEnergyLastElectricityReading.__init__ | (self, coordinator: DataUpdateCoordinator, client: OVOEnergy) | Initialize OVO Energy sensor. | Initialize OVO Energy sensor. | def __init__(self, coordinator: DataUpdateCoordinator, client: OVOEnergy):
"""Initialize OVO Energy sensor."""
super().__init__(
coordinator,
client,
f"{client.account_id}_last_electricity_reading",
"OVO Last Electricity Reading",
"mdi:flash",
"kWh",
) | [
"def",
"__init__",
"(",
"self",
",",
"coordinator",
":",
"DataUpdateCoordinator",
",",
"client",
":",
"OVOEnergy",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"coordinator",
",",
"client",
",",
"f\"{client.account_id}_last_electricity_reading\"",
",",
"\"OVO Last Electricity Reading\"",
",",
"\"mdi:flash\"",
",",
"\"kWh\"",
",",
")"
] | [
84,
4
] | [
94,
9
] | python | hu | ['hu', 'pt', 'it'] | False |
OVOEnergyLastElectricityReading.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self) -> str:
"""Return the state of the sensor."""
usage: OVODailyUsage = self.coordinator.data
if usage is None or not usage.electricity:
return None
return usage.electricity[-1].consumption | [
"def",
"state",
"(",
"self",
")",
"->",
"str",
":",
"usage",
":",
"OVODailyUsage",
"=",
"self",
".",
"coordinator",
".",
"data",
"if",
"usage",
"is",
"None",
"or",
"not",
"usage",
".",
"electricity",
":",
"return",
"None",
"return",
"usage",
".",
"electricity",
"[",
"-",
"1",
"]",
".",
"consumption"
] | [
97,
4
] | [
102,
48
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.