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
list | start_point
list | end_point
list | language
stringclasses 1
value | docstring_language
stringlengths 2
7
| docstring_language_predictions
stringlengths 18
23
| is_langid_reliable
stringclasses 2
values |
---|---|---|---|---|---|---|---|---|---|---|---|
configured_instances
|
(hass)
|
Return a set of configured GeoNet NZ Volcano instances.
|
Return a set of configured GeoNet NZ Volcano instances.
|
def configured_instances(hass):
"""Return a set of configured GeoNet NZ Volcano instances."""
return {
f"{entry.data[CONF_LATITUDE]}, {entry.data[CONF_LONGITUDE]}"
for entry in hass.config_entries.async_entries(DOMAIN)
}
|
[
"def",
"configured_instances",
"(",
"hass",
")",
":",
"return",
"{",
"f\"{entry.data[CONF_LATITUDE]}, {entry.data[CONF_LONGITUDE]}\"",
"for",
"entry",
"in",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
"}"
] |
[
20,
0
] |
[
25,
5
] |
python
|
en
|
['en', 'nl', 'en']
|
True
|
GeonetnzVolcanoFlowHandler._show_form
|
(self, errors=None)
|
Show the form to the user.
|
Show the form to the user.
|
async def _show_form(self, errors=None):
"""Show the form to the user."""
data_schema = vol.Schema(
{vol.Optional(CONF_RADIUS, default=DEFAULT_RADIUS): cv.positive_int}
)
return self.async_show_form(
step_id="user", data_schema=data_schema, errors=errors or {}
)
|
[
"async",
"def",
"_show_form",
"(",
"self",
",",
"errors",
"=",
"None",
")",
":",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Optional",
"(",
"CONF_RADIUS",
",",
"default",
"=",
"DEFAULT_RADIUS",
")",
":",
"cv",
".",
"positive_int",
"}",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"data_schema",
",",
"errors",
"=",
"errors",
"or",
"{",
"}",
")"
] |
[
33,
4
] |
[
41,
9
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
GeonetnzVolcanoFlowHandler.async_step_import
|
(self, import_config)
|
Import a config entry from configuration.yaml.
|
Import a config entry from configuration.yaml.
|
async def async_step_import(self, import_config):
"""Import a config entry from configuration.yaml."""
return await self.async_step_user(import_config)
|
[
"async",
"def",
"async_step_import",
"(",
"self",
",",
"import_config",
")",
":",
"return",
"await",
"self",
".",
"async_step_user",
"(",
"import_config",
")"
] |
[
43,
4
] |
[
45,
56
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
GeonetnzVolcanoFlowHandler.async_step_user
|
(self, user_input=None)
|
Handle the start of the config flow.
|
Handle the start of the config flow.
|
async def async_step_user(self, user_input=None):
"""Handle the start of the config flow."""
if not user_input:
return await self._show_form()
latitude = user_input.get(CONF_LATITUDE, self.hass.config.latitude)
user_input[CONF_LATITUDE] = latitude
longitude = user_input.get(CONF_LONGITUDE, self.hass.config.longitude)
user_input[CONF_LONGITUDE] = longitude
identifier = f"{user_input[CONF_LATITUDE]}, {user_input[CONF_LONGITUDE]}"
if identifier in configured_instances(self.hass):
return await self._show_form({"base": "already_configured"})
if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
user_input[CONF_UNIT_SYSTEM] = CONF_UNIT_SYSTEM_IMPERIAL
else:
user_input[CONF_UNIT_SYSTEM] = CONF_UNIT_SYSTEM_METRIC
scan_interval = user_input.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
user_input[CONF_SCAN_INTERVAL] = scan_interval.seconds
return self.async_create_entry(title=identifier, data=user_input)
|
[
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"not",
"user_input",
":",
"return",
"await",
"self",
".",
"_show_form",
"(",
")",
"latitude",
"=",
"user_input",
".",
"get",
"(",
"CONF_LATITUDE",
",",
"self",
".",
"hass",
".",
"config",
".",
"latitude",
")",
"user_input",
"[",
"CONF_LATITUDE",
"]",
"=",
"latitude",
"longitude",
"=",
"user_input",
".",
"get",
"(",
"CONF_LONGITUDE",
",",
"self",
".",
"hass",
".",
"config",
".",
"longitude",
")",
"user_input",
"[",
"CONF_LONGITUDE",
"]",
"=",
"longitude",
"identifier",
"=",
"f\"{user_input[CONF_LATITUDE]}, {user_input[CONF_LONGITUDE]}\"",
"if",
"identifier",
"in",
"configured_instances",
"(",
"self",
".",
"hass",
")",
":",
"return",
"await",
"self",
".",
"_show_form",
"(",
"{",
"\"base\"",
":",
"\"already_configured\"",
"}",
")",
"if",
"self",
".",
"hass",
".",
"config",
".",
"units",
".",
"name",
"==",
"CONF_UNIT_SYSTEM_IMPERIAL",
":",
"user_input",
"[",
"CONF_UNIT_SYSTEM",
"]",
"=",
"CONF_UNIT_SYSTEM_IMPERIAL",
"else",
":",
"user_input",
"[",
"CONF_UNIT_SYSTEM",
"]",
"=",
"CONF_UNIT_SYSTEM_METRIC",
"scan_interval",
"=",
"user_input",
".",
"get",
"(",
"CONF_SCAN_INTERVAL",
",",
"DEFAULT_SCAN_INTERVAL",
")",
"user_input",
"[",
"CONF_SCAN_INTERVAL",
"]",
"=",
"scan_interval",
".",
"seconds",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"identifier",
",",
"data",
"=",
"user_input",
")"
] |
[
47,
4
] |
[
69,
73
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
IslamicPrayerFlowHandler.async_get_options_flow
|
(config_entry)
|
Get the options flow for this handler.
|
Get the options flow for this handler.
|
def async_get_options_flow(config_entry):
"""Get the options flow for this handler."""
return IslamicPrayerOptionsFlowHandler(config_entry)
|
[
"def",
"async_get_options_flow",
"(",
"config_entry",
")",
":",
"return",
"IslamicPrayerOptionsFlowHandler",
"(",
"config_entry",
")"
] |
[
18,
4
] |
[
20,
60
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
IslamicPrayerFlowHandler.async_step_user
|
(self, user_input=None)
|
Handle a flow initialized by the user.
|
Handle a flow initialized by the user.
|
async def async_step_user(self, user_input=None):
"""Handle a flow initialized by the user."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
if user_input is None:
return self.async_show_form(step_id="user")
return self.async_create_entry(title=NAME, data=user_input)
|
[
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"self",
".",
"_async_current_entries",
"(",
")",
":",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"single_instance_allowed\"",
")",
"if",
"user_input",
"is",
"None",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
")",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"NAME",
",",
"data",
"=",
"user_input",
")"
] |
[
22,
4
] |
[
30,
67
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
IslamicPrayerFlowHandler.async_step_import
|
(self, import_config)
|
Import from config.
|
Import from config.
|
async def async_step_import(self, import_config):
"""Import from config."""
return await self.async_step_user(user_input=import_config)
|
[
"async",
"def",
"async_step_import",
"(",
"self",
",",
"import_config",
")",
":",
"return",
"await",
"self",
".",
"async_step_user",
"(",
"user_input",
"=",
"import_config",
")"
] |
[
32,
4
] |
[
34,
67
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
IslamicPrayerOptionsFlowHandler.__init__
|
(self, config_entry)
|
Initialize options flow.
|
Initialize options flow.
|
def __init__(self, config_entry):
"""Initialize options flow."""
self.config_entry = config_entry
|
[
"def",
"__init__",
"(",
"self",
",",
"config_entry",
")",
":",
"self",
".",
"config_entry",
"=",
"config_entry"
] |
[
40,
4
] |
[
42,
40
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
IslamicPrayerOptionsFlowHandler.async_step_init
|
(self, user_input=None)
|
Manage options.
|
Manage options.
|
async def async_step_init(self, user_input=None):
"""Manage options."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
options = {
vol.Optional(
CONF_CALC_METHOD,
default=self.config_entry.options.get(
CONF_CALC_METHOD, DEFAULT_CALC_METHOD
),
): vol.In(CALC_METHODS)
}
return self.async_show_form(step_id="init", data_schema=vol.Schema(options))
|
[
"async",
"def",
"async_step_init",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"not",
"None",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"\"\"",
",",
"data",
"=",
"user_input",
")",
"options",
"=",
"{",
"vol",
".",
"Optional",
"(",
"CONF_CALC_METHOD",
",",
"default",
"=",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_CALC_METHOD",
",",
"DEFAULT_CALC_METHOD",
")",
",",
")",
":",
"vol",
".",
"In",
"(",
"CALC_METHODS",
")",
"}",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"init\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"options",
")",
")"
] |
[
44,
4
] |
[
58,
84
] |
python
|
en
|
['en', 'en', 'en']
|
False
|
async_setup_entry
|
(hass, config_entry, async_add_entities)
|
Set up Z-Wave Switch from Config Entry.
|
Set up Z-Wave Switch from Config Entry.
|
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Z-Wave Switch from Config Entry."""
@callback
def async_add_switch(switch):
"""Add Z-Wave Switch."""
async_add_entities([switch])
async_dispatcher_connect(hass, "zwave_new_switch", async_add_switch)
|
[
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"@",
"callback",
"def",
"async_add_switch",
"(",
"switch",
")",
":",
"\"\"\"Add Z-Wave Switch.\"\"\"",
"async_add_entities",
"(",
"[",
"switch",
"]",
")",
"async_dispatcher_connect",
"(",
"hass",
",",
"\"zwave_new_switch\"",
",",
"async_add_switch",
")"
] |
[
10,
0
] |
[
18,
72
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
get_device
|
(values, **kwargs)
|
Create zwave entity device.
|
Create zwave entity device.
|
def get_device(values, **kwargs):
"""Create zwave entity device."""
return ZwaveSwitch(values)
|
[
"def",
"get_device",
"(",
"values",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"ZwaveSwitch",
"(",
"values",
")"
] |
[
21,
0
] |
[
23,
30
] |
python
|
en
|
['pl', 'zh', 'en']
|
False
|
ZwaveSwitch.__init__
|
(self, values)
|
Initialize the Z-Wave switch device.
|
Initialize the Z-Wave switch device.
|
def __init__(self, values):
"""Initialize the Z-Wave switch device."""
ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self.refresh_on_update = (
workaround.get_device_mapping(values.primary)
== workaround.WORKAROUND_REFRESH_NODE_ON_UPDATE
)
self.last_update = time.perf_counter()
self._state = self.values.primary.data
|
[
"def",
"__init__",
"(",
"self",
",",
"values",
")",
":",
"ZWaveDeviceEntity",
".",
"__init__",
"(",
"self",
",",
"values",
",",
"DOMAIN",
")",
"self",
".",
"refresh_on_update",
"=",
"(",
"workaround",
".",
"get_device_mapping",
"(",
"values",
".",
"primary",
")",
"==",
"workaround",
".",
"WORKAROUND_REFRESH_NODE_ON_UPDATE",
")",
"self",
".",
"last_update",
"=",
"time",
".",
"perf_counter",
"(",
")",
"self",
".",
"_state",
"=",
"self",
".",
"values",
".",
"primary",
".",
"data"
] |
[
29,
4
] |
[
37,
46
] |
python
|
en
|
['en', 'pl', 'en']
|
True
|
ZwaveSwitch.update_properties
|
(self)
|
Handle data changes for node values.
|
Handle data changes for node values.
|
def update_properties(self):
"""Handle data changes for node values."""
self._state = self.values.primary.data
if self.refresh_on_update and time.perf_counter() - self.last_update > 30:
self.last_update = time.perf_counter()
self.node.request_state()
|
[
"def",
"update_properties",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"self",
".",
"values",
".",
"primary",
".",
"data",
"if",
"self",
".",
"refresh_on_update",
"and",
"time",
".",
"perf_counter",
"(",
")",
"-",
"self",
".",
"last_update",
">",
"30",
":",
"self",
".",
"last_update",
"=",
"time",
".",
"perf_counter",
"(",
")",
"self",
".",
"node",
".",
"request_state",
"(",
")"
] |
[
39,
4
] |
[
44,
37
] |
python
|
en
|
['fr', 'en', 'en']
|
True
|
ZwaveSwitch.is_on
|
(self)
|
Return true if device is on.
|
Return true if device is on.
|
def is_on(self):
"""Return true if device is on."""
return self._state
|
[
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] |
[
47,
4
] |
[
49,
26
] |
python
|
en
|
['en', 'fy', 'en']
|
True
|
ZwaveSwitch.turn_on
|
(self, **kwargs)
|
Turn the device on.
|
Turn the device on.
|
def turn_on(self, **kwargs):
"""Turn the device on."""
self.node.set_switch(self.values.primary.value_id, True)
|
[
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"node",
".",
"set_switch",
"(",
"self",
".",
"values",
".",
"primary",
".",
"value_id",
",",
"True",
")"
] |
[
51,
4
] |
[
53,
64
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
ZwaveSwitch.turn_off
|
(self, **kwargs)
|
Turn the device off.
|
Turn the device off.
|
def turn_off(self, **kwargs):
"""Turn the device off."""
self.node.set_switch(self.values.primary.value_id, False)
|
[
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"node",
".",
"set_switch",
"(",
"self",
".",
"values",
".",
"primary",
".",
"value_id",
",",
"False",
")"
] |
[
55,
4
] |
[
57,
65
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
test_platform_manually_configured
|
(hass)
|
Test that nothing happens when platform is manually configured.
|
Test that nothing happens when platform is manually configured.
|
async def test_platform_manually_configured(hass):
"""Test that nothing happens when platform is manually configured."""
assert await async_setup_component(
hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": AXIS_DOMAIN}}
)
assert AXIS_DOMAIN not in hass.data
|
[
"async",
"def",
"test_platform_manually_configured",
"(",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"LIGHT_DOMAIN",
",",
"{",
"LIGHT_DOMAIN",
":",
"{",
"\"platform\"",
":",
"AXIS_DOMAIN",
"}",
"}",
")",
"assert",
"AXIS_DOMAIN",
"not",
"in",
"hass",
".",
"data"
] |
[
44,
0
] |
[
50,
39
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
test_no_lights
|
(hass)
|
Test that no light events in Axis results in no light entities.
|
Test that no light events in Axis results in no light entities.
|
async def test_no_lights(hass):
"""Test that no light events in Axis results in no light entities."""
await setup_axis_integration(hass)
assert not hass.states.async_entity_ids(LIGHT_DOMAIN)
|
[
"async",
"def",
"test_no_lights",
"(",
"hass",
")",
":",
"await",
"setup_axis_integration",
"(",
"hass",
")",
"assert",
"not",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"LIGHT_DOMAIN",
")"
] |
[
53,
0
] |
[
57,
57
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
test_lights
|
(hass)
|
Test that lights are loaded properly.
|
Test that lights are loaded properly.
|
async def test_lights(hass):
"""Test that lights are loaded properly."""
api_discovery = deepcopy(API_DISCOVERY_RESPONSE)
api_discovery["data"]["apiList"].append(API_DISCOVERY_LIGHT_CONTROL)
with patch.dict(API_DISCOVERY_RESPONSE, api_discovery):
config_entry = await setup_axis_integration(hass)
device = hass.data[AXIS_DOMAIN][config_entry.unique_id]
# Add light
with patch(
"axis.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}},
), patch(
"axis.light_control.LightControl.get_valid_intensity",
return_value={"data": {"ranges": [{"high": 150}]}},
):
device.api.event.process_event(EVENT_ON)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(LIGHT_DOMAIN)) == 1
entity_id = f"{LIGHT_DOMAIN}.{NAME}_ir_light_0"
light_0 = hass.states.get(entity_id)
assert light_0.state == STATE_ON
assert light_0.name == f"{NAME} IR Light 0"
# Turn on, set brightness, light already on
with patch(
"axis.light_control.LightControl.activate_light"
) as mock_activate, patch(
"axis.light_control.LightControl.set_manual_intensity"
) as mock_set_intensity, patch(
"axis.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}},
):
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: entity_id, ATTR_BRIGHTNESS: 50},
blocking=True,
)
mock_activate.assert_not_awaited()
mock_set_intensity.assert_called_once_with("led0", 29)
# Turn off
with patch(
"axis.light_control.LightControl.deactivate_light"
) as mock_deactivate, patch(
"axis.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}},
):
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
mock_deactivate.assert_called_once()
# Event turn off light
device.api.event.process_event(EVENT_OFF)
await hass.async_block_till_done()
light_0 = hass.states.get(entity_id)
assert light_0.state == STATE_OFF
# Turn on, set brightness
with patch(
"axis.light_control.LightControl.activate_light"
) as mock_activate, patch(
"axis.light_control.LightControl.set_manual_intensity"
) as mock_set_intensity, patch(
"axis.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}},
):
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
mock_activate.assert_called_once()
mock_set_intensity.assert_not_called()
# Turn off, light already off
with patch(
"axis.light_control.LightControl.deactivate_light"
) as mock_deactivate, patch(
"axis.light_control.LightControl.get_current_intensity",
return_value={"data": {"intensity": 100}},
):
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
mock_deactivate.assert_not_called()
|
[
"async",
"def",
"test_lights",
"(",
"hass",
")",
":",
"api_discovery",
"=",
"deepcopy",
"(",
"API_DISCOVERY_RESPONSE",
")",
"api_discovery",
"[",
"\"data\"",
"]",
"[",
"\"apiList\"",
"]",
".",
"append",
"(",
"API_DISCOVERY_LIGHT_CONTROL",
")",
"with",
"patch",
".",
"dict",
"(",
"API_DISCOVERY_RESPONSE",
",",
"api_discovery",
")",
":",
"config_entry",
"=",
"await",
"setup_axis_integration",
"(",
"hass",
")",
"device",
"=",
"hass",
".",
"data",
"[",
"AXIS_DOMAIN",
"]",
"[",
"config_entry",
".",
"unique_id",
"]",
"# Add light",
"with",
"patch",
"(",
"\"axis.light_control.LightControl.get_current_intensity\"",
",",
"return_value",
"=",
"{",
"\"data\"",
":",
"{",
"\"intensity\"",
":",
"100",
"}",
"}",
",",
")",
",",
"patch",
"(",
"\"axis.light_control.LightControl.get_valid_intensity\"",
",",
"return_value",
"=",
"{",
"\"data\"",
":",
"{",
"\"ranges\"",
":",
"[",
"{",
"\"high\"",
":",
"150",
"}",
"]",
"}",
"}",
",",
")",
":",
"device",
".",
"api",
".",
"event",
".",
"process_event",
"(",
"EVENT_ON",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"LIGHT_DOMAIN",
")",
")",
"==",
"1",
"entity_id",
"=",
"f\"{LIGHT_DOMAIN}.{NAME}_ir_light_0\"",
"light_0",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"light_0",
".",
"state",
"==",
"STATE_ON",
"assert",
"light_0",
".",
"name",
"==",
"f\"{NAME} IR Light 0\"",
"# Turn on, set brightness, light already on",
"with",
"patch",
"(",
"\"axis.light_control.LightControl.activate_light\"",
")",
"as",
"mock_activate",
",",
"patch",
"(",
"\"axis.light_control.LightControl.set_manual_intensity\"",
")",
"as",
"mock_set_intensity",
",",
"patch",
"(",
"\"axis.light_control.LightControl.get_current_intensity\"",
",",
"return_value",
"=",
"{",
"\"data\"",
":",
"{",
"\"intensity\"",
":",
"100",
"}",
"}",
",",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
",",
"ATTR_BRIGHTNESS",
":",
"50",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"mock_activate",
".",
"assert_not_awaited",
"(",
")",
"mock_set_intensity",
".",
"assert_called_once_with",
"(",
"\"led0\"",
",",
"29",
")",
"# Turn off",
"with",
"patch",
"(",
"\"axis.light_control.LightControl.deactivate_light\"",
")",
"as",
"mock_deactivate",
",",
"patch",
"(",
"\"axis.light_control.LightControl.get_current_intensity\"",
",",
"return_value",
"=",
"{",
"\"data\"",
":",
"{",
"\"intensity\"",
":",
"100",
"}",
"}",
",",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"mock_deactivate",
".",
"assert_called_once",
"(",
")",
"# Event turn off light",
"device",
".",
"api",
".",
"event",
".",
"process_event",
"(",
"EVENT_OFF",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"light_0",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"light_0",
".",
"state",
"==",
"STATE_OFF",
"# Turn on, set brightness",
"with",
"patch",
"(",
"\"axis.light_control.LightControl.activate_light\"",
")",
"as",
"mock_activate",
",",
"patch",
"(",
"\"axis.light_control.LightControl.set_manual_intensity\"",
")",
"as",
"mock_set_intensity",
",",
"patch",
"(",
"\"axis.light_control.LightControl.get_current_intensity\"",
",",
"return_value",
"=",
"{",
"\"data\"",
":",
"{",
"\"intensity\"",
":",
"100",
"}",
"}",
",",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"mock_activate",
".",
"assert_called_once",
"(",
")",
"mock_set_intensity",
".",
"assert_not_called",
"(",
")",
"# Turn off, light already off",
"with",
"patch",
"(",
"\"axis.light_control.LightControl.deactivate_light\"",
")",
"as",
"mock_deactivate",
",",
"patch",
"(",
"\"axis.light_control.LightControl.get_current_intensity\"",
",",
"return_value",
"=",
"{",
"\"data\"",
":",
"{",
"\"intensity\"",
":",
"100",
"}",
"}",
",",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"mock_deactivate",
".",
"assert_not_called",
"(",
")"
] |
[
60,
0
] |
[
159,
43
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
async_setup
|
(hass, config)
|
Set up Synology DSM sensors from legacy config file.
|
Set up Synology DSM sensors from legacy config file.
|
async def async_setup(hass, config):
"""Set up Synology DSM sensors from legacy config file."""
conf = config.get(DOMAIN)
if conf is None:
return True
for dsm_conf in conf:
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data=dsm_conf,
)
)
return True
|
[
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"conf",
"=",
"config",
".",
"get",
"(",
"DOMAIN",
")",
"if",
"conf",
"is",
"None",
":",
"return",
"True",
"for",
"dsm_conf",
"in",
"conf",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"dsm_conf",
",",
")",
")",
"return",
"True"
] |
[
96,
0
] |
[
112,
15
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
async_setup_entry
|
(hass: HomeAssistantType, entry: ConfigEntry)
|
Set up Synology DSM sensors.
|
Set up Synology DSM sensors.
|
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Set up Synology DSM sensors."""
# Migrate old unique_id
@callback
def _async_migrator(entity_entry: entity_registry.RegistryEntry):
"""Migrate away from ID using label."""
# Reject if new unique_id
if "SYNO." in entity_entry.unique_id:
return None
entries = {
**STORAGE_DISK_BINARY_SENSORS,
**STORAGE_DISK_SENSORS,
**STORAGE_VOL_SENSORS,
**UTILISATION_SENSORS,
}
infos = entity_entry.unique_id.split("_")
serial = infos.pop(0)
label = infos.pop(0)
device_id = "_".join(infos)
# Removed entity
if (
"Type" in entity_entry.unique_id
or "Device" in entity_entry.unique_id
or "Name" in entity_entry.unique_id
):
return None
entity_type = None
for entity_key, entity_attrs in entries.items():
if (
device_id
and entity_attrs[ENTITY_NAME] == "Status"
and "Status" in entity_entry.unique_id
and "(Smart)" not in entity_entry.unique_id
):
if "sd" in device_id and "disk" in entity_key:
entity_type = entity_key
continue
if "volume" in device_id and "volume" in entity_key:
entity_type = entity_key
continue
if entity_attrs[ENTITY_NAME] == label:
entity_type = entity_key
new_unique_id = "_".join([serial, entity_type])
if device_id:
new_unique_id += f"_{device_id}"
_LOGGER.info(
"Migrating unique_id from [%s] to [%s]",
entity_entry.unique_id,
new_unique_id,
)
return {"new_unique_id": new_unique_id}
await entity_registry.async_migrate_entries(hass, entry.entry_id, _async_migrator)
# Migrate existing entry configuration
if entry.data.get(CONF_VERIFY_SSL) is None:
hass.config_entries.async_update_entry(
entry, data={**entry.data, CONF_VERIFY_SSL: DEFAULT_VERIFY_SSL}
)
# Continue setup
api = SynoApi(hass, entry)
try:
await api.async_setup()
except (SynologyDSMLoginFailedException, SynologyDSMRequestException) as err:
_LOGGER.debug("async_setup_entry - Unable to connect to DSM: %s", err)
raise ConfigEntryNotReady from err
undo_listener = entry.add_update_listener(_async_update_listener)
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.unique_id] = {
SYNO_API: api,
UNDO_UPDATE_LISTENER: undo_listener,
}
# Services
await _async_setup_services(hass)
# For SSDP compat
if not entry.data.get(CONF_MAC):
network = await hass.async_add_executor_job(getattr, api.dsm, "network")
hass.config_entries.async_update_entry(
entry, data={**entry.data, CONF_MAC: network.macs}
)
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
return True
|
[
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"# Migrate old unique_id",
"@",
"callback",
"def",
"_async_migrator",
"(",
"entity_entry",
":",
"entity_registry",
".",
"RegistryEntry",
")",
":",
"\"\"\"Migrate away from ID using label.\"\"\"",
"# Reject if new unique_id",
"if",
"\"SYNO.\"",
"in",
"entity_entry",
".",
"unique_id",
":",
"return",
"None",
"entries",
"=",
"{",
"*",
"*",
"STORAGE_DISK_BINARY_SENSORS",
",",
"*",
"*",
"STORAGE_DISK_SENSORS",
",",
"*",
"*",
"STORAGE_VOL_SENSORS",
",",
"*",
"*",
"UTILISATION_SENSORS",
",",
"}",
"infos",
"=",
"entity_entry",
".",
"unique_id",
".",
"split",
"(",
"\"_\"",
")",
"serial",
"=",
"infos",
".",
"pop",
"(",
"0",
")",
"label",
"=",
"infos",
".",
"pop",
"(",
"0",
")",
"device_id",
"=",
"\"_\"",
".",
"join",
"(",
"infos",
")",
"# Removed entity",
"if",
"(",
"\"Type\"",
"in",
"entity_entry",
".",
"unique_id",
"or",
"\"Device\"",
"in",
"entity_entry",
".",
"unique_id",
"or",
"\"Name\"",
"in",
"entity_entry",
".",
"unique_id",
")",
":",
"return",
"None",
"entity_type",
"=",
"None",
"for",
"entity_key",
",",
"entity_attrs",
"in",
"entries",
".",
"items",
"(",
")",
":",
"if",
"(",
"device_id",
"and",
"entity_attrs",
"[",
"ENTITY_NAME",
"]",
"==",
"\"Status\"",
"and",
"\"Status\"",
"in",
"entity_entry",
".",
"unique_id",
"and",
"\"(Smart)\"",
"not",
"in",
"entity_entry",
".",
"unique_id",
")",
":",
"if",
"\"sd\"",
"in",
"device_id",
"and",
"\"disk\"",
"in",
"entity_key",
":",
"entity_type",
"=",
"entity_key",
"continue",
"if",
"\"volume\"",
"in",
"device_id",
"and",
"\"volume\"",
"in",
"entity_key",
":",
"entity_type",
"=",
"entity_key",
"continue",
"if",
"entity_attrs",
"[",
"ENTITY_NAME",
"]",
"==",
"label",
":",
"entity_type",
"=",
"entity_key",
"new_unique_id",
"=",
"\"_\"",
".",
"join",
"(",
"[",
"serial",
",",
"entity_type",
"]",
")",
"if",
"device_id",
":",
"new_unique_id",
"+=",
"f\"_{device_id}\"",
"_LOGGER",
".",
"info",
"(",
"\"Migrating unique_id from [%s] to [%s]\"",
",",
"entity_entry",
".",
"unique_id",
",",
"new_unique_id",
",",
")",
"return",
"{",
"\"new_unique_id\"",
":",
"new_unique_id",
"}",
"await",
"entity_registry",
".",
"async_migrate_entries",
"(",
"hass",
",",
"entry",
".",
"entry_id",
",",
"_async_migrator",
")",
"# Migrate existing entry configuration",
"if",
"entry",
".",
"data",
".",
"get",
"(",
"CONF_VERIFY_SSL",
")",
"is",
"None",
":",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"entry",
",",
"data",
"=",
"{",
"*",
"*",
"entry",
".",
"data",
",",
"CONF_VERIFY_SSL",
":",
"DEFAULT_VERIFY_SSL",
"}",
")",
"# Continue setup",
"api",
"=",
"SynoApi",
"(",
"hass",
",",
"entry",
")",
"try",
":",
"await",
"api",
".",
"async_setup",
"(",
")",
"except",
"(",
"SynologyDSMLoginFailedException",
",",
"SynologyDSMRequestException",
")",
"as",
"err",
":",
"_LOGGER",
".",
"debug",
"(",
"\"async_setup_entry - Unable to connect to DSM: %s\"",
",",
"err",
")",
"raise",
"ConfigEntryNotReady",
"from",
"err",
"undo_listener",
"=",
"entry",
".",
"add_update_listener",
"(",
"_async_update_listener",
")",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"unique_id",
"]",
"=",
"{",
"SYNO_API",
":",
"api",
",",
"UNDO_UPDATE_LISTENER",
":",
"undo_listener",
",",
"}",
"# Services",
"await",
"_async_setup_services",
"(",
"hass",
")",
"# For SSDP compat",
"if",
"not",
"entry",
".",
"data",
".",
"get",
"(",
"CONF_MAC",
")",
":",
"network",
"=",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"getattr",
",",
"api",
".",
"dsm",
",",
"\"network\"",
")",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"entry",
",",
"data",
"=",
"{",
"*",
"*",
"entry",
".",
"data",
",",
"CONF_MAC",
":",
"network",
".",
"macs",
"}",
")",
"for",
"platform",
"in",
"PLATFORMS",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"entry",
",",
"platform",
")",
")",
"return",
"True"
] |
[
115,
0
] |
[
213,
15
] |
python
|
en
|
['en', 'da', 'en']
|
True
|
async_unload_entry
|
(hass: HomeAssistantType, entry: ConfigEntry)
|
Unload Synology DSM sensors.
|
Unload Synology DSM sensors.
|
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Unload Synology DSM sensors."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, platform)
for platform in PLATFORMS
]
)
)
if unload_ok:
entry_data = hass.data[DOMAIN][entry.unique_id]
entry_data[UNDO_UPDATE_LISTENER]()
await entry_data[SYNO_API].async_unload()
hass.data[DOMAIN].pop(entry.unique_id)
return unload_ok
|
[
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"unload_ok",
"=",
"all",
"(",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"entry",
",",
"platform",
")",
"for",
"platform",
"in",
"PLATFORMS",
"]",
")",
")",
"if",
"unload_ok",
":",
"entry_data",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"unique_id",
"]",
"entry_data",
"[",
"UNDO_UPDATE_LISTENER",
"]",
"(",
")",
"await",
"entry_data",
"[",
"SYNO_API",
"]",
".",
"async_unload",
"(",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"entry",
".",
"unique_id",
")",
"return",
"unload_ok"
] |
[
216,
0
] |
[
233,
20
] |
python
|
bg
|
['hu', 'bg', 'en']
|
False
|
_async_update_listener
|
(hass: HomeAssistantType, entry: ConfigEntry)
|
Handle options update.
|
Handle options update.
|
async def _async_update_listener(hass: HomeAssistantType, entry: ConfigEntry):
"""Handle options update."""
await hass.config_entries.async_reload(entry.entry_id)
|
[
"async",
"def",
"_async_update_listener",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_reload",
"(",
"entry",
".",
"entry_id",
")"
] |
[
236,
0
] |
[
238,
58
] |
python
|
en
|
['en', 'nl', 'en']
|
True
|
_async_setup_services
|
(hass: HomeAssistantType)
|
Service handler setup.
|
Service handler setup.
|
async def _async_setup_services(hass: HomeAssistantType):
"""Service handler setup."""
async def service_handler(call: ServiceCall):
"""Handle service call."""
serial = call.data.get(CONF_SERIAL)
dsm_devices = hass.data[DOMAIN]
if serial:
dsm_device = dsm_devices.get(serial)
elif len(dsm_devices) == 1:
dsm_device = next(iter(dsm_devices.values()))
serial = next(iter(dsm_devices))
else:
_LOGGER.error(
"service_handler - more than one DSM configured, must specify one of serials %s",
sorted(dsm_devices),
)
return
if not dsm_device:
_LOGGER.error(
"service_handler - DSM with specified serial %s not found", serial
)
return
_LOGGER.debug("%s DSM with serial %s", call.service, serial)
dsm_api = dsm_device[SYNO_API]
if call.service == SERVICE_REBOOT:
await dsm_api.async_reboot()
elif call.service == SERVICE_SHUTDOWN:
await dsm_api.system.shutdown()
for service in SERVICES:
hass.services.async_register(DOMAIN, service, service_handler)
|
[
"async",
"def",
"_async_setup_services",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"async",
"def",
"service_handler",
"(",
"call",
":",
"ServiceCall",
")",
":",
"\"\"\"Handle service call.\"\"\"",
"serial",
"=",
"call",
".",
"data",
".",
"get",
"(",
"CONF_SERIAL",
")",
"dsm_devices",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"if",
"serial",
":",
"dsm_device",
"=",
"dsm_devices",
".",
"get",
"(",
"serial",
")",
"elif",
"len",
"(",
"dsm_devices",
")",
"==",
"1",
":",
"dsm_device",
"=",
"next",
"(",
"iter",
"(",
"dsm_devices",
".",
"values",
"(",
")",
")",
")",
"serial",
"=",
"next",
"(",
"iter",
"(",
"dsm_devices",
")",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"service_handler - more than one DSM configured, must specify one of serials %s\"",
",",
"sorted",
"(",
"dsm_devices",
")",
",",
")",
"return",
"if",
"not",
"dsm_device",
":",
"_LOGGER",
".",
"error",
"(",
"\"service_handler - DSM with specified serial %s not found\"",
",",
"serial",
")",
"return",
"_LOGGER",
".",
"debug",
"(",
"\"%s DSM with serial %s\"",
",",
"call",
".",
"service",
",",
"serial",
")",
"dsm_api",
"=",
"dsm_device",
"[",
"SYNO_API",
"]",
"if",
"call",
".",
"service",
"==",
"SERVICE_REBOOT",
":",
"await",
"dsm_api",
".",
"async_reboot",
"(",
")",
"elif",
"call",
".",
"service",
"==",
"SERVICE_SHUTDOWN",
":",
"await",
"dsm_api",
".",
"system",
".",
"shutdown",
"(",
")",
"for",
"service",
"in",
"SERVICES",
":",
"hass",
".",
"services",
".",
"async_register",
"(",
"DOMAIN",
",",
"service",
",",
"service_handler",
")"
] |
[
241,
0
] |
[
275,
70
] |
python
|
en
|
['en', 'da', 'en']
|
True
|
SynoApi.__init__
|
(self, hass: HomeAssistantType, entry: ConfigEntry)
|
Initialize the API wrapper class.
|
Initialize the API wrapper class.
|
def __init__(self, hass: HomeAssistantType, entry: ConfigEntry):
"""Initialize the API wrapper class."""
self._hass = hass
self._entry = entry
# DSM APIs
self.dsm: SynologyDSM = None
self.information: SynoDSMInformation = None
self.network: SynoDSMNetwork = None
self.security: SynoCoreSecurity = None
self.storage: SynoStorage = None
self.surveillance_station: SynoSurveillanceStation = None
self.system: SynoCoreSystem = None
self.upgrade: SynoCoreUpgrade = None
self.utilisation: SynoCoreUtilization = None
# Should we fetch them
self._fetching_entities = {}
self._with_information = True
self._with_security = True
self._with_storage = True
self._with_surveillance_station = True
self._with_system = True
self._with_upgrade = True
self._with_utilisation = True
self._unsub_dispatcher = None
|
[
"def",
"__init__",
"(",
"self",
",",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"_entry",
"=",
"entry",
"# DSM APIs",
"self",
".",
"dsm",
":",
"SynologyDSM",
"=",
"None",
"self",
".",
"information",
":",
"SynoDSMInformation",
"=",
"None",
"self",
".",
"network",
":",
"SynoDSMNetwork",
"=",
"None",
"self",
".",
"security",
":",
"SynoCoreSecurity",
"=",
"None",
"self",
".",
"storage",
":",
"SynoStorage",
"=",
"None",
"self",
".",
"surveillance_station",
":",
"SynoSurveillanceStation",
"=",
"None",
"self",
".",
"system",
":",
"SynoCoreSystem",
"=",
"None",
"self",
".",
"upgrade",
":",
"SynoCoreUpgrade",
"=",
"None",
"self",
".",
"utilisation",
":",
"SynoCoreUtilization",
"=",
"None",
"# Should we fetch them",
"self",
".",
"_fetching_entities",
"=",
"{",
"}",
"self",
".",
"_with_information",
"=",
"True",
"self",
".",
"_with_security",
"=",
"True",
"self",
".",
"_with_storage",
"=",
"True",
"self",
".",
"_with_surveillance_station",
"=",
"True",
"self",
".",
"_with_system",
"=",
"True",
"self",
".",
"_with_upgrade",
"=",
"True",
"self",
".",
"_with_utilisation",
"=",
"True",
"self",
".",
"_unsub_dispatcher",
"=",
"None"
] |
[
281,
4
] |
[
307,
37
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynoApi.signal_sensor_update
|
(self)
|
Event specific per Synology DSM entry to signal updates in sensors.
|
Event specific per Synology DSM entry to signal updates in sensors.
|
def signal_sensor_update(self) -> str:
"""Event specific per Synology DSM entry to signal updates in sensors."""
return f"{DOMAIN}-{self.information.serial}-sensor-update"
|
[
"def",
"signal_sensor_update",
"(",
"self",
")",
"->",
"str",
":",
"return",
"f\"{DOMAIN}-{self.information.serial}-sensor-update\""
] |
[
310,
4
] |
[
312,
66
] |
python
|
en
|
['en', 'en', 'it']
|
True
|
SynoApi.async_setup
|
(self)
|
Start interacting with the NAS.
|
Start interacting with the NAS.
|
async def async_setup(self):
"""Start interacting with the NAS."""
self.dsm = SynologyDSM(
self._entry.data[CONF_HOST],
self._entry.data[CONF_PORT],
self._entry.data[CONF_USERNAME],
self._entry.data[CONF_PASSWORD],
self._entry.data[CONF_SSL],
self._entry.data[CONF_VERIFY_SSL],
timeout=self._entry.options.get(CONF_TIMEOUT),
device_token=self._entry.data.get("device_token"),
)
await self._hass.async_add_executor_job(self.dsm.login)
self._with_surveillance_station = bool(
self.dsm.apis.get(SynoSurveillanceStation.CAMERA_API_KEY)
)
self._async_setup_api_requests()
await self._hass.async_add_executor_job(self._fetch_device_configuration)
await self.async_update()
self._unsub_dispatcher = async_track_time_interval(
self._hass,
self.async_update,
timedelta(
minutes=self._entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)
),
)
|
[
"async",
"def",
"async_setup",
"(",
"self",
")",
":",
"self",
".",
"dsm",
"=",
"SynologyDSM",
"(",
"self",
".",
"_entry",
".",
"data",
"[",
"CONF_HOST",
"]",
",",
"self",
".",
"_entry",
".",
"data",
"[",
"CONF_PORT",
"]",
",",
"self",
".",
"_entry",
".",
"data",
"[",
"CONF_USERNAME",
"]",
",",
"self",
".",
"_entry",
".",
"data",
"[",
"CONF_PASSWORD",
"]",
",",
"self",
".",
"_entry",
".",
"data",
"[",
"CONF_SSL",
"]",
",",
"self",
".",
"_entry",
".",
"data",
"[",
"CONF_VERIFY_SSL",
"]",
",",
"timeout",
"=",
"self",
".",
"_entry",
".",
"options",
".",
"get",
"(",
"CONF_TIMEOUT",
")",
",",
"device_token",
"=",
"self",
".",
"_entry",
".",
"data",
".",
"get",
"(",
"\"device_token\"",
")",
",",
")",
"await",
"self",
".",
"_hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"dsm",
".",
"login",
")",
"self",
".",
"_with_surveillance_station",
"=",
"bool",
"(",
"self",
".",
"dsm",
".",
"apis",
".",
"get",
"(",
"SynoSurveillanceStation",
".",
"CAMERA_API_KEY",
")",
")",
"self",
".",
"_async_setup_api_requests",
"(",
")",
"await",
"self",
".",
"_hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"_fetch_device_configuration",
")",
"await",
"self",
".",
"async_update",
"(",
")",
"self",
".",
"_unsub_dispatcher",
"=",
"async_track_time_interval",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"async_update",
",",
"timedelta",
"(",
"minutes",
"=",
"self",
".",
"_entry",
".",
"options",
".",
"get",
"(",
"CONF_SCAN_INTERVAL",
",",
"DEFAULT_SCAN_INTERVAL",
")",
")",
",",
")"
] |
[
314,
4
] |
[
345,
9
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynoApi.subscribe
|
(self, api_key, unique_id)
|
Subscribe an entity from API fetches.
|
Subscribe an entity from API fetches.
|
def subscribe(self, api_key, unique_id):
"""Subscribe an entity from API fetches."""
if api_key not in self._fetching_entities:
self._fetching_entities[api_key] = set()
self._fetching_entities[api_key].add(unique_id)
@callback
def unsubscribe() -> None:
"""Unsubscribe an entity from API fetches (when disable)."""
self._fetching_entities[api_key].remove(unique_id)
return unsubscribe
|
[
"def",
"subscribe",
"(",
"self",
",",
"api_key",
",",
"unique_id",
")",
":",
"if",
"api_key",
"not",
"in",
"self",
".",
"_fetching_entities",
":",
"self",
".",
"_fetching_entities",
"[",
"api_key",
"]",
"=",
"set",
"(",
")",
"self",
".",
"_fetching_entities",
"[",
"api_key",
"]",
".",
"add",
"(",
"unique_id",
")",
"@",
"callback",
"def",
"unsubscribe",
"(",
")",
"->",
"None",
":",
"\"\"\"Unsubscribe an entity from API fetches (when disable).\"\"\"",
"self",
".",
"_fetching_entities",
"[",
"api_key",
"]",
".",
"remove",
"(",
"unique_id",
")",
"return",
"unsubscribe"
] |
[
348,
4
] |
[
359,
26
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynoApi._async_setup_api_requests
|
(self)
|
Determine if we should fetch each API, if one entity needs it.
|
Determine if we should fetch each API, if one entity needs it.
|
def _async_setup_api_requests(self):
"""Determine if we should fetch each API, if one entity needs it."""
# Entities not added yet, fetch all
if not self._fetching_entities:
return
# Determine if we should fetch an API
self._with_security = bool(
self._fetching_entities.get(SynoCoreSecurity.API_KEY)
)
self._with_storage = bool(self._fetching_entities.get(SynoStorage.API_KEY))
self._with_system = bool(self._fetching_entities.get(SynoCoreSystem.API_KEY))
self._with_upgrade = bool(self._fetching_entities.get(SynoCoreUpgrade.API_KEY))
self._with_utilisation = bool(
self._fetching_entities.get(SynoCoreUtilization.API_KEY)
)
self._with_information = bool(
self._fetching_entities.get(SynoDSMInformation.API_KEY)
)
self._with_surveillance_station = bool(
self._fetching_entities.get(SynoSurveillanceStation.CAMERA_API_KEY)
) or bool(
self._fetching_entities.get(SynoSurveillanceStation.HOME_MODE_API_KEY)
)
# Reset not used API, information is not reset since it's used in device_info
if not self._with_security:
self.dsm.reset(self.security)
self.security = None
if not self._with_storage:
self.dsm.reset(self.storage)
self.storage = None
if not self._with_system:
self.dsm.reset(self.system)
self.system = None
if not self._with_upgrade:
self.dsm.reset(self.upgrade)
self.upgrade = None
if not self._with_utilisation:
self.dsm.reset(self.utilisation)
self.utilisation = None
if not self._with_surveillance_station:
self.dsm.reset(self.surveillance_station)
self.surveillance_station = None
|
[
"def",
"_async_setup_api_requests",
"(",
"self",
")",
":",
"# Entities not added yet, fetch all",
"if",
"not",
"self",
".",
"_fetching_entities",
":",
"return",
"# Determine if we should fetch an API",
"self",
".",
"_with_security",
"=",
"bool",
"(",
"self",
".",
"_fetching_entities",
".",
"get",
"(",
"SynoCoreSecurity",
".",
"API_KEY",
")",
")",
"self",
".",
"_with_storage",
"=",
"bool",
"(",
"self",
".",
"_fetching_entities",
".",
"get",
"(",
"SynoStorage",
".",
"API_KEY",
")",
")",
"self",
".",
"_with_system",
"=",
"bool",
"(",
"self",
".",
"_fetching_entities",
".",
"get",
"(",
"SynoCoreSystem",
".",
"API_KEY",
")",
")",
"self",
".",
"_with_upgrade",
"=",
"bool",
"(",
"self",
".",
"_fetching_entities",
".",
"get",
"(",
"SynoCoreUpgrade",
".",
"API_KEY",
")",
")",
"self",
".",
"_with_utilisation",
"=",
"bool",
"(",
"self",
".",
"_fetching_entities",
".",
"get",
"(",
"SynoCoreUtilization",
".",
"API_KEY",
")",
")",
"self",
".",
"_with_information",
"=",
"bool",
"(",
"self",
".",
"_fetching_entities",
".",
"get",
"(",
"SynoDSMInformation",
".",
"API_KEY",
")",
")",
"self",
".",
"_with_surveillance_station",
"=",
"bool",
"(",
"self",
".",
"_fetching_entities",
".",
"get",
"(",
"SynoSurveillanceStation",
".",
"CAMERA_API_KEY",
")",
")",
"or",
"bool",
"(",
"self",
".",
"_fetching_entities",
".",
"get",
"(",
"SynoSurveillanceStation",
".",
"HOME_MODE_API_KEY",
")",
")",
"# Reset not used API, information is not reset since it's used in device_info",
"if",
"not",
"self",
".",
"_with_security",
":",
"self",
".",
"dsm",
".",
"reset",
"(",
"self",
".",
"security",
")",
"self",
".",
"security",
"=",
"None",
"if",
"not",
"self",
".",
"_with_storage",
":",
"self",
".",
"dsm",
".",
"reset",
"(",
"self",
".",
"storage",
")",
"self",
".",
"storage",
"=",
"None",
"if",
"not",
"self",
".",
"_with_system",
":",
"self",
".",
"dsm",
".",
"reset",
"(",
"self",
".",
"system",
")",
"self",
".",
"system",
"=",
"None",
"if",
"not",
"self",
".",
"_with_upgrade",
":",
"self",
".",
"dsm",
".",
"reset",
"(",
"self",
".",
"upgrade",
")",
"self",
".",
"upgrade",
"=",
"None",
"if",
"not",
"self",
".",
"_with_utilisation",
":",
"self",
".",
"dsm",
".",
"reset",
"(",
"self",
".",
"utilisation",
")",
"self",
".",
"utilisation",
"=",
"None",
"if",
"not",
"self",
".",
"_with_surveillance_station",
":",
"self",
".",
"dsm",
".",
"reset",
"(",
"self",
".",
"surveillance_station",
")",
"self",
".",
"surveillance_station",
"=",
"None"
] |
[
362,
4
] |
[
410,
44
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynoApi._fetch_device_configuration
|
(self)
|
Fetch initial device config.
|
Fetch initial device config.
|
def _fetch_device_configuration(self):
"""Fetch initial device config."""
self.information = self.dsm.information
self.network = self.dsm.network
self.network.update()
if self._with_security:
self.security = self.dsm.security
if self._with_storage:
self.storage = self.dsm.storage
if self._with_upgrade:
self.upgrade = self.dsm.upgrade
if self._with_system:
self.system = self.dsm.system
if self._with_utilisation:
self.utilisation = self.dsm.utilisation
if self._with_surveillance_station:
self.surveillance_station = self.dsm.surveillance_station
|
[
"def",
"_fetch_device_configuration",
"(",
"self",
")",
":",
"self",
".",
"information",
"=",
"self",
".",
"dsm",
".",
"information",
"self",
".",
"network",
"=",
"self",
".",
"dsm",
".",
"network",
"self",
".",
"network",
".",
"update",
"(",
")",
"if",
"self",
".",
"_with_security",
":",
"self",
".",
"security",
"=",
"self",
".",
"dsm",
".",
"security",
"if",
"self",
".",
"_with_storage",
":",
"self",
".",
"storage",
"=",
"self",
".",
"dsm",
".",
"storage",
"if",
"self",
".",
"_with_upgrade",
":",
"self",
".",
"upgrade",
"=",
"self",
".",
"dsm",
".",
"upgrade",
"if",
"self",
".",
"_with_system",
":",
"self",
".",
"system",
"=",
"self",
".",
"dsm",
".",
"system",
"if",
"self",
".",
"_with_utilisation",
":",
"self",
".",
"utilisation",
"=",
"self",
".",
"dsm",
".",
"utilisation",
"if",
"self",
".",
"_with_surveillance_station",
":",
"self",
".",
"surveillance_station",
"=",
"self",
".",
"dsm",
".",
"surveillance_station"
] |
[
412,
4
] |
[
434,
69
] |
python
|
en
|
['sv', 'en', 'en']
|
True
|
SynoApi.async_reboot
|
(self)
|
Reboot NAS.
|
Reboot NAS.
|
async def async_reboot(self):
"""Reboot NAS."""
if not self.system:
_LOGGER.debug("async_reboot - System API not ready: %s", self)
return
await self._hass.async_add_executor_job(self.system.reboot)
|
[
"async",
"def",
"async_reboot",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"system",
":",
"_LOGGER",
".",
"debug",
"(",
"\"async_reboot - System API not ready: %s\"",
",",
"self",
")",
"return",
"await",
"self",
".",
"_hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"system",
".",
"reboot",
")"
] |
[
436,
4
] |
[
441,
67
] |
python
|
en
|
['en', 'nl', 'en']
|
False
|
SynoApi.async_shutdown
|
(self)
|
Shutdown NAS.
|
Shutdown NAS.
|
async def async_shutdown(self):
"""Shutdown NAS."""
if not self.system:
_LOGGER.debug("async_shutdown - System API not ready: %s", self)
return
await self._hass.async_add_executor_job(self.system.shutdown)
|
[
"async",
"def",
"async_shutdown",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"system",
":",
"_LOGGER",
".",
"debug",
"(",
"\"async_shutdown - System API not ready: %s\"",
",",
"self",
")",
"return",
"await",
"self",
".",
"_hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"system",
".",
"shutdown",
")"
] |
[
443,
4
] |
[
448,
69
] |
python
|
en
|
['en', 'ja-Latn', 'en']
|
False
|
SynoApi.async_unload
|
(self)
|
Stop interacting with the NAS and prepare for removal from hass.
|
Stop interacting with the NAS and prepare for removal from hass.
|
async def async_unload(self):
"""Stop interacting with the NAS and prepare for removal from hass."""
self._unsub_dispatcher()
|
[
"async",
"def",
"async_unload",
"(",
"self",
")",
":",
"self",
".",
"_unsub_dispatcher",
"(",
")"
] |
[
450,
4
] |
[
452,
32
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynoApi.async_update
|
(self, now=None)
|
Update function for updating API information.
|
Update function for updating API information.
|
async def async_update(self, now=None):
"""Update function for updating API information."""
self._async_setup_api_requests()
try:
await self._hass.async_add_executor_job(
self.dsm.update, self._with_information
)
except (SynologyDSMLoginFailedException, SynologyDSMRequestException) as err:
_LOGGER.warning(
"async_update - connection error during update, fallback by reloading the entry"
)
_LOGGER.debug("async_update - exception: %s", err)
await self._hass.config_entries.async_reload(self._entry.entry_id)
return
async_dispatcher_send(self._hass, self.signal_sensor_update)
|
[
"async",
"def",
"async_update",
"(",
"self",
",",
"now",
"=",
"None",
")",
":",
"self",
".",
"_async_setup_api_requests",
"(",
")",
"try",
":",
"await",
"self",
".",
"_hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"dsm",
".",
"update",
",",
"self",
".",
"_with_information",
")",
"except",
"(",
"SynologyDSMLoginFailedException",
",",
"SynologyDSMRequestException",
")",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"async_update - connection error during update, fallback by reloading the entry\"",
")",
"_LOGGER",
".",
"debug",
"(",
"\"async_update - exception: %s\"",
",",
"err",
")",
"await",
"self",
".",
"_hass",
".",
"config_entries",
".",
"async_reload",
"(",
"self",
".",
"_entry",
".",
"entry_id",
")",
"return",
"async_dispatcher_send",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"signal_sensor_update",
")"
] |
[
454,
4
] |
[
468,
68
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.__init__
|
(
self,
api: SynoApi,
entity_type: str,
entity_info: Dict[str, str],
)
|
Initialize the Synology DSM entity.
|
Initialize the Synology DSM entity.
|
def __init__(
self,
api: SynoApi,
entity_type: str,
entity_info: Dict[str, str],
):
"""Initialize the Synology DSM entity."""
super().__init__()
self._api = api
self._api_key = entity_type.split(":")[0]
self.entity_type = entity_type.split(":")[-1]
self._name = f"{api.network.hostname} {entity_info[ENTITY_NAME]}"
self._class = entity_info[ENTITY_CLASS]
self._enable_default = entity_info[ENTITY_ENABLE]
self._icon = entity_info[ENTITY_ICON]
self._unit = entity_info[ENTITY_UNIT]
self._unique_id = f"{self._api.information.serial}_{entity_type}"
|
[
"def",
"__init__",
"(",
"self",
",",
"api",
":",
"SynoApi",
",",
"entity_type",
":",
"str",
",",
"entity_info",
":",
"Dict",
"[",
"str",
",",
"str",
"]",
",",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"_api",
"=",
"api",
"self",
".",
"_api_key",
"=",
"entity_type",
".",
"split",
"(",
"\":\"",
")",
"[",
"0",
"]",
"self",
".",
"entity_type",
"=",
"entity_type",
".",
"split",
"(",
"\":\"",
")",
"[",
"-",
"1",
"]",
"self",
".",
"_name",
"=",
"f\"{api.network.hostname} {entity_info[ENTITY_NAME]}\"",
"self",
".",
"_class",
"=",
"entity_info",
"[",
"ENTITY_CLASS",
"]",
"self",
".",
"_enable_default",
"=",
"entity_info",
"[",
"ENTITY_ENABLE",
"]",
"self",
".",
"_icon",
"=",
"entity_info",
"[",
"ENTITY_ICON",
"]",
"self",
".",
"_unit",
"=",
"entity_info",
"[",
"ENTITY_UNIT",
"]",
"self",
".",
"_unique_id",
"=",
"f\"{self._api.information.serial}_{entity_type}\""
] |
[
474,
4
] |
[
491,
73
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.unique_id
|
(self)
|
Return a unique ID.
|
Return a unique ID.
|
def unique_id(self) -> str:
"""Return a unique ID."""
return self._unique_id
|
[
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_unique_id"
] |
[
494,
4
] |
[
496,
30
] |
python
|
ca
|
['fr', 'ca', 'en']
|
False
|
SynologyDSMEntity.name
|
(self)
|
Return the name.
|
Return the name.
|
def name(self) -> str:
"""Return the name."""
return self._name
|
[
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_name"
] |
[
499,
4
] |
[
501,
25
] |
python
|
en
|
['en', 'ig', 'en']
|
True
|
SynologyDSMEntity.icon
|
(self)
|
Return the icon.
|
Return the icon.
|
def icon(self) -> str:
"""Return the icon."""
return self._icon
|
[
"def",
"icon",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_icon"
] |
[
504,
4
] |
[
506,
25
] |
python
|
en
|
['en', 'sr', 'en']
|
True
|
SynologyDSMEntity.unit_of_measurement
|
(self)
|
Return the unit the value is expressed in.
|
Return the unit the value is expressed in.
|
def unit_of_measurement(self) -> str:
"""Return the unit the value is expressed in."""
if self.entity_type in TEMP_SENSORS_KEYS:
return self.hass.config.units.temperature_unit
return self._unit
|
[
"def",
"unit_of_measurement",
"(",
"self",
")",
"->",
"str",
":",
"if",
"self",
".",
"entity_type",
"in",
"TEMP_SENSORS_KEYS",
":",
"return",
"self",
".",
"hass",
".",
"config",
".",
"units",
".",
"temperature_unit",
"return",
"self",
".",
"_unit"
] |
[
509,
4
] |
[
513,
25
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.device_class
|
(self)
|
Return the class of this device.
|
Return the class of this device.
|
def device_class(self) -> str:
"""Return the class of this device."""
return self._class
|
[
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_class"
] |
[
516,
4
] |
[
518,
26
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.device_state_attributes
|
(self)
|
Return the state attributes.
|
Return the state attributes.
|
def device_state_attributes(self) -> Dict[str, any]:
"""Return the state attributes."""
return {ATTR_ATTRIBUTION: ATTRIBUTION}
|
[
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"any",
"]",
":",
"return",
"{",
"ATTR_ATTRIBUTION",
":",
"ATTRIBUTION",
"}"
] |
[
521,
4
] |
[
523,
46
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.device_info
|
(self)
|
Return the device information.
|
Return the device information.
|
def device_info(self) -> Dict[str, any]:
"""Return the device information."""
return {
"identifiers": {(DOMAIN, self._api.information.serial)},
"name": "Synology NAS",
"manufacturer": "Synology",
"model": self._api.information.model,
"sw_version": self._api.information.version_string,
}
|
[
"def",
"device_info",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"any",
"]",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"_api",
".",
"information",
".",
"serial",
")",
"}",
",",
"\"name\"",
":",
"\"Synology NAS\"",
",",
"\"manufacturer\"",
":",
"\"Synology\"",
",",
"\"model\"",
":",
"self",
".",
"_api",
".",
"information",
".",
"model",
",",
"\"sw_version\"",
":",
"self",
".",
"_api",
".",
"information",
".",
"version_string",
",",
"}"
] |
[
526,
4
] |
[
534,
9
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.entity_registry_enabled_default
|
(self)
|
Return if the entity should be enabled when first added to the entity registry.
|
Return if the entity should be enabled when first added to the entity registry.
|
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return self._enable_default
|
[
"def",
"entity_registry_enabled_default",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_enable_default"
] |
[
537,
4
] |
[
539,
35
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.should_poll
|
(self)
|
No polling needed.
|
No polling needed.
|
def should_poll(self) -> bool:
"""No polling needed."""
return False
|
[
"def",
"should_poll",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"False"
] |
[
542,
4
] |
[
544,
20
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.async_update
|
(self)
|
Only used by the generic entity update service.
|
Only used by the generic entity update service.
|
async def async_update(self):
"""Only used by the generic entity update service."""
if not self.enabled:
return
await self._api.async_update()
|
[
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"enabled",
":",
"return",
"await",
"self",
".",
"_api",
".",
"async_update",
"(",
")"
] |
[
546,
4
] |
[
551,
38
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMEntity.async_added_to_hass
|
(self)
|
Register state update callback.
|
Register state update callback.
|
async def async_added_to_hass(self):
"""Register state update callback."""
self.async_on_remove(
async_dispatcher_connect(
self.hass, self._api.signal_sensor_update, self.async_write_ha_state
)
)
self.async_on_remove(self._api.subscribe(self._api_key, self.unique_id))
|
[
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_api",
".",
"signal_sensor_update",
",",
"self",
".",
"async_write_ha_state",
")",
")",
"self",
".",
"async_on_remove",
"(",
"self",
".",
"_api",
".",
"subscribe",
"(",
"self",
".",
"_api_key",
",",
"self",
".",
"unique_id",
")",
")"
] |
[
553,
4
] |
[
561,
80
] |
python
|
en
|
['en', 'co', 'en']
|
True
|
SynologyDSMDeviceEntity.__init__
|
(
self,
api: SynoApi,
entity_type: str,
entity_info: Dict[str, str],
device_id: str = None,
)
|
Initialize the Synology DSM disk or volume entity.
|
Initialize the Synology DSM disk or volume entity.
|
def __init__(
self,
api: SynoApi,
entity_type: str,
entity_info: Dict[str, str],
device_id: str = None,
):
"""Initialize the Synology DSM disk or volume entity."""
super().__init__(api, entity_type, entity_info)
self._device_id = device_id
self._device_name = None
self._device_manufacturer = None
self._device_model = None
self._device_firmware = None
self._device_type = None
if "volume" in entity_type:
volume = self._api.storage.get_volume(self._device_id)
# Volume does not have a name
self._device_name = volume["id"].replace("_", " ").capitalize()
self._device_manufacturer = "Synology"
self._device_model = self._api.information.model
self._device_firmware = self._api.information.version_string
self._device_type = (
volume["device_type"]
.replace("_", " ")
.replace("raid", "RAID")
.replace("shr", "SHR")
)
elif "disk" in entity_type:
disk = self._api.storage.get_disk(self._device_id)
self._device_name = disk["name"]
self._device_manufacturer = disk["vendor"]
self._device_model = disk["model"].strip()
self._device_firmware = disk["firm"]
self._device_type = disk["diskType"]
self._name = f"{self._api.network.hostname} {self._device_name} {entity_info[ENTITY_NAME]}"
self._unique_id += f"_{self._device_id}"
|
[
"def",
"__init__",
"(",
"self",
",",
"api",
":",
"SynoApi",
",",
"entity_type",
":",
"str",
",",
"entity_info",
":",
"Dict",
"[",
"str",
",",
"str",
"]",
",",
"device_id",
":",
"str",
"=",
"None",
",",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"api",
",",
"entity_type",
",",
"entity_info",
")",
"self",
".",
"_device_id",
"=",
"device_id",
"self",
".",
"_device_name",
"=",
"None",
"self",
".",
"_device_manufacturer",
"=",
"None",
"self",
".",
"_device_model",
"=",
"None",
"self",
".",
"_device_firmware",
"=",
"None",
"self",
".",
"_device_type",
"=",
"None",
"if",
"\"volume\"",
"in",
"entity_type",
":",
"volume",
"=",
"self",
".",
"_api",
".",
"storage",
".",
"get_volume",
"(",
"self",
".",
"_device_id",
")",
"# Volume does not have a name",
"self",
".",
"_device_name",
"=",
"volume",
"[",
"\"id\"",
"]",
".",
"replace",
"(",
"\"_\"",
",",
"\" \"",
")",
".",
"capitalize",
"(",
")",
"self",
".",
"_device_manufacturer",
"=",
"\"Synology\"",
"self",
".",
"_device_model",
"=",
"self",
".",
"_api",
".",
"information",
".",
"model",
"self",
".",
"_device_firmware",
"=",
"self",
".",
"_api",
".",
"information",
".",
"version_string",
"self",
".",
"_device_type",
"=",
"(",
"volume",
"[",
"\"device_type\"",
"]",
".",
"replace",
"(",
"\"_\"",
",",
"\" \"",
")",
".",
"replace",
"(",
"\"raid\"",
",",
"\"RAID\"",
")",
".",
"replace",
"(",
"\"shr\"",
",",
"\"SHR\"",
")",
")",
"elif",
"\"disk\"",
"in",
"entity_type",
":",
"disk",
"=",
"self",
".",
"_api",
".",
"storage",
".",
"get_disk",
"(",
"self",
".",
"_device_id",
")",
"self",
".",
"_device_name",
"=",
"disk",
"[",
"\"name\"",
"]",
"self",
".",
"_device_manufacturer",
"=",
"disk",
"[",
"\"vendor\"",
"]",
"self",
".",
"_device_model",
"=",
"disk",
"[",
"\"model\"",
"]",
".",
"strip",
"(",
")",
"self",
".",
"_device_firmware",
"=",
"disk",
"[",
"\"firm\"",
"]",
"self",
".",
"_device_type",
"=",
"disk",
"[",
"\"diskType\"",
"]",
"self",
".",
"_name",
"=",
"f\"{self._api.network.hostname} {self._device_name} {entity_info[ENTITY_NAME]}\"",
"self",
".",
"_unique_id",
"+=",
"f\"_{self._device_id}\""
] |
[
567,
4
] |
[
604,
48
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMDeviceEntity.available
|
(self)
|
Return True if entity is available.
|
Return True if entity is available.
|
def available(self) -> bool:
"""Return True if entity is available."""
return bool(self._api.storage)
|
[
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"bool",
"(",
"self",
".",
"_api",
".",
"storage",
")"
] |
[
607,
4
] |
[
609,
38
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
SynologyDSMDeviceEntity.device_info
|
(self)
|
Return the device information.
|
Return the device information.
|
def device_info(self) -> Dict[str, any]:
"""Return the device information."""
return {
"identifiers": {(DOMAIN, self._api.information.serial, self._device_id)},
"name": f"Synology NAS ({self._device_name} - {self._device_type})",
"manufacturer": self._device_manufacturer,
"model": self._device_model,
"sw_version": self._device_firmware,
"via_device": (DOMAIN, self._api.information.serial),
}
|
[
"def",
"device_info",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"any",
"]",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"_api",
".",
"information",
".",
"serial",
",",
"self",
".",
"_device_id",
")",
"}",
",",
"\"name\"",
":",
"f\"Synology NAS ({self._device_name} - {self._device_type})\"",
",",
"\"manufacturer\"",
":",
"self",
".",
"_device_manufacturer",
",",
"\"model\"",
":",
"self",
".",
"_device_model",
",",
"\"sw_version\"",
":",
"self",
".",
"_device_firmware",
",",
"\"via_device\"",
":",
"(",
"DOMAIN",
",",
"self",
".",
"_api",
".",
"information",
".",
"serial",
")",
",",
"}"
] |
[
612,
4
] |
[
621,
9
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
setup_platform
|
(hass, config, add_entities, discovery_info=None)
|
Set up PwrCtrl devices/switches.
|
Set up PwrCtrl devices/switches.
|
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up PwrCtrl devices/switches."""
host = config.get(CONF_HOST)
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
port_recv = config[CONF_PORT_RECV]
port_send = config[CONF_PORT_SEND]
try:
master = DeviceMaster(
username=username,
password=password,
read_port=port_send,
write_port=port_recv,
)
master.query(ip_addr=host)
except OSError as ex:
_LOGGER.error("Unable to discover PwrCtrl device: %s", str(ex))
return False
devices = []
for device in master.devices.values():
parent_device = PwrCtrlDevice(device)
devices.extend(
PwrCtrlSwitch(switch, parent_device) for switch in device.switches.values()
)
add_entities(devices)
|
[
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
"username",
"=",
"config",
"[",
"CONF_USERNAME",
"]",
"password",
"=",
"config",
"[",
"CONF_PASSWORD",
"]",
"port_recv",
"=",
"config",
"[",
"CONF_PORT_RECV",
"]",
"port_send",
"=",
"config",
"[",
"CONF_PORT_SEND",
"]",
"try",
":",
"master",
"=",
"DeviceMaster",
"(",
"username",
"=",
"username",
",",
"password",
"=",
"password",
",",
"read_port",
"=",
"port_send",
",",
"write_port",
"=",
"port_recv",
",",
")",
"master",
".",
"query",
"(",
"ip_addr",
"=",
"host",
")",
"except",
"OSError",
"as",
"ex",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unable to discover PwrCtrl device: %s\"",
",",
"str",
"(",
"ex",
")",
")",
"return",
"False",
"devices",
"=",
"[",
"]",
"for",
"device",
"in",
"master",
".",
"devices",
".",
"values",
"(",
")",
":",
"parent_device",
"=",
"PwrCtrlDevice",
"(",
"device",
")",
"devices",
".",
"extend",
"(",
"PwrCtrlSwitch",
"(",
"switch",
",",
"parent_device",
")",
"for",
"switch",
"in",
"device",
".",
"switches",
".",
"values",
"(",
")",
")",
"add_entities",
"(",
"devices",
")"
] |
[
30,
0
] |
[
57,
25
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwrCtrlSwitch.__init__
|
(self, port, parent_device)
|
Initialize the PwrCtrl switch.
|
Initialize the PwrCtrl switch.
|
def __init__(self, port, parent_device):
"""Initialize the PwrCtrl switch."""
self._port = port
self._parent_device = parent_device
|
[
"def",
"__init__",
"(",
"self",
",",
"port",
",",
"parent_device",
")",
":",
"self",
".",
"_port",
"=",
"port",
"self",
".",
"_parent_device",
"=",
"parent_device"
] |
[
63,
4
] |
[
66,
43
] |
python
|
en
|
['en', 'pl', 'en']
|
True
|
PwrCtrlSwitch.unique_id
|
(self)
|
Return the unique ID of the device.
|
Return the unique ID of the device.
|
def unique_id(self):
"""Return the unique ID of the device."""
return f"{self._port.device.host}-{self._port.get_index()}"
|
[
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self._port.device.host}-{self._port.get_index()}\""
] |
[
69,
4
] |
[
71,
67
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwrCtrlSwitch.name
|
(self)
|
Return the name of the device.
|
Return the name of the device.
|
def name(self):
"""Return the name of the device."""
return self._port.label
|
[
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_port",
".",
"label"
] |
[
74,
4
] |
[
76,
31
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwrCtrlSwitch.is_on
|
(self)
|
Return true if the device is on.
|
Return true if the device is on.
|
def is_on(self):
"""Return true if the device is on."""
return self._port.get_state()
|
[
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_port",
".",
"get_state",
"(",
")"
] |
[
79,
4
] |
[
81,
37
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwrCtrlSwitch.update
|
(self)
|
Trigger update for all switches on the parent device.
|
Trigger update for all switches on the parent device.
|
def update(self):
"""Trigger update for all switches on the parent device."""
self._parent_device.update()
|
[
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_parent_device",
".",
"update",
"(",
")"
] |
[
83,
4
] |
[
85,
36
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwrCtrlSwitch.turn_on
|
(self, **kwargs)
|
Turn the switch on.
|
Turn the switch on.
|
def turn_on(self, **kwargs):
"""Turn the switch on."""
self._port.on()
|
[
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_port",
".",
"on",
"(",
")"
] |
[
87,
4
] |
[
89,
23
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwrCtrlSwitch.turn_off
|
(self, **kwargs)
|
Turn the switch off.
|
Turn the switch off.
|
def turn_off(self, **kwargs):
"""Turn the switch off."""
self._port.off()
|
[
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_port",
".",
"off",
"(",
")"
] |
[
91,
4
] |
[
93,
24
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwrCtrlDevice.__init__
|
(self, device)
|
Initialize the PwrCtrl device.
|
Initialize the PwrCtrl device.
|
def __init__(self, device):
"""Initialize the PwrCtrl device."""
self._device = device
|
[
"def",
"__init__",
"(",
"self",
",",
"device",
")",
":",
"self",
".",
"_device",
"=",
"device"
] |
[
99,
4
] |
[
101,
29
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwrCtrlDevice.update
|
(self)
|
Update the device and all its switches.
|
Update the device and all its switches.
|
def update(self):
"""Update the device and all its switches."""
self._device.update()
|
[
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_device",
".",
"update",
"(",
")"
] |
[
104,
4
] |
[
106,
29
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
async_attach_trigger
|
(
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: dict,
)
|
Listen for state changes based on configuration.
|
Listen for state changes based on configuration.
|
async def async_attach_trigger(
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: dict,
) -> CALLBACK_TYPE:
"""Listen for state changes based on configuration."""
return await toggle_entity.async_attach_trigger(
hass, config, action, automation_info
)
|
[
"async",
"def",
"async_attach_trigger",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"ConfigType",
",",
"action",
":",
"AutomationActionType",
",",
"automation_info",
":",
"dict",
",",
")",
"->",
"CALLBACK_TYPE",
":",
"return",
"await",
"toggle_entity",
".",
"async_attach_trigger",
"(",
"hass",
",",
"config",
",",
"action",
",",
"automation_info",
")"
] |
[
18,
0
] |
[
27,
5
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
async_get_triggers
|
(hass: HomeAssistant, device_id: str)
|
List device triggers.
|
List device triggers.
|
async def async_get_triggers(hass: HomeAssistant, device_id: str) -> List[dict]:
"""List device triggers."""
return await toggle_entity.async_get_triggers(hass, device_id, DOMAIN)
|
[
"async",
"def",
"async_get_triggers",
"(",
"hass",
":",
"HomeAssistant",
",",
"device_id",
":",
"str",
")",
"->",
"List",
"[",
"dict",
"]",
":",
"return",
"await",
"toggle_entity",
".",
"async_get_triggers",
"(",
"hass",
",",
"device_id",
",",
"DOMAIN",
")"
] |
[
30,
0
] |
[
32,
74
] |
python
|
en
|
['fr', 'en', 'en']
|
True
|
async_get_trigger_capabilities
|
(hass: HomeAssistant, config: dict)
|
List trigger capabilities.
|
List trigger capabilities.
|
async def async_get_trigger_capabilities(hass: HomeAssistant, config: dict) -> dict:
"""List trigger capabilities."""
return await toggle_entity.async_get_trigger_capabilities(hass, config)
|
[
"async",
"def",
"async_get_trigger_capabilities",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
")",
"->",
"dict",
":",
"return",
"await",
"toggle_entity",
".",
"async_get_trigger_capabilities",
"(",
"hass",
",",
"config",
")"
] |
[
35,
0
] |
[
37,
75
] |
python
|
en
|
['en', 'la', 'en']
|
True
|
setup_platform
|
(hass, config, add_entities, discovery_info=None)
|
Set up the PWM LED lights.
|
Set up the PWM LED lights.
|
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the PWM LED lights."""
leds = []
for led_conf in config[CONF_LEDS]:
driver_type = led_conf[CONF_DRIVER]
pins = led_conf[CONF_PINS]
opt_args = {}
if CONF_FREQUENCY in led_conf:
opt_args["freq"] = led_conf[CONF_FREQUENCY]
if driver_type == CONF_DRIVER_GPIO:
if CONF_HOST in led_conf:
opt_args["host"] = led_conf[CONF_HOST]
driver = GpioDriver(pins, **opt_args)
elif driver_type == CONF_DRIVER_PCA9685:
if CONF_ADDRESS in led_conf:
opt_args["address"] = led_conf[CONF_ADDRESS]
driver = Pca9685Driver(pins, **opt_args)
else:
_LOGGER.error("Invalid driver type")
return
name = led_conf[CONF_NAME]
led_type = led_conf[CONF_TYPE]
if led_type == CONF_LED_TYPE_SIMPLE:
led = PwmSimpleLed(SimpleLed(driver), name)
elif led_type == CONF_LED_TYPE_RGB:
led = PwmRgbLed(RgbLed(driver), name)
elif led_type == CONF_LED_TYPE_RGBW:
led = PwmRgbLed(RgbwLed(driver), name)
else:
_LOGGER.error("Invalid led type")
return
leds.append(led)
add_entities(leds)
|
[
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"leds",
"=",
"[",
"]",
"for",
"led_conf",
"in",
"config",
"[",
"CONF_LEDS",
"]",
":",
"driver_type",
"=",
"led_conf",
"[",
"CONF_DRIVER",
"]",
"pins",
"=",
"led_conf",
"[",
"CONF_PINS",
"]",
"opt_args",
"=",
"{",
"}",
"if",
"CONF_FREQUENCY",
"in",
"led_conf",
":",
"opt_args",
"[",
"\"freq\"",
"]",
"=",
"led_conf",
"[",
"CONF_FREQUENCY",
"]",
"if",
"driver_type",
"==",
"CONF_DRIVER_GPIO",
":",
"if",
"CONF_HOST",
"in",
"led_conf",
":",
"opt_args",
"[",
"\"host\"",
"]",
"=",
"led_conf",
"[",
"CONF_HOST",
"]",
"driver",
"=",
"GpioDriver",
"(",
"pins",
",",
"*",
"*",
"opt_args",
")",
"elif",
"driver_type",
"==",
"CONF_DRIVER_PCA9685",
":",
"if",
"CONF_ADDRESS",
"in",
"led_conf",
":",
"opt_args",
"[",
"\"address\"",
"]",
"=",
"led_conf",
"[",
"CONF_ADDRESS",
"]",
"driver",
"=",
"Pca9685Driver",
"(",
"pins",
",",
"*",
"*",
"opt_args",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid driver type\"",
")",
"return",
"name",
"=",
"led_conf",
"[",
"CONF_NAME",
"]",
"led_type",
"=",
"led_conf",
"[",
"CONF_TYPE",
"]",
"if",
"led_type",
"==",
"CONF_LED_TYPE_SIMPLE",
":",
"led",
"=",
"PwmSimpleLed",
"(",
"SimpleLed",
"(",
"driver",
")",
",",
"name",
")",
"elif",
"led_type",
"==",
"CONF_LED_TYPE_RGB",
":",
"led",
"=",
"PwmRgbLed",
"(",
"RgbLed",
"(",
"driver",
")",
",",
"name",
")",
"elif",
"led_type",
"==",
"CONF_LED_TYPE_RGBW",
":",
"led",
"=",
"PwmRgbLed",
"(",
"RgbwLed",
"(",
"driver",
")",
",",
"name",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid led type\"",
")",
"return",
"leds",
".",
"append",
"(",
"led",
")",
"add_entities",
"(",
"leds",
")"
] |
[
68,
0
] |
[
103,
22
] |
python
|
en
|
['en', 'bg', 'en']
|
True
|
_from_hass_brightness
|
(brightness)
|
Convert Home Assistant brightness units to percentage.
|
Convert Home Assistant brightness units to percentage.
|
def _from_hass_brightness(brightness):
"""Convert Home Assistant brightness units to percentage."""
return brightness / 255
|
[
"def",
"_from_hass_brightness",
"(",
"brightness",
")",
":",
"return",
"brightness",
"/",
"255"
] |
[
235,
0
] |
[
237,
27
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
_from_hass_color
|
(color)
|
Convert Home Assistant RGB list to Color tuple.
|
Convert Home Assistant RGB list to Color tuple.
|
def _from_hass_color(color):
"""Convert Home Assistant RGB list to Color tuple."""
rgb = color_util.color_hs_to_RGB(*color)
return Color(*tuple(rgb))
|
[
"def",
"_from_hass_color",
"(",
"color",
")",
":",
"rgb",
"=",
"color_util",
".",
"color_hs_to_RGB",
"(",
"*",
"color",
")",
"return",
"Color",
"(",
"*",
"tuple",
"(",
"rgb",
")",
")"
] |
[
240,
0
] |
[
244,
29
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwmSimpleLed.__init__
|
(self, led, name)
|
Initialize one-color PWM LED.
|
Initialize one-color PWM LED.
|
def __init__(self, led, name):
"""Initialize one-color PWM LED."""
self._led = led
self._name = name
self._is_on = False
self._brightness = DEFAULT_BRIGHTNESS
|
[
"def",
"__init__",
"(",
"self",
",",
"led",
",",
"name",
")",
":",
"self",
".",
"_led",
"=",
"led",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_is_on",
"=",
"False",
"self",
".",
"_brightness",
"=",
"DEFAULT_BRIGHTNESS"
] |
[
109,
4
] |
[
114,
45
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwmSimpleLed.async_added_to_hass
|
(self)
|
Handle entity about to be added to hass event.
|
Handle entity about to be added to hass event.
|
async def async_added_to_hass(self):
"""Handle entity about to be added to hass event."""
await super().async_added_to_hass()
last_state = await self.async_get_last_state()
if last_state:
self._is_on = last_state.state == STATE_ON
self._brightness = last_state.attributes.get(
"brightness", DEFAULT_BRIGHTNESS
)
|
[
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_added_to_hass",
"(",
")",
"last_state",
"=",
"await",
"self",
".",
"async_get_last_state",
"(",
")",
"if",
"last_state",
":",
"self",
".",
"_is_on",
"=",
"last_state",
".",
"state",
"==",
"STATE_ON",
"self",
".",
"_brightness",
"=",
"last_state",
".",
"attributes",
".",
"get",
"(",
"\"brightness\"",
",",
"DEFAULT_BRIGHTNESS",
")"
] |
[
116,
4
] |
[
124,
13
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwmSimpleLed.should_poll
|
(self)
|
No polling needed.
|
No polling needed.
|
def should_poll(self):
"""No polling needed."""
return False
|
[
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] |
[
127,
4
] |
[
129,
20
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwmSimpleLed.name
|
(self)
|
Return the name of the group.
|
Return the name of the group.
|
def name(self):
"""Return the name of the group."""
return self._name
|
[
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] |
[
132,
4
] |
[
134,
25
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwmSimpleLed.is_on
|
(self)
|
Return true if device is on.
|
Return true if device is on.
|
def is_on(self):
"""Return true if device is on."""
return self._is_on
|
[
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_is_on"
] |
[
137,
4
] |
[
139,
26
] |
python
|
en
|
['en', 'fy', 'en']
|
True
|
PwmSimpleLed.brightness
|
(self)
|
Return the brightness property.
|
Return the brightness property.
|
def brightness(self):
"""Return the brightness property."""
return self._brightness
|
[
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_brightness"
] |
[
142,
4
] |
[
144,
31
] |
python
|
en
|
['en', 'ru-Latn', 'en']
|
True
|
PwmSimpleLed.supported_features
|
(self)
|
Flag supported features.
|
Flag supported features.
|
def supported_features(self):
"""Flag supported features."""
return SUPPORT_SIMPLE_LED
|
[
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_SIMPLE_LED"
] |
[
147,
4
] |
[
149,
33
] |
python
|
en
|
['da', 'en', 'en']
|
True
|
PwmSimpleLed.turn_on
|
(self, **kwargs)
|
Turn on a led.
|
Turn on a led.
|
def turn_on(self, **kwargs):
"""Turn on a led."""
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
if ATTR_TRANSITION in kwargs:
transition_time = kwargs[ATTR_TRANSITION]
self._led.transition(
transition_time,
is_on=True,
brightness=_from_hass_brightness(self._brightness),
)
else:
self._led.set(
is_on=True, brightness=_from_hass_brightness(self._brightness)
)
self._is_on = True
self.schedule_update_ha_state()
|
[
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"ATTR_BRIGHTNESS",
"in",
"kwargs",
":",
"self",
".",
"_brightness",
"=",
"kwargs",
"[",
"ATTR_BRIGHTNESS",
"]",
"if",
"ATTR_TRANSITION",
"in",
"kwargs",
":",
"transition_time",
"=",
"kwargs",
"[",
"ATTR_TRANSITION",
"]",
"self",
".",
"_led",
".",
"transition",
"(",
"transition_time",
",",
"is_on",
"=",
"True",
",",
"brightness",
"=",
"_from_hass_brightness",
"(",
"self",
".",
"_brightness",
")",
",",
")",
"else",
":",
"self",
".",
"_led",
".",
"set",
"(",
"is_on",
"=",
"True",
",",
"brightness",
"=",
"_from_hass_brightness",
"(",
"self",
".",
"_brightness",
")",
")",
"self",
".",
"_is_on",
"=",
"True",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] |
[
151,
4
] |
[
169,
39
] |
python
|
en
|
['en', 'haw', 'en']
|
True
|
PwmSimpleLed.turn_off
|
(self, **kwargs)
|
Turn off a LED.
|
Turn off a LED.
|
def turn_off(self, **kwargs):
"""Turn off a LED."""
if self.is_on:
if ATTR_TRANSITION in kwargs:
transition_time = kwargs[ATTR_TRANSITION]
self._led.transition(transition_time, is_on=False)
else:
self._led.off()
self._is_on = False
self.schedule_update_ha_state()
|
[
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"is_on",
":",
"if",
"ATTR_TRANSITION",
"in",
"kwargs",
":",
"transition_time",
"=",
"kwargs",
"[",
"ATTR_TRANSITION",
"]",
"self",
".",
"_led",
".",
"transition",
"(",
"transition_time",
",",
"is_on",
"=",
"False",
")",
"else",
":",
"self",
".",
"_led",
".",
"off",
"(",
")",
"self",
".",
"_is_on",
"=",
"False",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] |
[
171,
4
] |
[
181,
39
] |
python
|
en
|
['en', 'bg', 'en']
|
True
|
PwmRgbLed.__init__
|
(self, led, name)
|
Initialize a RGB(W) PWM LED.
|
Initialize a RGB(W) PWM LED.
|
def __init__(self, led, name):
"""Initialize a RGB(W) PWM LED."""
super().__init__(led, name)
self._color = DEFAULT_COLOR
|
[
"def",
"__init__",
"(",
"self",
",",
"led",
",",
"name",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"led",
",",
"name",
")",
"self",
".",
"_color",
"=",
"DEFAULT_COLOR"
] |
[
187,
4
] |
[
190,
35
] |
python
|
en
|
['en', 'pl', 'it']
|
False
|
PwmRgbLed.async_added_to_hass
|
(self)
|
Handle entity about to be added to hass event.
|
Handle entity about to be added to hass event.
|
async def async_added_to_hass(self):
"""Handle entity about to be added to hass event."""
await super().async_added_to_hass()
last_state = await self.async_get_last_state()
if last_state:
self._color = last_state.attributes.get("hs_color", DEFAULT_COLOR)
|
[
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_added_to_hass",
"(",
")",
"last_state",
"=",
"await",
"self",
".",
"async_get_last_state",
"(",
")",
"if",
"last_state",
":",
"self",
".",
"_color",
"=",
"last_state",
".",
"attributes",
".",
"get",
"(",
"\"hs_color\"",
",",
"DEFAULT_COLOR",
")"
] |
[
192,
4
] |
[
197,
78
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwmRgbLed.hs_color
|
(self)
|
Return the color property.
|
Return the color property.
|
def hs_color(self):
"""Return the color property."""
return self._color
|
[
"def",
"hs_color",
"(",
"self",
")",
":",
"return",
"self",
".",
"_color"
] |
[
200,
4
] |
[
202,
26
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
PwmRgbLed.supported_features
|
(self)
|
Flag supported features.
|
Flag supported features.
|
def supported_features(self):
"""Flag supported features."""
return SUPPORT_RGB_LED
|
[
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_RGB_LED"
] |
[
205,
4
] |
[
207,
30
] |
python
|
en
|
['da', 'en', 'en']
|
True
|
PwmRgbLed.turn_on
|
(self, **kwargs)
|
Turn on a LED.
|
Turn on a LED.
|
def turn_on(self, **kwargs):
"""Turn on a LED."""
if ATTR_HS_COLOR in kwargs:
self._color = kwargs[ATTR_HS_COLOR]
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
if ATTR_TRANSITION in kwargs:
transition_time = kwargs[ATTR_TRANSITION]
self._led.transition(
transition_time,
is_on=True,
brightness=_from_hass_brightness(self._brightness),
color=_from_hass_color(self._color),
)
else:
self._led.set(
is_on=True,
brightness=_from_hass_brightness(self._brightness),
color=_from_hass_color(self._color),
)
self._is_on = True
self.schedule_update_ha_state()
|
[
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"ATTR_HS_COLOR",
"in",
"kwargs",
":",
"self",
".",
"_color",
"=",
"kwargs",
"[",
"ATTR_HS_COLOR",
"]",
"if",
"ATTR_BRIGHTNESS",
"in",
"kwargs",
":",
"self",
".",
"_brightness",
"=",
"kwargs",
"[",
"ATTR_BRIGHTNESS",
"]",
"if",
"ATTR_TRANSITION",
"in",
"kwargs",
":",
"transition_time",
"=",
"kwargs",
"[",
"ATTR_TRANSITION",
"]",
"self",
".",
"_led",
".",
"transition",
"(",
"transition_time",
",",
"is_on",
"=",
"True",
",",
"brightness",
"=",
"_from_hass_brightness",
"(",
"self",
".",
"_brightness",
")",
",",
"color",
"=",
"_from_hass_color",
"(",
"self",
".",
"_color",
")",
",",
")",
"else",
":",
"self",
".",
"_led",
".",
"set",
"(",
"is_on",
"=",
"True",
",",
"brightness",
"=",
"_from_hass_brightness",
"(",
"self",
".",
"_brightness",
")",
",",
"color",
"=",
"_from_hass_color",
"(",
"self",
".",
"_color",
")",
",",
")",
"self",
".",
"_is_on",
"=",
"True",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] |
[
209,
4
] |
[
232,
39
] |
python
|
en
|
['en', 'haw', 'en']
|
True
|
async_setup_entry
|
(
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable
)
|
Record the async_add_entities function to add them later when received from Dynalite.
|
Record the async_add_entities function to add them later when received from Dynalite.
|
async def async_setup_entry(
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable
) -> None:
"""Record the async_add_entities function to add them later when received from Dynalite."""
@callback
def cover_from_device(device, bridge):
if device.has_tilt:
return DynaliteCoverWithTilt(device, bridge)
return DynaliteCover(device, bridge)
async_setup_entry_base(
hass, config_entry, async_add_entities, "cover", cover_from_device
)
|
[
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"config_entry",
":",
"ConfigEntry",
",",
"async_add_entities",
":",
"Callable",
")",
"->",
"None",
":",
"@",
"callback",
"def",
"cover_from_device",
"(",
"device",
",",
"bridge",
")",
":",
"if",
"device",
".",
"has_tilt",
":",
"return",
"DynaliteCoverWithTilt",
"(",
"device",
",",
"bridge",
")",
"return",
"DynaliteCover",
"(",
"device",
",",
"bridge",
")",
"async_setup_entry_base",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
",",
"\"cover\"",
",",
"cover_from_device",
")"
] |
[
16,
0
] |
[
29,
5
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.device_class
|
(self)
|
Return the class of the device.
|
Return the class of the device.
|
def device_class(self) -> str:
"""Return the class of the device."""
dev_cls = self._device.device_class
ret_val = DEFAULT_COVER_CLASS
if dev_cls in DEVICE_CLASSES:
ret_val = dev_cls
return ret_val
|
[
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"dev_cls",
"=",
"self",
".",
"_device",
".",
"device_class",
"ret_val",
"=",
"DEFAULT_COVER_CLASS",
"if",
"dev_cls",
"in",
"DEVICE_CLASSES",
":",
"ret_val",
"=",
"dev_cls",
"return",
"ret_val"
] |
[
36,
4
] |
[
42,
22
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.current_cover_position
|
(self)
|
Return the position of the cover from 0 to 100.
|
Return the position of the cover from 0 to 100.
|
def current_cover_position(self) -> int:
"""Return the position of the cover from 0 to 100."""
return self._device.current_cover_position
|
[
"def",
"current_cover_position",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_device",
".",
"current_cover_position"
] |
[
45,
4
] |
[
47,
50
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.is_opening
|
(self)
|
Return true if cover is opening.
|
Return true if cover is opening.
|
def is_opening(self) -> bool:
"""Return true if cover is opening."""
return self._device.is_opening
|
[
"def",
"is_opening",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"is_opening"
] |
[
50,
4
] |
[
52,
38
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.is_closing
|
(self)
|
Return true if cover is closing.
|
Return true if cover is closing.
|
def is_closing(self) -> bool:
"""Return true if cover is closing."""
return self._device.is_closing
|
[
"def",
"is_closing",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"is_closing"
] |
[
55,
4
] |
[
57,
38
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.is_closed
|
(self)
|
Return true if cover is closed.
|
Return true if cover is closed.
|
def is_closed(self) -> bool:
"""Return true if cover is closed."""
return self._device.is_closed
|
[
"def",
"is_closed",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"is_closed"
] |
[
60,
4
] |
[
62,
37
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.async_open_cover
|
(self, **kwargs)
|
Open the cover.
|
Open the cover.
|
async def async_open_cover(self, **kwargs) -> None:
"""Open the cover."""
await self._device.async_open_cover(**kwargs)
|
[
"async",
"def",
"async_open_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"_device",
".",
"async_open_cover",
"(",
"*",
"*",
"kwargs",
")"
] |
[
64,
4
] |
[
66,
53
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.async_close_cover
|
(self, **kwargs)
|
Close the cover.
|
Close the cover.
|
async def async_close_cover(self, **kwargs) -> None:
"""Close the cover."""
await self._device.async_close_cover(**kwargs)
|
[
"async",
"def",
"async_close_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"_device",
".",
"async_close_cover",
"(",
"*",
"*",
"kwargs",
")"
] |
[
68,
4
] |
[
70,
54
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.async_set_cover_position
|
(self, **kwargs)
|
Set the cover position.
|
Set the cover position.
|
async def async_set_cover_position(self, **kwargs) -> None:
"""Set the cover position."""
await self._device.async_set_cover_position(**kwargs)
|
[
"async",
"def",
"async_set_cover_position",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"_device",
".",
"async_set_cover_position",
"(",
"*",
"*",
"kwargs",
")"
] |
[
72,
4
] |
[
74,
61
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCover.async_stop_cover
|
(self, **kwargs)
|
Stop the cover.
|
Stop the cover.
|
async def async_stop_cover(self, **kwargs) -> None:
"""Stop the cover."""
await self._device.async_stop_cover(**kwargs)
|
[
"async",
"def",
"async_stop_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"_device",
".",
"async_stop_cover",
"(",
"*",
"*",
"kwargs",
")"
] |
[
76,
4
] |
[
78,
53
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
DynaliteCoverWithTilt.current_cover_tilt_position
|
(self)
|
Return the current tilt position.
|
Return the current tilt position.
|
def current_cover_tilt_position(self) -> int:
"""Return the current tilt position."""
return self._device.current_cover_tilt_position
|
[
"def",
"current_cover_tilt_position",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_device",
".",
"current_cover_tilt_position"
] |
[
85,
4
] |
[
87,
55
] |
python
|
en
|
['en', 'da', 'en']
|
True
|
DynaliteCoverWithTilt.async_open_cover_tilt
|
(self, **kwargs)
|
Open cover tilt.
|
Open cover tilt.
|
async def async_open_cover_tilt(self, **kwargs) -> None:
"""Open cover tilt."""
await self._device.async_open_cover_tilt(**kwargs)
|
[
"async",
"def",
"async_open_cover_tilt",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"_device",
".",
"async_open_cover_tilt",
"(",
"*",
"*",
"kwargs",
")"
] |
[
89,
4
] |
[
91,
58
] |
python
|
da
|
['da', 'no', 'en']
|
False
|
DynaliteCoverWithTilt.async_close_cover_tilt
|
(self, **kwargs)
|
Close cover tilt.
|
Close cover tilt.
|
async def async_close_cover_tilt(self, **kwargs) -> None:
"""Close cover tilt."""
await self._device.async_close_cover_tilt(**kwargs)
|
[
"async",
"def",
"async_close_cover_tilt",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"_device",
".",
"async_close_cover_tilt",
"(",
"*",
"*",
"kwargs",
")"
] |
[
93,
4
] |
[
95,
59
] |
python
|
da
|
['da', 'fr', 'en']
|
False
|
DynaliteCoverWithTilt.async_set_cover_tilt_position
|
(self, **kwargs)
|
Set the cover tilt position.
|
Set the cover tilt position.
|
async def async_set_cover_tilt_position(self, **kwargs) -> None:
"""Set the cover tilt position."""
await self._device.async_set_cover_tilt_position(**kwargs)
|
[
"async",
"def",
"async_set_cover_tilt_position",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"_device",
".",
"async_set_cover_tilt_position",
"(",
"*",
"*",
"kwargs",
")"
] |
[
97,
4
] |
[
99,
66
] |
python
|
en
|
['en', 'fr', 'en']
|
True
|
DynaliteCoverWithTilt.async_stop_cover_tilt
|
(self, **kwargs)
|
Stop the cover tilt.
|
Stop the cover tilt.
|
async def async_stop_cover_tilt(self, **kwargs) -> None:
"""Stop the cover tilt."""
await self._device.async_stop_cover_tilt(**kwargs)
|
[
"async",
"def",
"async_stop_cover_tilt",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"_device",
".",
"async_stop_cover_tilt",
"(",
"*",
"*",
"kwargs",
")"
] |
[
101,
4
] |
[
103,
58
] |
python
|
en
|
['en', 'no', 'en']
|
True
|
async_setup
|
(hass: HomeAssistant, config: dict)
|
Set up the Monoprice 6-Zone Amplifier component.
|
Set up the Monoprice 6-Zone Amplifier component.
|
async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the Monoprice 6-Zone Amplifier component."""
return True
|
[
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
")",
":",
"return",
"True"
] |
[
25,
0
] |
[
27,
15
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
async_setup_entry
|
(hass: HomeAssistant, entry: ConfigEntry)
|
Set up Monoprice 6-Zone Amplifier from a config entry.
|
Set up Monoprice 6-Zone Amplifier from a config entry.
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up Monoprice 6-Zone Amplifier from a config entry."""
port = entry.data[CONF_PORT]
try:
monoprice = await hass.async_add_executor_job(get_monoprice, port)
except SerialException as err:
_LOGGER.error("Error connecting to Monoprice controller at %s", port)
raise ConfigEntryNotReady from err
# double negative to handle absence of value
first_run = not bool(entry.data.get(CONF_NOT_FIRST_RUN))
if first_run:
hass.config_entries.async_update_entry(
entry, data={**entry.data, CONF_NOT_FIRST_RUN: True}
)
undo_listener = entry.add_update_listener(_update_listener)
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
MONOPRICE_OBJECT: monoprice,
UNDO_UPDATE_LISTENER: undo_listener,
FIRST_RUN: first_run,
}
for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)
return True
|
[
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"port",
"=",
"entry",
".",
"data",
"[",
"CONF_PORT",
"]",
"try",
":",
"monoprice",
"=",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"get_monoprice",
",",
"port",
")",
"except",
"SerialException",
"as",
"err",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error connecting to Monoprice controller at %s\"",
",",
"port",
")",
"raise",
"ConfigEntryNotReady",
"from",
"err",
"# double negative to handle absence of value",
"first_run",
"=",
"not",
"bool",
"(",
"entry",
".",
"data",
".",
"get",
"(",
"CONF_NOT_FIRST_RUN",
")",
")",
"if",
"first_run",
":",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"entry",
",",
"data",
"=",
"{",
"*",
"*",
"entry",
".",
"data",
",",
"CONF_NOT_FIRST_RUN",
":",
"True",
"}",
")",
"undo_listener",
"=",
"entry",
".",
"add_update_listener",
"(",
"_update_listener",
")",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"[",
"entry",
".",
"entry_id",
"]",
"=",
"{",
"MONOPRICE_OBJECT",
":",
"monoprice",
",",
"UNDO_UPDATE_LISTENER",
":",
"undo_listener",
",",
"FIRST_RUN",
":",
"first_run",
",",
"}",
"for",
"component",
"in",
"PLATFORMS",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"entry",
",",
"component",
")",
")",
"return",
"True"
] |
[
30,
0
] |
[
61,
15
] |
python
|
en
|
['en', 'en', 'en']
|
True
|
async_unload_entry
|
(hass: HomeAssistant, entry: ConfigEntry)
|
Unload a config entry.
|
Unload a config entry.
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, component)
for component in PLATFORMS
]
)
)
if unload_ok:
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok
|
[
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"unload_ok",
"=",
"all",
"(",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"entry",
",",
"component",
")",
"for",
"component",
"in",
"PLATFORMS",
"]",
")",
")",
"if",
"unload_ok",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"UNDO_UPDATE_LISTENER",
"]",
"(",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"entry",
".",
"entry_id",
")",
"return",
"unload_ok"
] |
[
64,
0
] |
[
79,
20
] |
python
|
en
|
['en', 'es', 'en']
|
True
|
_update_listener
|
(hass: HomeAssistant, entry: ConfigEntry)
|
Handle options update.
|
Handle options update.
|
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry):
"""Handle options update."""
await hass.config_entries.async_reload(entry.entry_id)
|
[
"async",
"def",
"_update_listener",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_reload",
"(",
"entry",
".",
"entry_id",
")"
] |
[
82,
0
] |
[
84,
58
] |
python
|
en
|
['en', 'nl', 'en']
|
True
|
turn_on
|
(hass, entity_id, variables=None, context=None)
|
Turn script on.
This is a legacy helper method. Do not use it for new tests.
|
Turn script on.
|
def turn_on(hass, entity_id, variables=None, context=None):
"""Turn script on.
This is a legacy helper method. Do not use it for new tests.
"""
_, object_id = split_entity_id(entity_id)
hass.services.call(DOMAIN, object_id, variables, context=context)
|
[
"def",
"turn_on",
"(",
"hass",
",",
"entity_id",
",",
"variables",
"=",
"None",
",",
"context",
"=",
"None",
")",
":",
"_",
",",
"object_id",
"=",
"split_entity_id",
"(",
"entity_id",
")",
"hass",
".",
"services",
".",
"call",
"(",
"DOMAIN",
",",
"object_id",
",",
"variables",
",",
"context",
"=",
"context",
")"
] |
[
33,
0
] |
[
40,
69
] |
python
|
en
|
['en', 'et', 'en']
|
True
|
turn_off
|
(hass, entity_id)
|
Turn script on.
This is a legacy helper method. Do not use it for new tests.
|
Turn script on.
|
def turn_off(hass, entity_id):
"""Turn script on.
This is a legacy helper method. Do not use it for new tests.
"""
hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
|
[
"def",
"turn_off",
"(",
"hass",
",",
"entity_id",
")",
":",
"hass",
".",
"services",
".",
"call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
")"
] |
[
44,
0
] |
[
49,
77
] |
python
|
en
|
['en', 'et', 'en']
|
True
|