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 |
---|---|---|---|---|---|---|---|---|---|---|---|
test_setup | (hass: HomeAssistantType, fritz: Mock) | Test setup of platform. | Test setup of platform. | async def test_setup(hass: HomeAssistantType, fritz: Mock):
"""Test setup of platform."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
state = hass.states.get(ENTITY_ID)
assert state
assert state.attributes[ATTR_BATTERY_LEVEL] == 23
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 18
assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name"
assert state.attributes[ATTR_HVAC_MODES] == [HVAC_MODE_HEAT, HVAC_MODE_OFF]
assert state.attributes[ATTR_MAX_TEMP] == 28
assert state.attributes[ATTR_MIN_TEMP] == 8
assert state.attributes[ATTR_PRESET_MODE] is None
assert state.attributes[ATTR_PRESET_MODES] == [PRESET_ECO, PRESET_COMFORT]
assert state.attributes[ATTR_STATE_BATTERY_LOW] is True
assert state.attributes[ATTR_STATE_DEVICE_LOCKED] == "fake_locked_device"
assert state.attributes[ATTR_STATE_HOLIDAY_MODE] == "fake_holiday"
assert state.attributes[ATTR_STATE_LOCKED] == "fake_locked"
assert state.attributes[ATTR_STATE_SUMMER_MODE] == "fake_summer"
assert state.attributes[ATTR_STATE_WINDOW_OPEN] == "fake_window"
assert state.attributes[ATTR_TEMPERATURE] == 19.5
assert state.state == HVAC_MODE_HEAT | [
"async",
"def",
"test_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BATTERY_LEVEL",
"]",
"==",
"23",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_CURRENT_TEMPERATURE",
"]",
"==",
"18",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_FRIENDLY_NAME",
"]",
"==",
"\"fake_name\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_HVAC_MODES",
"]",
"==",
"[",
"HVAC_MODE_HEAT",
",",
"HVAC_MODE_OFF",
"]",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MAX_TEMP",
"]",
"==",
"28",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MIN_TEMP",
"]",
"==",
"8",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_PRESET_MODE",
"]",
"is",
"None",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_PRESET_MODES",
"]",
"==",
"[",
"PRESET_ECO",
",",
"PRESET_COMFORT",
"]",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_STATE_BATTERY_LOW",
"]",
"is",
"True",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_STATE_DEVICE_LOCKED",
"]",
"==",
"\"fake_locked_device\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_STATE_HOLIDAY_MODE",
"]",
"==",
"\"fake_holiday\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_STATE_LOCKED",
"]",
"==",
"\"fake_locked\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_STATE_SUMMER_MODE",
"]",
"==",
"\"fake_summer\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_STATE_WINDOW_OPEN",
"]",
"==",
"\"fake_window\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_TEMPERATURE",
"]",
"==",
"19.5",
"assert",
"state",
".",
"state",
"==",
"HVAC_MODE_HEAT"
] | [
55,
0
] | [
79,
40
] | python | en | ['en', 'da', 'en'] | True |
test_target_temperature_on | (hass: HomeAssistantType, fritz: Mock) | Test turn device on. | Test turn device on. | async def test_target_temperature_on(hass: HomeAssistantType, fritz: Mock):
"""Test turn device on."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
device.target_temperature = 127.0
await setup_fritzbox(hass, MOCK_CONFIG)
state = hass.states.get(ENTITY_ID)
assert state
assert state.attributes[ATTR_TEMPERATURE] == 30 | [
"async",
"def",
"test_target_temperature_on",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"device",
".",
"target_temperature",
"=",
"127.0",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_TEMPERATURE",
"]",
"==",
"30"
] | [
82,
0
] | [
91,
51
] | python | en | ['es', 'en', 'en'] | True |
test_target_temperature_off | (hass: HomeAssistantType, fritz: Mock) | Test turn device on. | Test turn device on. | async def test_target_temperature_off(hass: HomeAssistantType, fritz: Mock):
"""Test turn device on."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
device.target_temperature = 126.5
await setup_fritzbox(hass, MOCK_CONFIG)
state = hass.states.get(ENTITY_ID)
assert state
assert state.attributes[ATTR_TEMPERATURE] == 0 | [
"async",
"def",
"test_target_temperature_off",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"device",
".",
"target_temperature",
"=",
"126.5",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_TEMPERATURE",
"]",
"==",
"0"
] | [
94,
0
] | [
103,
50
] | python | en | ['es', 'en', 'en'] | True |
test_update | (hass: HomeAssistantType, fritz: Mock) | Test update with error. | Test update with error. | async def test_update(hass: HomeAssistantType, fritz: Mock):
"""Test update with error."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
state = hass.states.get(ENTITY_ID)
assert state
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 18
assert state.attributes[ATTR_MAX_TEMP] == 28
assert state.attributes[ATTR_MIN_TEMP] == 8
assert state.attributes[ATTR_TEMPERATURE] == 19.5
device.actual_temperature = 19
device.target_temperature = 20
next_update = dt_util.utcnow() + timedelta(seconds=200)
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ID)
assert device.update.call_count == 1
assert state
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 19
assert state.attributes[ATTR_TEMPERATURE] == 20 | [
"async",
"def",
"test_update",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_CURRENT_TEMPERATURE",
"]",
"==",
"18",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MAX_TEMP",
"]",
"==",
"28",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MIN_TEMP",
"]",
"==",
"8",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_TEMPERATURE",
"]",
"==",
"19.5",
"device",
".",
"actual_temperature",
"=",
"19",
"device",
".",
"target_temperature",
"=",
"20",
"next_update",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"200",
")",
"async_fire_time_changed",
"(",
"hass",
",",
"next_update",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"device",
".",
"update",
".",
"call_count",
"==",
"1",
"assert",
"state",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_CURRENT_TEMPERATURE",
"]",
"==",
"19",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_TEMPERATURE",
"]",
"==",
"20"
] | [
106,
0
] | [
131,
51
] | python | en | ['en', 'de', 'en'] | True |
test_update_error | (hass: HomeAssistantType, fritz: Mock) | Test update with error. | Test update with error. | async def test_update_error(hass: HomeAssistantType, fritz: Mock):
"""Test update with error."""
device = FritzDeviceClimateMock()
device.update.side_effect = HTTPError("Boom")
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
assert device.update.call_count == 0
assert fritz().login.call_count == 1
next_update = dt_util.utcnow() + timedelta(seconds=200)
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()
assert device.update.call_count == 1
assert fritz().login.call_count == 2 | [
"async",
"def",
"test_update_error",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"device",
".",
"update",
".",
"side_effect",
"=",
"HTTPError",
"(",
"\"Boom\"",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"assert",
"device",
".",
"update",
".",
"call_count",
"==",
"0",
"assert",
"fritz",
"(",
")",
".",
"login",
".",
"call_count",
"==",
"1",
"next_update",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"200",
")",
"async_fire_time_changed",
"(",
"hass",
",",
"next_update",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"device",
".",
"update",
".",
"call_count",
"==",
"1",
"assert",
"fritz",
"(",
")",
".",
"login",
".",
"call_count",
"==",
"2"
] | [
134,
0
] | [
149,
40
] | python | en | ['en', 'de', 'en'] | True |
test_set_temperature_temperature | (hass: HomeAssistantType, fritz: Mock) | Test setting temperature by temperature. | Test setting temperature by temperature. | async def test_set_temperature_temperature(hass: HomeAssistantType, fritz: Mock):
"""Test setting temperature by temperature."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 123},
True,
)
assert device.set_target_temperature.call_args_list == [call(123)] | [
"async",
"def",
"test_set_temperature_temperature",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"assert",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SET_TEMPERATURE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_TEMPERATURE",
":",
"123",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_target_temperature",
".",
"call_args_list",
"==",
"[",
"call",
"(",
"123",
")",
"]"
] | [
152,
0
] | [
165,
70
] | python | en | ['en', 'en', 'en'] | True |
test_set_temperature_mode_off | (hass: HomeAssistantType, fritz: Mock) | Test setting temperature by mode. | Test setting temperature by mode. | async def test_set_temperature_mode_off(hass: HomeAssistantType, fritz: Mock):
"""Test setting temperature by mode."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_HVAC_MODE: HVAC_MODE_OFF,
ATTR_TEMPERATURE: 123,
},
True,
)
assert device.set_target_temperature.call_args_list == [call(0)] | [
"async",
"def",
"test_set_temperature_mode_off",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"assert",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SET_TEMPERATURE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_HVAC_MODE",
":",
"HVAC_MODE_OFF",
",",
"ATTR_TEMPERATURE",
":",
"123",
",",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_target_temperature",
".",
"call_args_list",
"==",
"[",
"call",
"(",
"0",
")",
"]"
] | [
168,
0
] | [
185,
68
] | python | en | ['en', 'en', 'en'] | True |
test_set_temperature_mode_heat | (hass: HomeAssistantType, fritz: Mock) | Test setting temperature by mode. | Test setting temperature by mode. | async def test_set_temperature_mode_heat(hass: HomeAssistantType, fritz: Mock):
"""Test setting temperature by mode."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_HVAC_MODE: HVAC_MODE_HEAT,
ATTR_TEMPERATURE: 123,
},
True,
)
assert device.set_target_temperature.call_args_list == [call(22)] | [
"async",
"def",
"test_set_temperature_mode_heat",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"assert",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SET_TEMPERATURE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_HVAC_MODE",
":",
"HVAC_MODE_HEAT",
",",
"ATTR_TEMPERATURE",
":",
"123",
",",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_target_temperature",
".",
"call_args_list",
"==",
"[",
"call",
"(",
"22",
")",
"]"
] | [
188,
0
] | [
205,
69
] | python | en | ['en', 'en', 'en'] | True |
test_set_hvac_mode_off | (hass: HomeAssistantType, fritz: Mock) | Test setting hvac mode. | Test setting hvac mode. | async def test_set_hvac_mode_off(hass: HomeAssistantType, fritz: Mock):
"""Test setting hvac mode."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVAC_MODE_OFF},
True,
)
assert device.set_target_temperature.call_args_list == [call(0)] | [
"async",
"def",
"test_set_hvac_mode_off",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"assert",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SET_HVAC_MODE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_HVAC_MODE",
":",
"HVAC_MODE_OFF",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_target_temperature",
".",
"call_args_list",
"==",
"[",
"call",
"(",
"0",
")",
"]"
] | [
208,
0
] | [
221,
68
] | python | en | ['en', 'sq', 'ru'] | False |
test_set_hvac_mode_heat | (hass: HomeAssistantType, fritz: Mock) | Test setting hvac mode. | Test setting hvac mode. | async def test_set_hvac_mode_heat(hass: HomeAssistantType, fritz: Mock):
"""Test setting hvac mode."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVAC_MODE_HEAT},
True,
)
assert device.set_target_temperature.call_args_list == [call(22)] | [
"async",
"def",
"test_set_hvac_mode_heat",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"assert",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SET_HVAC_MODE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_HVAC_MODE",
":",
"HVAC_MODE_HEAT",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_target_temperature",
".",
"call_args_list",
"==",
"[",
"call",
"(",
"22",
")",
"]"
] | [
224,
0
] | [
237,
69
] | python | en | ['en', 'sq', 'ru'] | False |
test_set_preset_mode_comfort | (hass: HomeAssistantType, fritz: Mock) | Test setting preset mode. | Test setting preset mode. | async def test_set_preset_mode_comfort(hass: HomeAssistantType, fritz: Mock):
"""Test setting preset mode."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_COMFORT},
True,
)
assert device.set_target_temperature.call_args_list == [call(22)] | [
"async",
"def",
"test_set_preset_mode_comfort",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"assert",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SET_PRESET_MODE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_PRESET_MODE",
":",
"PRESET_COMFORT",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_target_temperature",
".",
"call_args_list",
"==",
"[",
"call",
"(",
"22",
")",
"]"
] | [
240,
0
] | [
253,
69
] | python | en | ['en', 'ko', 'en'] | True |
test_set_preset_mode_eco | (hass: HomeAssistantType, fritz: Mock) | Test setting preset mode. | Test setting preset mode. | async def test_set_preset_mode_eco(hass: HomeAssistantType, fritz: Mock):
"""Test setting preset mode."""
device = FritzDeviceClimateMock()
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
assert await hass.services.async_call(
DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_ECO},
True,
)
assert device.set_target_temperature.call_args_list == [call(16)] | [
"async",
"def",
"test_set_preset_mode_eco",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"assert",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SET_PRESET_MODE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_PRESET_MODE",
":",
"PRESET_ECO",
"}",
",",
"True",
",",
")",
"assert",
"device",
".",
"set_target_temperature",
".",
"call_args_list",
"==",
"[",
"call",
"(",
"16",
")",
"]"
] | [
256,
0
] | [
269,
69
] | python | en | ['en', 'ko', 'en'] | True |
test_preset_mode_update | (hass: HomeAssistantType, fritz: Mock) | Test preset mode. | Test preset mode. | async def test_preset_mode_update(hass: HomeAssistantType, fritz: Mock):
"""Test preset mode."""
device = FritzDeviceClimateMock()
device.comfort_temperature = 98
device.eco_temperature = 99
fritz().get_devices.return_value = [device]
await setup_fritzbox(hass, MOCK_CONFIG)
state = hass.states.get(ENTITY_ID)
assert state
assert state.attributes[ATTR_PRESET_MODE] is None
device.target_temperature = 98
next_update = dt_util.utcnow() + timedelta(seconds=200)
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ID)
assert device.update.call_count == 1
assert state
assert state.attributes[ATTR_PRESET_MODE] == PRESET_COMFORT
device.target_temperature = 99
next_update = dt_util.utcnow() + timedelta(seconds=200)
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ID)
assert device.update.call_count == 2
assert state
assert state.attributes[ATTR_PRESET_MODE] == PRESET_ECO | [
"async",
"def",
"test_preset_mode_update",
"(",
"hass",
":",
"HomeAssistantType",
",",
"fritz",
":",
"Mock",
")",
":",
"device",
"=",
"FritzDeviceClimateMock",
"(",
")",
"device",
".",
"comfort_temperature",
"=",
"98",
"device",
".",
"eco_temperature",
"=",
"99",
"fritz",
"(",
")",
".",
"get_devices",
".",
"return_value",
"=",
"[",
"device",
"]",
"await",
"setup_fritzbox",
"(",
"hass",
",",
"MOCK_CONFIG",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_PRESET_MODE",
"]",
"is",
"None",
"device",
".",
"target_temperature",
"=",
"98",
"next_update",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"200",
")",
"async_fire_time_changed",
"(",
"hass",
",",
"next_update",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"device",
".",
"update",
".",
"call_count",
"==",
"1",
"assert",
"state",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_PRESET_MODE",
"]",
"==",
"PRESET_COMFORT",
"device",
".",
"target_temperature",
"=",
"99",
"next_update",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"200",
")",
"async_fire_time_changed",
"(",
"hass",
",",
"next_update",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"device",
".",
"update",
".",
"call_count",
"==",
"2",
"assert",
"state",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_PRESET_MODE",
"]",
"==",
"PRESET_ECO"
] | [
272,
0
] | [
305,
59
] | python | de | ['de', 'ko', 'it'] | False |
_key2bin | (s) | Convert a key into a string of binary digits | Convert a key into a string of binary digits | def _key2bin(s):
"Convert a key into a string of binary digits"
kl=[bord(x) for x in s]
kl=[binary[x>>4]+binary[x&15] for x in kl]
return ''.join(kl) | [
"def",
"_key2bin",
"(",
"s",
")",
":",
"kl",
"=",
"[",
"bord",
"(",
"x",
")",
"for",
"x",
"in",
"s",
"]",
"kl",
"=",
"[",
"binary",
"[",
"x",
">>",
"4",
"]",
"+",
"binary",
"[",
"x",
"&",
"15",
"]",
"for",
"x",
"in",
"kl",
"]",
"return",
"''",
".",
"join",
"(",
"kl",
")"
] | [
49,
0
] | [
53,
22
] | python | en | ['en', 'en', 'en'] | True |
_extract | (key, start, length) | Extract a bitstring(2.x)/bytestring(2.x) from a string of binary digits, and return its
numeric value. | Extract a bitstring(2.x)/bytestring(2.x) from a string of binary digits, and return its
numeric value. | def _extract(key, start, length):
"""Extract a bitstring(2.x)/bytestring(2.x) from a string of binary digits, and return its
numeric value."""
k=key[start:start+length]
return reduce(lambda x,y: x*2+ord(y)-48, k, 0) | [
"def",
"_extract",
"(",
"key",
",",
"start",
",",
"length",
")",
":",
"k",
"=",
"key",
"[",
"start",
":",
"start",
"+",
"length",
"]",
"return",
"reduce",
"(",
"lambda",
"x",
",",
"y",
":",
"x",
"*",
"2",
"+",
"ord",
"(",
"y",
")",
"-",
"48",
",",
"k",
",",
"0",
")"
] | [
55,
0
] | [
59,
50
] | python | en | ['en', 'en', 'en'] | True |
key_to_english | (key) | key_to_english(key:string(2.x)/bytes(3.x)) : string
Transform an arbitrary key into a string containing English words.
The key length must be a multiple of 8.
| key_to_english(key:string(2.x)/bytes(3.x)) : string
Transform an arbitrary key into a string containing English words.
The key length must be a multiple of 8.
| def key_to_english (key):
"""key_to_english(key:string(2.x)/bytes(3.x)) : string
Transform an arbitrary key into a string containing English words.
The key length must be a multiple of 8.
"""
english=''
for index in range(0, len(key), 8): # Loop over 8-byte subkeys
subkey=key[index:index+8]
# Compute the parity of the key
skbin=_key2bin(subkey) ; p=0
for i in range(0, 64, 2): p=p+_extract(skbin, i, 2)
# Append parity bits to the subkey
skbin=_key2bin(subkey+bchr((p<<6) & 255))
for i in range(0, 64, 11):
english=english+wordlist[_extract(skbin, i, 11)]+' '
return english[:-1] | [
"def",
"key_to_english",
"(",
"key",
")",
":",
"english",
"=",
"''",
"for",
"index",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"key",
")",
",",
"8",
")",
":",
"# Loop over 8-byte subkeys",
"subkey",
"=",
"key",
"[",
"index",
":",
"index",
"+",
"8",
"]",
"# Compute the parity of the key",
"skbin",
"=",
"_key2bin",
"(",
"subkey",
")",
"p",
"=",
"0",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"64",
",",
"2",
")",
":",
"p",
"=",
"p",
"+",
"_extract",
"(",
"skbin",
",",
"i",
",",
"2",
")",
"# Append parity bits to the subkey",
"skbin",
"=",
"_key2bin",
"(",
"subkey",
"+",
"bchr",
"(",
"(",
"p",
"<<",
"6",
")",
"&",
"255",
")",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"64",
",",
"11",
")",
":",
"english",
"=",
"english",
"+",
"wordlist",
"[",
"_extract",
"(",
"skbin",
",",
"i",
",",
"11",
")",
"]",
"+",
"' '",
"return",
"english",
"[",
":",
"-",
"1",
"]"
] | [
61,
0
] | [
77,
23
] | python | en | ['it', 'ru-Latn', 'en'] | False |
english_to_key | (s) | english_to_key(string):string(2.x)/bytes(2.x)
Transform a string into a corresponding key.
The string must contain words separated by whitespace; the number
of words must be a multiple of 6.
| english_to_key(string):string(2.x)/bytes(2.x)
Transform a string into a corresponding key.
The string must contain words separated by whitespace; the number
of words must be a multiple of 6.
| def english_to_key (s):
"""english_to_key(string):string(2.x)/bytes(2.x)
Transform a string into a corresponding key.
The string must contain words separated by whitespace; the number
of words must be a multiple of 6.
"""
L=s.upper().split() ; key=b''
for index in range(0, len(L), 6):
sublist=L[index:index+6] ; char=9*[0] ; bits=0
for i in sublist:
index = wordlist.index(i)
shift = (8-(bits+11)%8) %8
y = index << shift
cl, cc, cr = (y>>16), (y>>8)&0xff, y & 0xff
if (shift>5):
char[bits>>3] = char[bits>>3] | cl
char[(bits>>3)+1] = char[(bits>>3)+1] | cc
char[(bits>>3)+2] = char[(bits>>3)+2] | cr
elif shift>-3:
char[bits>>3] = char[bits>>3] | cc
char[(bits>>3)+1] = char[(bits>>3)+1] | cr
else: char[bits>>3] = char[bits>>3] | cr
bits=bits+11
subkey=reduce(lambda x,y:x+bchr(y), char, b'')
# Check the parity of the resulting key
skbin=_key2bin(subkey)
p=0
for i in range(0, 64, 2): p=p+_extract(skbin, i, 2)
if (p&3) != _extract(skbin, 64, 2):
raise ValueError("Parity error in resulting key")
key=key+subkey[0:8]
return key | [
"def",
"english_to_key",
"(",
"s",
")",
":",
"L",
"=",
"s",
".",
"upper",
"(",
")",
".",
"split",
"(",
")",
"key",
"=",
"b''",
"for",
"index",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"L",
")",
",",
"6",
")",
":",
"sublist",
"=",
"L",
"[",
"index",
":",
"index",
"+",
"6",
"]",
"char",
"=",
"9",
"*",
"[",
"0",
"]",
"bits",
"=",
"0",
"for",
"i",
"in",
"sublist",
":",
"index",
"=",
"wordlist",
".",
"index",
"(",
"i",
")",
"shift",
"=",
"(",
"8",
"-",
"(",
"bits",
"+",
"11",
")",
"%",
"8",
")",
"%",
"8",
"y",
"=",
"index",
"<<",
"shift",
"cl",
",",
"cc",
",",
"cr",
"=",
"(",
"y",
">>",
"16",
")",
",",
"(",
"y",
">>",
"8",
")",
"&",
"0xff",
",",
"y",
"&",
"0xff",
"if",
"(",
"shift",
">",
"5",
")",
":",
"char",
"[",
"bits",
">>",
"3",
"]",
"=",
"char",
"[",
"bits",
">>",
"3",
"]",
"|",
"cl",
"char",
"[",
"(",
"bits",
">>",
"3",
")",
"+",
"1",
"]",
"=",
"char",
"[",
"(",
"bits",
">>",
"3",
")",
"+",
"1",
"]",
"|",
"cc",
"char",
"[",
"(",
"bits",
">>",
"3",
")",
"+",
"2",
"]",
"=",
"char",
"[",
"(",
"bits",
">>",
"3",
")",
"+",
"2",
"]",
"|",
"cr",
"elif",
"shift",
">",
"-",
"3",
":",
"char",
"[",
"bits",
">>",
"3",
"]",
"=",
"char",
"[",
"bits",
">>",
"3",
"]",
"|",
"cc",
"char",
"[",
"(",
"bits",
">>",
"3",
")",
"+",
"1",
"]",
"=",
"char",
"[",
"(",
"bits",
">>",
"3",
")",
"+",
"1",
"]",
"|",
"cr",
"else",
":",
"char",
"[",
"bits",
">>",
"3",
"]",
"=",
"char",
"[",
"bits",
">>",
"3",
"]",
"|",
"cr",
"bits",
"=",
"bits",
"+",
"11",
"subkey",
"=",
"reduce",
"(",
"lambda",
"x",
",",
"y",
":",
"x",
"+",
"bchr",
"(",
"y",
")",
",",
"char",
",",
"b''",
")",
"# Check the parity of the resulting key",
"skbin",
"=",
"_key2bin",
"(",
"subkey",
")",
"p",
"=",
"0",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"64",
",",
"2",
")",
":",
"p",
"=",
"p",
"+",
"_extract",
"(",
"skbin",
",",
"i",
",",
"2",
")",
"if",
"(",
"p",
"&",
"3",
")",
"!=",
"_extract",
"(",
"skbin",
",",
"64",
",",
"2",
")",
":",
"raise",
"ValueError",
"(",
"\"Parity error in resulting key\"",
")",
"key",
"=",
"key",
"+",
"subkey",
"[",
"0",
":",
"8",
"]",
"return",
"key"
] | [
79,
0
] | [
112,
14
] | python | en | ['it', 'ru-Latn', 'en'] | False |
Dataset.__init__ | (self, X, y) | Reads source and target sequences from txt files. | Reads source and target sequences from txt files. | def __init__(self, X, y):
"""Reads source and target sequences from txt files."""
self.X = X
self.y = y | [
"def",
"__init__",
"(",
"self",
",",
"X",
",",
"y",
")",
":",
"self",
".",
"X",
"=",
"X",
"self",
".",
"y",
"=",
"y"
] | [
84,
4
] | [
87,
18
] | python | en | ['en', 'en', 'en'] | True |
Dataset.__getitem__ | (self, index) | Returns one data pair (source and target). | Returns one data pair (source and target). | def __getitem__(self, index):
"""Returns one data pair (source and target)."""
data = {}
data["X"] = self.X[index]
data["y"] = self.y[index]
return data | [
"def",
"__getitem__",
"(",
"self",
",",
"index",
")",
":",
"data",
"=",
"{",
"}",
"data",
"[",
"\"X\"",
"]",
"=",
"self",
".",
"X",
"[",
"index",
"]",
"data",
"[",
"\"y\"",
"]",
"=",
"self",
".",
"y",
"[",
"index",
"]",
"return",
"data"
] | [
92,
4
] | [
97,
19
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (
hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities
) | Set up the HomematicIP alrm control panel from a config entry. | Set up the HomematicIP alrm control panel from a config entry. | async def async_setup_entry(
hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities
) -> None:
"""Set up the HomematicIP alrm control panel from a config entry."""
hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id]
async_add_entities([HomematicipAlarmControlPanelEntity(hap)]) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config_entry",
":",
"ConfigEntry",
",",
"async_add_entities",
")",
"->",
"None",
":",
"hap",
"=",
"hass",
".",
"data",
"[",
"HMIPC_DOMAIN",
"]",
"[",
"config_entry",
".",
"unique_id",
"]",
"async_add_entities",
"(",
"[",
"HomematicipAlarmControlPanelEntity",
"(",
"hap",
")",
"]",
")"
] | [
29,
0
] | [
34,
65
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.__init__ | (self, hap: HomematicipHAP) | Initialize the alarm control panel. | Initialize the alarm control panel. | def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize the alarm control panel."""
self._home = hap.home
_LOGGER.info("Setting up %s", self.name) | [
"def",
"__init__",
"(",
"self",
",",
"hap",
":",
"HomematicipHAP",
")",
"->",
"None",
":",
"self",
".",
"_home",
"=",
"hap",
".",
"home",
"_LOGGER",
".",
"info",
"(",
"\"Setting up %s\"",
",",
"self",
".",
"name",
")"
] | [
40,
4
] | [
43,
48
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.device_info | (self) | Return device specific attributes. | Return device specific attributes. | def device_info(self) -> Dict[str, Any]:
"""Return device specific attributes."""
return {
"identifiers": {(HMIPC_DOMAIN, f"ACP {self._home.id}")},
"name": self.name,
"manufacturer": "eQ-3",
"model": CONST_ALARM_CONTROL_PANEL_NAME,
"via_device": (HMIPC_DOMAIN, self._home.id),
} | [
"def",
"device_info",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"HMIPC_DOMAIN",
",",
"f\"ACP {self._home.id}\"",
")",
"}",
",",
"\"name\"",
":",
"self",
".",
"name",
",",
"\"manufacturer\"",
":",
"\"eQ-3\"",
",",
"\"model\"",
":",
"CONST_ALARM_CONTROL_PANEL_NAME",
",",
"\"via_device\"",
":",
"(",
"HMIPC_DOMAIN",
",",
"self",
".",
"_home",
".",
"id",
")",
",",
"}"
] | [
46,
4
] | [
54,
9
] | python | en | ['fr', 'it', 'en'] | False |
HomematicipAlarmControlPanelEntity.state | (self) | Return the state of the alarm control panel. | Return the state of the alarm control panel. | def state(self) -> str:
"""Return the state of the alarm control panel."""
# check for triggered alarm
if self._security_and_alarm.alarmActive:
return STATE_ALARM_TRIGGERED
activation_state = self._home.get_security_zones_activation()
# check arm_away
if activation_state == (True, True):
return STATE_ALARM_ARMED_AWAY
# check arm_home
if activation_state == (False, True):
return STATE_ALARM_ARMED_HOME
return STATE_ALARM_DISARMED | [
"def",
"state",
"(",
"self",
")",
"->",
"str",
":",
"# check for triggered alarm",
"if",
"self",
".",
"_security_and_alarm",
".",
"alarmActive",
":",
"return",
"STATE_ALARM_TRIGGERED",
"activation_state",
"=",
"self",
".",
"_home",
".",
"get_security_zones_activation",
"(",
")",
"# check arm_away",
"if",
"activation_state",
"==",
"(",
"True",
",",
"True",
")",
":",
"return",
"STATE_ALARM_ARMED_AWAY",
"# check arm_home",
"if",
"activation_state",
"==",
"(",
"False",
",",
"True",
")",
":",
"return",
"STATE_ALARM_ARMED_HOME",
"return",
"STATE_ALARM_DISARMED"
] | [
57,
4
] | [
71,
35
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"SUPPORT_ALARM_ARM_HOME",
"|",
"SUPPORT_ALARM_ARM_AWAY"
] | [
78,
4
] | [
80,
62
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.async_alarm_disarm | (self, code=None) | Send disarm command. | Send disarm command. | async def async_alarm_disarm(self, code=None) -> None:
"""Send disarm command."""
await self._home.set_security_zones_activation(False, False) | [
"async",
"def",
"async_alarm_disarm",
"(",
"self",
",",
"code",
"=",
"None",
")",
"->",
"None",
":",
"await",
"self",
".",
"_home",
".",
"set_security_zones_activation",
"(",
"False",
",",
"False",
")"
] | [
82,
4
] | [
84,
68
] | python | en | ['en', 'pt', 'en'] | True |
HomematicipAlarmControlPanelEntity.async_alarm_arm_home | (self, code=None) | Send arm home command. | Send arm home command. | async def async_alarm_arm_home(self, code=None) -> None:
"""Send arm home command."""
await self._home.set_security_zones_activation(False, True) | [
"async",
"def",
"async_alarm_arm_home",
"(",
"self",
",",
"code",
"=",
"None",
")",
"->",
"None",
":",
"await",
"self",
".",
"_home",
".",
"set_security_zones_activation",
"(",
"False",
",",
"True",
")"
] | [
86,
4
] | [
88,
67
] | python | en | ['en', 'pt', 'en'] | True |
HomematicipAlarmControlPanelEntity.async_alarm_arm_away | (self, code=None) | Send arm away command. | Send arm away command. | async def async_alarm_arm_away(self, code=None) -> None:
"""Send arm away command."""
await self._home.set_security_zones_activation(True, True) | [
"async",
"def",
"async_alarm_arm_away",
"(",
"self",
",",
"code",
"=",
"None",
")",
"->",
"None",
":",
"await",
"self",
".",
"_home",
".",
"set_security_zones_activation",
"(",
"True",
",",
"True",
")"
] | [
90,
4
] | [
92,
66
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.async_added_to_hass | (self) | Register callbacks. | Register callbacks. | async def async_added_to_hass(self) -> None:
"""Register callbacks."""
self._home.on_update(self._async_device_changed) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"_home",
".",
"on_update",
"(",
"self",
".",
"_async_device_changed",
")"
] | [
94,
4
] | [
96,
56
] | python | en | ['en', 'no', 'en'] | False |
HomematicipAlarmControlPanelEntity._async_device_changed | (self, *args, **kwargs) | Handle entity state changes. | Handle entity state changes. | def _async_device_changed(self, *args, **kwargs) -> None:
"""Handle entity state changes."""
# Don't update disabled entities
if self.enabled:
_LOGGER.debug("Event %s (%s)", self.name, CONST_ALARM_CONTROL_PANEL_NAME)
self.async_write_ha_state()
else:
_LOGGER.debug(
"Device Changed Event for %s (Alarm Control Panel) not fired. Entity is disabled",
self.name,
) | [
"def",
"_async_device_changed",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"# Don't update disabled entities",
"if",
"self",
".",
"enabled",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Event %s (%s)\"",
",",
"self",
".",
"name",
",",
"CONST_ALARM_CONTROL_PANEL_NAME",
")",
"self",
".",
"async_write_ha_state",
"(",
")",
"else",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Device Changed Event for %s (Alarm Control Panel) not fired. Entity is disabled\"",
",",
"self",
".",
"name",
",",
")"
] | [
99,
4
] | [
109,
13
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.name | (self) | Return the name of the generic entity. | Return the name of the generic entity. | def name(self) -> str:
"""Return the name of the generic entity."""
name = CONST_ALARM_CONTROL_PANEL_NAME
if self._home.name:
name = f"{self._home.name} {name}"
return name | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"name",
"=",
"CONST_ALARM_CONTROL_PANEL_NAME",
"if",
"self",
".",
"_home",
".",
"name",
":",
"name",
"=",
"f\"{self._home.name} {name}\"",
"return",
"name"
] | [
112,
4
] | [
117,
19
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.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"
] | [
120,
4
] | [
122,
20
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.available | (self) | Return if alarm control panel is available. | Return if alarm control panel is available. | def available(self) -> bool:
"""Return if alarm control panel is available."""
return self._home.connected | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_home",
".",
"connected"
] | [
125,
4
] | [
127,
35
] | python | en | ['en', 'en', 'en'] | True |
HomematicipAlarmControlPanelEntity.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self.__class__.__name__}_{self._home.id}" | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"f\"{self.__class__.__name__}_{self._home.id}\""
] | [
130,
4
] | [
132,
59
] | python | ca | ['fr', 'ca', 'en'] | False |
create_server | () | create server | create server | def create_server():
"""create server"""
return HTTPServer(('127.0.0.1', 3000), SimpleHTTPRequestHandler) | [
"def",
"create_server",
"(",
")",
":",
"return",
"HTTPServer",
"(",
"(",
"'127.0.0.1'",
",",
"3000",
")",
",",
"SimpleHTTPRequestHandler",
")"
] | [
110,
0
] | [
112,
68
] | python | en | ['en', 'bs', 'en'] | False |
run_forever | () | keep server running forever | keep server running forever | def run_forever():
"""keep server running forever"""
server = create_server()
try:
print('Starting server on port 3000')
server.serve_forever()
except KeyboardInterrupt:
server.shutdown()
server.server_close() | [
"def",
"run_forever",
"(",
")",
":",
"server",
"=",
"create_server",
"(",
")",
"try",
":",
"print",
"(",
"'Starting server on port 3000'",
")",
"server",
".",
"serve_forever",
"(",
")",
"except",
"KeyboardInterrupt",
":",
"server",
".",
"shutdown",
"(",
")",
"server",
".",
"server_close",
"(",
")"
] | [
115,
0
] | [
124,
29
] | python | en | ['en', 'no', 'en'] | True |
SimpleHTTPRequestHandler.do_GET | (self) | handle GET routes | handle GET routes | def do_GET(self):
"""handle GET routes"""
parsed_path = urlparse(self.path)
parsed_qs = parse_qs(parsed_path.query)
if parsed_path.path == '/':
#set header
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.end_headers()
#set body
self.wfile.write(b"""<!DOCTYPE html>
<html>
<head>
<title> cowsay </title>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="/cowsay">cowsay</a></li>
</ul>
</nav>
<header>
<main>
<p>cowsay is a program that generates ASCII pictures of a cow with a message. This is my first time making an HTTP server in Python</p>
</main>
</body>
</html>""")
elif parsed_path.path == '/cowsay':
self.send_response(200)
self.end_headers()
self.wfile.write(b"""<!DOCTYPE html>
<html>
<head>
<title> cowsay </title>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="/">Home</a></li>
</ul>
</nav>
<header>
<main>
<p>A message about other things you can do. After the port number, add <b>cow?msg="message"</b> in the address bar, replacing message with your message </p>
</main>
</body>
</html>""")
elif parsed_path.path == '/cow':
try:
daemon = cow.Daemon()
msg = daemon.milk(json.loads(parsed_qs['msg'][0]))
except (KeyError, json.decoder.JSONDecodeError):
self.send_response(400)
self.end_headers()
self.wfile.write(b'Incorrect format')
return
self.send_response(200)
self.end_headers()
self.wfile.write(msg.encode('utf8'))
else:
self.send_response(404)
self.end_headers()
self.wfile.write(b'Not Found') | [
"def",
"do_GET",
"(",
"self",
")",
":",
"parsed_path",
"=",
"urlparse",
"(",
"self",
".",
"path",
")",
"parsed_qs",
"=",
"parse_qs",
"(",
"parsed_path",
".",
"query",
")",
"if",
"parsed_path",
".",
"path",
"==",
"'/'",
":",
"#set header",
"self",
".",
"send_response",
"(",
"200",
")",
"self",
".",
"send_header",
"(",
"'Content-Type'",
",",
"'text/html'",
")",
"self",
".",
"end_headers",
"(",
")",
"#set body",
"self",
".",
"wfile",
".",
"write",
"(",
"b\"\"\"<!DOCTYPE html>\n<html>\n<head>\n <title> cowsay </title>\n</head>\n<body>\n <header>\n <nav>\n <ul>\n <li><a href=\"/cowsay\">cowsay</a></li>\n </ul>\n </nav>\n <header>\n <main>\n <p>cowsay is a program that generates ASCII pictures of a cow with a message. This is my first time making an HTTP server in Python</p>\n </main>\n</body>\n</html>\"\"\"",
")",
"elif",
"parsed_path",
".",
"path",
"==",
"'/cowsay'",
":",
"self",
".",
"send_response",
"(",
"200",
")",
"self",
".",
"end_headers",
"(",
")",
"self",
".",
"wfile",
".",
"write",
"(",
"b\"\"\"<!DOCTYPE html>\n<html>\n<head>\n <title> cowsay </title>\n</head>\n<body>\n <header>\n <nav>\n <ul>\n <li><a href=\"/\">Home</a></li>\n </ul>\n </nav>\n <header>\n <main>\n <p>A message about other things you can do. After the port number, add <b>cow?msg=\"message\"</b> in the address bar, replacing message with your message </p>\n </main>\n</body>\n</html>\"\"\"",
")",
"elif",
"parsed_path",
".",
"path",
"==",
"'/cow'",
":",
"try",
":",
"daemon",
"=",
"cow",
".",
"Daemon",
"(",
")",
"msg",
"=",
"daemon",
".",
"milk",
"(",
"json",
".",
"loads",
"(",
"parsed_qs",
"[",
"'msg'",
"]",
"[",
"0",
"]",
")",
")",
"except",
"(",
"KeyError",
",",
"json",
".",
"decoder",
".",
"JSONDecodeError",
")",
":",
"self",
".",
"send_response",
"(",
"400",
")",
"self",
".",
"end_headers",
"(",
")",
"self",
".",
"wfile",
".",
"write",
"(",
"b'Incorrect format'",
")",
"return",
"self",
".",
"send_response",
"(",
"200",
")",
"self",
".",
"end_headers",
"(",
")",
"self",
".",
"wfile",
".",
"write",
"(",
"msg",
".",
"encode",
"(",
"'utf8'",
")",
")",
"else",
":",
"self",
".",
"send_response",
"(",
"404",
")",
"self",
".",
"end_headers",
"(",
")",
"self",
".",
"wfile",
".",
"write",
"(",
"b'Not Found'",
")"
] | [
8,
4
] | [
79,
42
] | python | en | ['fr', 'en', 'en'] | True |
SimpleHTTPRequestHandler.do_POST | (self) | handle POST routes | handle POST routes | def do_POST(self):
"""handle POST routes"""
parsed_path = urlparse(self.path)
if parsed_path.path == '/cow':
try:
content_length = int(self.headers['Content-Length'])
body = json.loads(self.rfile.read(content_length).decode('utf8'))
except (KeyError, json.decoder.JSONDecodeError) as err:
self.send_response(400)
self.end_headers()
self.wfile.write(b'Incorrect format')
return
self.send_response(201)
self.send_header('Content-Type', 'application/json')
self.end_headers()
daemon = cow.Daemon()
msg = daemon.milk(body['msg'])
self.wfile.write(json.dumps({'content': msg}).encode('utf8'))
else:
self.send_response(404)
self.send_header('Content-Type', 'text/html')
self.end_headers()
self.wfile.write(b'Not Found') | [
"def",
"do_POST",
"(",
"self",
")",
":",
"parsed_path",
"=",
"urlparse",
"(",
"self",
".",
"path",
")",
"if",
"parsed_path",
".",
"path",
"==",
"'/cow'",
":",
"try",
":",
"content_length",
"=",
"int",
"(",
"self",
".",
"headers",
"[",
"'Content-Length'",
"]",
")",
"body",
"=",
"json",
".",
"loads",
"(",
"self",
".",
"rfile",
".",
"read",
"(",
"content_length",
")",
".",
"decode",
"(",
"'utf8'",
")",
")",
"except",
"(",
"KeyError",
",",
"json",
".",
"decoder",
".",
"JSONDecodeError",
")",
"as",
"err",
":",
"self",
".",
"send_response",
"(",
"400",
")",
"self",
".",
"end_headers",
"(",
")",
"self",
".",
"wfile",
".",
"write",
"(",
"b'Incorrect format'",
")",
"return",
"self",
".",
"send_response",
"(",
"201",
")",
"self",
".",
"send_header",
"(",
"'Content-Type'",
",",
"'application/json'",
")",
"self",
".",
"end_headers",
"(",
")",
"daemon",
"=",
"cow",
".",
"Daemon",
"(",
")",
"msg",
"=",
"daemon",
".",
"milk",
"(",
"body",
"[",
"'msg'",
"]",
")",
"self",
".",
"wfile",
".",
"write",
"(",
"json",
".",
"dumps",
"(",
"{",
"'content'",
":",
"msg",
"}",
")",
".",
"encode",
"(",
"'utf8'",
")",
")",
"else",
":",
"self",
".",
"send_response",
"(",
"404",
")",
"self",
".",
"send_header",
"(",
"'Content-Type'",
",",
"'text/html'",
")",
"self",
".",
"end_headers",
"(",
")",
"self",
".",
"wfile",
".",
"write",
"(",
"b'Not Found'",
")"
] | [
81,
4
] | [
107,
42
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Lutron Caseta scene platform.
Adds scenes from the Caseta bridge associated with the config_entry as
scene entities.
| Set up the Lutron Caseta scene platform. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Lutron Caseta scene platform.
Adds scenes from the Caseta bridge associated with the config_entry as
scene entities.
"""
entities = []
bridge = hass.data[CASETA_DOMAIN][config_entry.entry_id]
scenes = bridge.get_scenes()
for scene in scenes:
entity = LutronCasetaScene(scenes[scene], bridge)
entities.append(entity)
async_add_entities(entities, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"entities",
"=",
"[",
"]",
"bridge",
"=",
"hass",
".",
"data",
"[",
"CASETA_DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"scenes",
"=",
"bridge",
".",
"get_scenes",
"(",
")",
"for",
"scene",
"in",
"scenes",
":",
"entity",
"=",
"LutronCasetaScene",
"(",
"scenes",
"[",
"scene",
"]",
",",
"bridge",
")",
"entities",
".",
"append",
"(",
"entity",
")",
"async_add_entities",
"(",
"entities",
",",
"True",
")"
] | [
8,
0
] | [
23,
38
] | python | en | ['en', 'hr', 'en'] | True |
LutronCasetaScene.__init__ | (self, scene, bridge) | Initialize the Lutron Caseta scene. | Initialize the Lutron Caseta scene. | def __init__(self, scene, bridge):
"""Initialize the Lutron Caseta scene."""
self._scene_name = scene["name"]
self._scene_id = scene["scene_id"]
self._bridge = bridge | [
"def",
"__init__",
"(",
"self",
",",
"scene",
",",
"bridge",
")",
":",
"self",
".",
"_scene_name",
"=",
"scene",
"[",
"\"name\"",
"]",
"self",
".",
"_scene_id",
"=",
"scene",
"[",
"\"scene_id\"",
"]",
"self",
".",
"_bridge",
"=",
"bridge"
] | [
29,
4
] | [
33,
29
] | python | en | ['en', 'ro', 'en'] | True |
LutronCasetaScene.name | (self) | Return the name of the scene. | Return the name of the scene. | def name(self):
"""Return the name of the scene."""
return self._scene_name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_scene_name"
] | [
36,
4
] | [
38,
31
] | python | en | ['en', 'ig', 'en'] | True |
LutronCasetaScene.async_activate | (self, **kwargs: Any) | Activate the scene. | Activate the scene. | async def async_activate(self, **kwargs: Any) -> None:
"""Activate the scene."""
await self._bridge.activate_scene(self._scene_id) | [
"async",
"def",
"async_activate",
"(",
"self",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"None",
":",
"await",
"self",
".",
"_bridge",
".",
"activate_scene",
"(",
"self",
".",
"_scene_id",
")"
] | [
40,
4
] | [
42,
57
] | python | en | ['en', 'it', 'en'] | True |
test_create_doorbell | (hass) | Test creation of a doorbell. | Test creation of a doorbell. | async def test_create_doorbell(hass):
"""Test creation of a doorbell."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
await _create_august_with_devices(hass, [doorbell_one])
sensor_k98gidt45gul_name_battery = hass.states.get(
"sensor.k98gidt45gul_name_battery"
)
assert sensor_k98gidt45gul_name_battery.state == "96"
assert (
sensor_k98gidt45gul_name_battery.attributes["unit_of_measurement"] == PERCENTAGE
) | [
"async",
"def",
"test_create_doorbell",
"(",
"hass",
")",
":",
"doorbell_one",
"=",
"await",
"_mock_doorbell_from_fixture",
"(",
"hass",
",",
"\"get_doorbell.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"doorbell_one",
"]",
")",
"sensor_k98gidt45gul_name_battery",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.k98gidt45gul_name_battery\"",
")",
"assert",
"sensor_k98gidt45gul_name_battery",
".",
"state",
"==",
"\"96\"",
"assert",
"(",
"sensor_k98gidt45gul_name_battery",
".",
"attributes",
"[",
"\"unit_of_measurement\"",
"]",
"==",
"PERCENTAGE",
")"
] | [
13,
0
] | [
24,
5
] | python | en | ['en', 'lb', 'en'] | True |
test_create_doorbell_offline | (hass) | Test creation of a doorbell that is offline. | Test creation of a doorbell that is offline. | async def test_create_doorbell_offline(hass):
"""Test creation of a doorbell that is offline."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json")
await _create_august_with_devices(hass, [doorbell_one])
entity_registry = await hass.helpers.entity_registry.async_get_registry()
sensor_tmt100_name_battery = hass.states.get("sensor.tmt100_name_battery")
assert sensor_tmt100_name_battery.state == "81"
assert sensor_tmt100_name_battery.attributes["unit_of_measurement"] == PERCENTAGE
entry = entity_registry.async_get("sensor.tmt100_name_battery")
assert entry
assert entry.unique_id == "tmt100_device_battery" | [
"async",
"def",
"test_create_doorbell_offline",
"(",
"hass",
")",
":",
"doorbell_one",
"=",
"await",
"_mock_doorbell_from_fixture",
"(",
"hass",
",",
"\"get_doorbell.offline.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"doorbell_one",
"]",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"sensor_tmt100_name_battery",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.tmt100_name_battery\"",
")",
"assert",
"sensor_tmt100_name_battery",
".",
"state",
"==",
"\"81\"",
"assert",
"sensor_tmt100_name_battery",
".",
"attributes",
"[",
"\"unit_of_measurement\"",
"]",
"==",
"PERCENTAGE",
"entry",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.tmt100_name_battery\"",
")",
"assert",
"entry",
"assert",
"entry",
".",
"unique_id",
"==",
"\"tmt100_device_battery\""
] | [
27,
0
] | [
39,
53
] | python | en | ['en', 'nl', 'en'] | True |
test_create_doorbell_hardwired | (hass) | Test creation of a doorbell that is hardwired without a battery. | Test creation of a doorbell that is hardwired without a battery. | async def test_create_doorbell_hardwired(hass):
"""Test creation of a doorbell that is hardwired without a battery."""
doorbell_one = await _mock_doorbell_from_fixture(
hass, "get_doorbell.nobattery.json"
)
await _create_august_with_devices(hass, [doorbell_one])
sensor_tmt100_name_battery = hass.states.get("sensor.tmt100_name_battery")
assert sensor_tmt100_name_battery is None | [
"async",
"def",
"test_create_doorbell_hardwired",
"(",
"hass",
")",
":",
"doorbell_one",
"=",
"await",
"_mock_doorbell_from_fixture",
"(",
"hass",
",",
"\"get_doorbell.nobattery.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"doorbell_one",
"]",
")",
"sensor_tmt100_name_battery",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.tmt100_name_battery\"",
")",
"assert",
"sensor_tmt100_name_battery",
"is",
"None"
] | [
42,
0
] | [
50,
45
] | python | en | ['en', 'en', 'en'] | True |
test_create_lock_with_linked_keypad | (hass) | Test creation of a lock with a linked keypad that both have a battery. | Test creation of a lock with a linked keypad that both have a battery. | async def test_create_lock_with_linked_keypad(hass):
"""Test creation of a lock with a linked keypad that both have a battery."""
lock_one = await _mock_lock_from_fixture(hass, "get_lock.doorsense_init.json")
await _create_august_with_devices(hass, [lock_one])
entity_registry = await hass.helpers.entity_registry.async_get_registry()
sensor_a6697750d607098bae8d6baa11ef8063_name_battery = hass.states.get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
)
assert sensor_a6697750d607098bae8d6baa11ef8063_name_battery.state == "88"
assert (
sensor_a6697750d607098bae8d6baa11ef8063_name_battery.attributes[
"unit_of_measurement"
]
== PERCENTAGE
)
entry = entity_registry.async_get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
)
assert entry
assert entry.unique_id == "A6697750D607098BAE8D6BAA11EF8063_device_battery"
state = hass.states.get("sensor.front_door_lock_keypad_battery")
assert state.state == "60"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery")
assert entry
assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery" | [
"async",
"def",
"test_create_lock_with_linked_keypad",
"(",
"hass",
")",
":",
"lock_one",
"=",
"await",
"_mock_lock_from_fixture",
"(",
"hass",
",",
"\"get_lock.doorsense_init.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"lock_one",
"]",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"sensor_a6697750d607098bae8d6baa11ef8063_name_battery",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.a6697750d607098bae8d6baa11ef8063_name_battery\"",
")",
"assert",
"sensor_a6697750d607098bae8d6baa11ef8063_name_battery",
".",
"state",
"==",
"\"88\"",
"assert",
"(",
"sensor_a6697750d607098bae8d6baa11ef8063_name_battery",
".",
"attributes",
"[",
"\"unit_of_measurement\"",
"]",
"==",
"PERCENTAGE",
")",
"entry",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.a6697750d607098bae8d6baa11ef8063_name_battery\"",
")",
"assert",
"entry",
"assert",
"entry",
".",
"unique_id",
"==",
"\"A6697750D607098BAE8D6BAA11EF8063_device_battery\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.front_door_lock_keypad_battery\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"60\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_UNIT_OF_MEASUREMENT",
"]",
"==",
"PERCENTAGE",
"entry",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.front_door_lock_keypad_battery\"",
")",
"assert",
"entry",
"assert",
"entry",
".",
"unique_id",
"==",
"\"5bc65c24e6ef2a263e1450a8_linked_keypad_battery\""
] | [
53,
0
] | [
80,
78
] | python | en | ['en', 'en', 'en'] | True |
test_create_lock_with_low_battery_linked_keypad | (hass) | Test creation of a lock with a linked keypad that both have a battery. | Test creation of a lock with a linked keypad that both have a battery. | async def test_create_lock_with_low_battery_linked_keypad(hass):
"""Test creation of a lock with a linked keypad that both have a battery."""
lock_one = await _mock_lock_from_fixture(hass, "get_lock.low_keypad_battery.json")
await _create_august_with_devices(hass, [lock_one])
entity_registry = await hass.helpers.entity_registry.async_get_registry()
sensor_a6697750d607098bae8d6baa11ef8063_name_battery = hass.states.get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
)
assert sensor_a6697750d607098bae8d6baa11ef8063_name_battery.state == "88"
assert (
sensor_a6697750d607098bae8d6baa11ef8063_name_battery.attributes[
"unit_of_measurement"
]
== PERCENTAGE
)
entry = entity_registry.async_get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
)
assert entry
assert entry.unique_id == "A6697750D607098BAE8D6BAA11EF8063_device_battery"
state = hass.states.get("sensor.front_door_lock_keypad_battery")
assert state.state == "10"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery")
assert entry
assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery"
# No activity means it will be unavailable until someone unlocks/locks it
lock_operator_sensor = entity_registry.async_get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_operator"
)
assert (
lock_operator_sensor.unique_id
== "A6697750D607098BAE8D6BAA11EF8063_lock_operator"
)
assert (
hass.states.get("sensor.a6697750d607098bae8d6baa11ef8063_name_operator").state
== STATE_UNAVAILABLE
) | [
"async",
"def",
"test_create_lock_with_low_battery_linked_keypad",
"(",
"hass",
")",
":",
"lock_one",
"=",
"await",
"_mock_lock_from_fixture",
"(",
"hass",
",",
"\"get_lock.low_keypad_battery.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"lock_one",
"]",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"sensor_a6697750d607098bae8d6baa11ef8063_name_battery",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.a6697750d607098bae8d6baa11ef8063_name_battery\"",
")",
"assert",
"sensor_a6697750d607098bae8d6baa11ef8063_name_battery",
".",
"state",
"==",
"\"88\"",
"assert",
"(",
"sensor_a6697750d607098bae8d6baa11ef8063_name_battery",
".",
"attributes",
"[",
"\"unit_of_measurement\"",
"]",
"==",
"PERCENTAGE",
")",
"entry",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.a6697750d607098bae8d6baa11ef8063_name_battery\"",
")",
"assert",
"entry",
"assert",
"entry",
".",
"unique_id",
"==",
"\"A6697750D607098BAE8D6BAA11EF8063_device_battery\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.front_door_lock_keypad_battery\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"10\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_UNIT_OF_MEASUREMENT",
"]",
"==",
"PERCENTAGE",
"entry",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.front_door_lock_keypad_battery\"",
")",
"assert",
"entry",
"assert",
"entry",
".",
"unique_id",
"==",
"\"5bc65c24e6ef2a263e1450a8_linked_keypad_battery\"",
"# No activity means it will be unavailable until someone unlocks/locks it",
"lock_operator_sensor",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.a6697750d607098bae8d6baa11ef8063_name_operator\"",
")",
"assert",
"(",
"lock_operator_sensor",
".",
"unique_id",
"==",
"\"A6697750D607098BAE8D6BAA11EF8063_lock_operator\"",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.a6697750d607098bae8d6baa11ef8063_name_operator\"",
")",
".",
"state",
"==",
"STATE_UNAVAILABLE",
")"
] | [
83,
0
] | [
123,
5
] | python | en | ['en', 'en', 'en'] | True |
test_lock_operator_bluetooth | (hass) | Test operation of a lock with doorsense and bridge. | Test operation of a lock with doorsense and bridge. | async def test_lock_operator_bluetooth(hass):
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
activities = await _mock_activities_from_fixture(
hass, "get_activity.lock_from_bluetooth.json"
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
assert lock_operator_sensor
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").state
== "Your favorite elven princess"
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"remote"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"keypad"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"autorelock"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"method"
]
== "mobile"
) | [
"async",
"def",
"test_lock_operator_bluetooth",
"(",
"hass",
")",
":",
"lock_one",
"=",
"await",
"_mock_doorsense_enabled_august_lock_detail",
"(",
"hass",
")",
"activities",
"=",
"await",
"_mock_activities_from_fixture",
"(",
"hass",
",",
"\"get_activity.lock_from_bluetooth.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"lock_one",
"]",
",",
"activities",
"=",
"activities",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"lock_operator_sensor",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
"assert",
"lock_operator_sensor",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"state",
"==",
"\"Your favorite elven princess\"",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"remote\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"keypad\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"autorelock\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"method\"",
"]",
"==",
"\"mobile\"",
")"
] | [
126,
0
] | [
167,
5
] | python | en | ['en', 'en', 'en'] | True |
test_lock_operator_keypad | (hass) | Test operation of a lock with doorsense and bridge. | Test operation of a lock with doorsense and bridge. | async def test_lock_operator_keypad(hass):
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
activities = await _mock_activities_from_fixture(
hass, "get_activity.lock_from_keypad.json"
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
assert lock_operator_sensor
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").state
== "Your favorite elven princess"
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"remote"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"keypad"
]
is True
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"autorelock"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"method"
]
== "keypad"
) | [
"async",
"def",
"test_lock_operator_keypad",
"(",
"hass",
")",
":",
"lock_one",
"=",
"await",
"_mock_doorsense_enabled_august_lock_detail",
"(",
"hass",
")",
"activities",
"=",
"await",
"_mock_activities_from_fixture",
"(",
"hass",
",",
"\"get_activity.lock_from_keypad.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"lock_one",
"]",
",",
"activities",
"=",
"activities",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"lock_operator_sensor",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
"assert",
"lock_operator_sensor",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"state",
"==",
"\"Your favorite elven princess\"",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"remote\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"keypad\"",
"]",
"is",
"True",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"autorelock\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"method\"",
"]",
"==",
"\"keypad\"",
")"
] | [
170,
0
] | [
211,
5
] | python | en | ['en', 'en', 'en'] | True |
test_lock_operator_remote | (hass) | Test operation of a lock with doorsense and bridge. | Test operation of a lock with doorsense and bridge. | async def test_lock_operator_remote(hass):
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
activities = await _mock_activities_from_fixture(hass, "get_activity.lock.json")
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
assert lock_operator_sensor
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").state
== "Your favorite elven princess"
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"remote"
]
is True
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"keypad"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"autorelock"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"method"
]
== "remote"
) | [
"async",
"def",
"test_lock_operator_remote",
"(",
"hass",
")",
":",
"lock_one",
"=",
"await",
"_mock_doorsense_enabled_august_lock_detail",
"(",
"hass",
")",
"activities",
"=",
"await",
"_mock_activities_from_fixture",
"(",
"hass",
",",
"\"get_activity.lock.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"lock_one",
"]",
",",
"activities",
"=",
"activities",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"lock_operator_sensor",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
"assert",
"lock_operator_sensor",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"state",
"==",
"\"Your favorite elven princess\"",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"remote\"",
"]",
"is",
"True",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"keypad\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"autorelock\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"method\"",
"]",
"==",
"\"remote\"",
")"
] | [
214,
0
] | [
253,
5
] | python | en | ['en', 'en', 'en'] | True |
test_lock_operator_autorelock | (hass) | Test operation of a lock with doorsense and bridge. | Test operation of a lock with doorsense and bridge. | async def test_lock_operator_autorelock(hass):
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
activities = await _mock_activities_from_fixture(
hass, "get_activity.lock_from_autorelock.json"
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
assert lock_operator_sensor
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").state
== "Auto Relock"
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"remote"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"keypad"
]
is False
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"autorelock"
]
is True
)
assert (
hass.states.get("sensor.online_with_doorsense_name_operator").attributes[
"method"
]
== "autorelock"
) | [
"async",
"def",
"test_lock_operator_autorelock",
"(",
"hass",
")",
":",
"lock_one",
"=",
"await",
"_mock_doorsense_enabled_august_lock_detail",
"(",
"hass",
")",
"activities",
"=",
"await",
"_mock_activities_from_fixture",
"(",
"hass",
",",
"\"get_activity.lock_from_autorelock.json\"",
")",
"await",
"_create_august_with_devices",
"(",
"hass",
",",
"[",
"lock_one",
"]",
",",
"activities",
"=",
"activities",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"lock_operator_sensor",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
"assert",
"lock_operator_sensor",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"state",
"==",
"\"Auto Relock\"",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"remote\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"keypad\"",
"]",
"is",
"False",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"autorelock\"",
"]",
"is",
"True",
")",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.online_with_doorsense_name_operator\"",
")",
".",
"attributes",
"[",
"\"method\"",
"]",
"==",
"\"autorelock\"",
")"
] | [
256,
0
] | [
297,
5
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, base_config) | Set up the Fibaro Component. | Set up the Fibaro Component. | def setup(hass, base_config):
"""Set up the Fibaro Component."""
gateways = base_config[DOMAIN][CONF_GATEWAYS]
hass.data[FIBARO_CONTROLLERS] = {}
def stop_fibaro(event):
"""Stop Fibaro Thread."""
_LOGGER.info("Shutting down Fibaro connection")
for controller in hass.data[FIBARO_CONTROLLERS].values():
controller.disable_state_handler()
hass.data[FIBARO_DEVICES] = {}
for component in FIBARO_COMPONENTS:
hass.data[FIBARO_DEVICES][component] = []
for gateway in gateways:
controller = FibaroController(gateway)
if controller.connect():
hass.data[FIBARO_CONTROLLERS][controller.hub_serial] = controller
for component in FIBARO_COMPONENTS:
hass.data[FIBARO_DEVICES][component].extend(
controller.fibaro_devices[component]
)
if hass.data[FIBARO_CONTROLLERS]:
for component in FIBARO_COMPONENTS:
discovery.load_platform(hass, component, DOMAIN, {}, base_config)
for controller in hass.data[FIBARO_CONTROLLERS].values():
controller.enable_state_handler()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_fibaro)
return True
return False | [
"def",
"setup",
"(",
"hass",
",",
"base_config",
")",
":",
"gateways",
"=",
"base_config",
"[",
"DOMAIN",
"]",
"[",
"CONF_GATEWAYS",
"]",
"hass",
".",
"data",
"[",
"FIBARO_CONTROLLERS",
"]",
"=",
"{",
"}",
"def",
"stop_fibaro",
"(",
"event",
")",
":",
"\"\"\"Stop Fibaro Thread.\"\"\"",
"_LOGGER",
".",
"info",
"(",
"\"Shutting down Fibaro connection\"",
")",
"for",
"controller",
"in",
"hass",
".",
"data",
"[",
"FIBARO_CONTROLLERS",
"]",
".",
"values",
"(",
")",
":",
"controller",
".",
"disable_state_handler",
"(",
")",
"hass",
".",
"data",
"[",
"FIBARO_DEVICES",
"]",
"=",
"{",
"}",
"for",
"component",
"in",
"FIBARO_COMPONENTS",
":",
"hass",
".",
"data",
"[",
"FIBARO_DEVICES",
"]",
"[",
"component",
"]",
"=",
"[",
"]",
"for",
"gateway",
"in",
"gateways",
":",
"controller",
"=",
"FibaroController",
"(",
"gateway",
")",
"if",
"controller",
".",
"connect",
"(",
")",
":",
"hass",
".",
"data",
"[",
"FIBARO_CONTROLLERS",
"]",
"[",
"controller",
".",
"hub_serial",
"]",
"=",
"controller",
"for",
"component",
"in",
"FIBARO_COMPONENTS",
":",
"hass",
".",
"data",
"[",
"FIBARO_DEVICES",
"]",
"[",
"component",
"]",
".",
"extend",
"(",
"controller",
".",
"fibaro_devices",
"[",
"component",
"]",
")",
"if",
"hass",
".",
"data",
"[",
"FIBARO_CONTROLLERS",
"]",
":",
"for",
"component",
"in",
"FIBARO_COMPONENTS",
":",
"discovery",
".",
"load_platform",
"(",
"hass",
",",
"component",
",",
"DOMAIN",
",",
"{",
"}",
",",
"base_config",
")",
"for",
"controller",
"in",
"hass",
".",
"data",
"[",
"FIBARO_CONTROLLERS",
"]",
".",
"values",
"(",
")",
":",
"controller",
".",
"enable_state_handler",
"(",
")",
"hass",
".",
"bus",
".",
"listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"stop_fibaro",
")",
"return",
"True",
"return",
"False"
] | [
355,
0
] | [
387,
16
] | python | en | ['en', 'ca', 'en'] | True |
FibaroController.__init__ | (self, config) | Initialize the Fibaro controller. | Initialize the Fibaro controller. | def __init__(self, config):
"""Initialize the Fibaro controller."""
self._client = FibaroClient(
config[CONF_URL], config[CONF_USERNAME], config[CONF_PASSWORD]
)
self._scene_map = None
# Whether to import devices from plugins
self._import_plugins = config[CONF_PLUGINS]
self._device_config = config[CONF_DEVICE_CONFIG]
self._room_map = None # Mapping roomId to room object
self._device_map = None # Mapping deviceId to device object
self.fibaro_devices = None # List of devices by type
self._callbacks = {} # Update value callbacks by deviceId
self._state_handler = None # Fiblary's StateHandler object
self._excluded_devices = config[CONF_EXCLUDE]
self.hub_serial = None | [
"def",
"__init__",
"(",
"self",
",",
"config",
")",
":",
"self",
".",
"_client",
"=",
"FibaroClient",
"(",
"config",
"[",
"CONF_URL",
"]",
",",
"config",
"[",
"CONF_USERNAME",
"]",
",",
"config",
"[",
"CONF_PASSWORD",
"]",
")",
"self",
".",
"_scene_map",
"=",
"None",
"# Whether to import devices from plugins",
"self",
".",
"_import_plugins",
"=",
"config",
"[",
"CONF_PLUGINS",
"]",
"self",
".",
"_device_config",
"=",
"config",
"[",
"CONF_DEVICE_CONFIG",
"]",
"self",
".",
"_room_map",
"=",
"None",
"# Mapping roomId to room object",
"self",
".",
"_device_map",
"=",
"None",
"# Mapping deviceId to device object",
"self",
".",
"fibaro_devices",
"=",
"None",
"# List of devices by type",
"self",
".",
"_callbacks",
"=",
"{",
"}",
"# Update value callbacks by deviceId",
"self",
".",
"_state_handler",
"=",
"None",
"# Fiblary's StateHandler object",
"self",
".",
"_excluded_devices",
"=",
"config",
"[",
"CONF_EXCLUDE",
"]",
"self",
".",
"hub_serial",
"=",
"None"
] | [
113,
4
] | [
129,
30
] | python | en | ['en', 'en', 'en'] | True |
FibaroController.connect | (self) | Start the communication with the Fibaro controller. | Start the communication with the Fibaro controller. | def connect(self):
"""Start the communication with the Fibaro controller."""
try:
login = self._client.login.get()
info = self._client.info.get()
self.hub_serial = slugify(info.serialNumber)
except AssertionError:
_LOGGER.error("Can't connect to Fibaro HC. Please check URL")
return False
if login is None or login.status is False:
_LOGGER.error(
"Invalid login for Fibaro HC. Please check username and password"
)
return False
self._room_map = {room.id: room for room in self._client.rooms.list()}
self._read_devices()
self._read_scenes()
return True | [
"def",
"connect",
"(",
"self",
")",
":",
"try",
":",
"login",
"=",
"self",
".",
"_client",
".",
"login",
".",
"get",
"(",
")",
"info",
"=",
"self",
".",
"_client",
".",
"info",
".",
"get",
"(",
")",
"self",
".",
"hub_serial",
"=",
"slugify",
"(",
"info",
".",
"serialNumber",
")",
"except",
"AssertionError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Can't connect to Fibaro HC. Please check URL\"",
")",
"return",
"False",
"if",
"login",
"is",
"None",
"or",
"login",
".",
"status",
"is",
"False",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid login for Fibaro HC. Please check username and password\"",
")",
"return",
"False",
"self",
".",
"_room_map",
"=",
"{",
"room",
".",
"id",
":",
"room",
"for",
"room",
"in",
"self",
".",
"_client",
".",
"rooms",
".",
"list",
"(",
")",
"}",
"self",
".",
"_read_devices",
"(",
")",
"self",
".",
"_read_scenes",
"(",
")",
"return",
"True"
] | [
131,
4
] | [
149,
19
] | python | en | ['en', 'en', 'en'] | True |
FibaroController.enable_state_handler | (self) | Start StateHandler thread for monitoring updates. | Start StateHandler thread for monitoring updates. | def enable_state_handler(self):
"""Start StateHandler thread for monitoring updates."""
self._state_handler = StateHandler(self._client, self._on_state_change) | [
"def",
"enable_state_handler",
"(",
"self",
")",
":",
"self",
".",
"_state_handler",
"=",
"StateHandler",
"(",
"self",
".",
"_client",
",",
"self",
".",
"_on_state_change",
")"
] | [
151,
4
] | [
153,
79
] | python | en | ['en', 'no', 'en'] | True |
FibaroController.disable_state_handler | (self) | Stop StateHandler thread used for monitoring updates. | Stop StateHandler thread used for monitoring updates. | def disable_state_handler(self):
"""Stop StateHandler thread used for monitoring updates."""
self._state_handler.stop()
self._state_handler = None | [
"def",
"disable_state_handler",
"(",
"self",
")",
":",
"self",
".",
"_state_handler",
".",
"stop",
"(",
")",
"self",
".",
"_state_handler",
"=",
"None"
] | [
155,
4
] | [
158,
34
] | python | en | ['en', 'en', 'en'] | True |
FibaroController._on_state_change | (self, state) | Handle change report received from the HomeCenter. | Handle change report received from the HomeCenter. | def _on_state_change(self, state):
"""Handle change report received from the HomeCenter."""
callback_set = set()
for change in state.get("changes", []):
try:
dev_id = change.pop("id")
if dev_id not in self._device_map:
continue
device = self._device_map[dev_id]
for property_name, value in change.items():
if property_name == "log":
if value and value != "transfer OK":
_LOGGER.debug("LOG %s: %s", device.friendly_name, value)
continue
if property_name == "logTemp":
continue
if property_name in device.properties:
device.properties[property_name] = value
_LOGGER.debug(
"<- %s.%s = %s", device.ha_id, property_name, str(value)
)
else:
_LOGGER.warning("%s.%s not found", device.ha_id, property_name)
if dev_id in self._callbacks:
callback_set.add(dev_id)
except (ValueError, KeyError):
pass
for item in callback_set:
self._callbacks[item]() | [
"def",
"_on_state_change",
"(",
"self",
",",
"state",
")",
":",
"callback_set",
"=",
"set",
"(",
")",
"for",
"change",
"in",
"state",
".",
"get",
"(",
"\"changes\"",
",",
"[",
"]",
")",
":",
"try",
":",
"dev_id",
"=",
"change",
".",
"pop",
"(",
"\"id\"",
")",
"if",
"dev_id",
"not",
"in",
"self",
".",
"_device_map",
":",
"continue",
"device",
"=",
"self",
".",
"_device_map",
"[",
"dev_id",
"]",
"for",
"property_name",
",",
"value",
"in",
"change",
".",
"items",
"(",
")",
":",
"if",
"property_name",
"==",
"\"log\"",
":",
"if",
"value",
"and",
"value",
"!=",
"\"transfer OK\"",
":",
"_LOGGER",
".",
"debug",
"(",
"\"LOG %s: %s\"",
",",
"device",
".",
"friendly_name",
",",
"value",
")",
"continue",
"if",
"property_name",
"==",
"\"logTemp\"",
":",
"continue",
"if",
"property_name",
"in",
"device",
".",
"properties",
":",
"device",
".",
"properties",
"[",
"property_name",
"]",
"=",
"value",
"_LOGGER",
".",
"debug",
"(",
"\"<- %s.%s = %s\"",
",",
"device",
".",
"ha_id",
",",
"property_name",
",",
"str",
"(",
"value",
")",
")",
"else",
":",
"_LOGGER",
".",
"warning",
"(",
"\"%s.%s not found\"",
",",
"device",
".",
"ha_id",
",",
"property_name",
")",
"if",
"dev_id",
"in",
"self",
".",
"_callbacks",
":",
"callback_set",
".",
"add",
"(",
"dev_id",
")",
"except",
"(",
"ValueError",
",",
"KeyError",
")",
":",
"pass",
"for",
"item",
"in",
"callback_set",
":",
"self",
".",
"_callbacks",
"[",
"item",
"]",
"(",
")"
] | [
160,
4
] | [
188,
35
] | python | en | ['en', 'en', 'en'] | True |
FibaroController.register | (self, device_id, callback) | Register device with a callback for updates. | Register device with a callback for updates. | def register(self, device_id, callback):
"""Register device with a callback for updates."""
self._callbacks[device_id] = callback | [
"def",
"register",
"(",
"self",
",",
"device_id",
",",
"callback",
")",
":",
"self",
".",
"_callbacks",
"[",
"device_id",
"]",
"=",
"callback"
] | [
190,
4
] | [
192,
45
] | python | en | ['en', 'en', 'en'] | True |
FibaroController.get_children | (self, device_id) | Get a list of child devices. | Get a list of child devices. | def get_children(self, device_id):
"""Get a list of child devices."""
return [
device
for device in self._device_map.values()
if device.parentId == device_id
] | [
"def",
"get_children",
"(",
"self",
",",
"device_id",
")",
":",
"return",
"[",
"device",
"for",
"device",
"in",
"self",
".",
"_device_map",
".",
"values",
"(",
")",
"if",
"device",
".",
"parentId",
"==",
"device_id",
"]"
] | [
194,
4
] | [
200,
9
] | python | en | ['en', 'en', 'en'] | True |
FibaroController.get_children2 | (self, device_id, endpoint_id) | Get a list of child devices for the same endpoint. | Get a list of child devices for the same endpoint. | def get_children2(self, device_id, endpoint_id):
"""Get a list of child devices for the same endpoint."""
return [
device
for device in self._device_map.values()
if device.parentId == device_id
and (
"endPointId" not in device.properties
or device.properties.endPointId == endpoint_id
)
] | [
"def",
"get_children2",
"(",
"self",
",",
"device_id",
",",
"endpoint_id",
")",
":",
"return",
"[",
"device",
"for",
"device",
"in",
"self",
".",
"_device_map",
".",
"values",
"(",
")",
"if",
"device",
".",
"parentId",
"==",
"device_id",
"and",
"(",
"\"endPointId\"",
"not",
"in",
"device",
".",
"properties",
"or",
"device",
".",
"properties",
".",
"endPointId",
"==",
"endpoint_id",
")",
"]"
] | [
202,
4
] | [
212,
9
] | python | en | ['en', 'en', 'en'] | True |
FibaroController.get_siblings | (self, device) | Get the siblings of a device. | Get the siblings of a device. | def get_siblings(self, device):
"""Get the siblings of a device."""
if "endPointId" in device.properties:
return self.get_children2(
self._device_map[device.id].parentId,
self._device_map[device.id].properties.endPointId,
)
return self.get_children(self._device_map[device.id].parentId) | [
"def",
"get_siblings",
"(",
"self",
",",
"device",
")",
":",
"if",
"\"endPointId\"",
"in",
"device",
".",
"properties",
":",
"return",
"self",
".",
"get_children2",
"(",
"self",
".",
"_device_map",
"[",
"device",
".",
"id",
"]",
".",
"parentId",
",",
"self",
".",
"_device_map",
"[",
"device",
".",
"id",
"]",
".",
"properties",
".",
"endPointId",
",",
")",
"return",
"self",
".",
"get_children",
"(",
"self",
".",
"_device_map",
"[",
"device",
".",
"id",
"]",
".",
"parentId",
")"
] | [
214,
4
] | [
221,
70
] | python | en | ['en', 'en', 'en'] | True |
FibaroController._map_device_to_type | (device) | Map device to HA device type. | Map device to HA device type. | def _map_device_to_type(device):
"""Map device to HA device type."""
# Use our lookup table to identify device type
device_type = None
if "type" in device:
device_type = FIBARO_TYPEMAP.get(device.type)
if device_type is None and "baseType" in device:
device_type = FIBARO_TYPEMAP.get(device.baseType)
# We can also identify device type by its capabilities
if device_type is None:
if "setBrightness" in device.actions:
device_type = "light"
elif "turnOn" in device.actions:
device_type = "switch"
elif "open" in device.actions:
device_type = "cover"
elif "secure" in device.actions:
device_type = "lock"
elif "value" in device.properties:
if device.properties.value in ("true", "false"):
device_type = "binary_sensor"
else:
device_type = "sensor"
# Switches that control lights should show up as lights
if device_type == "switch" and device.properties.get("isLight", False):
device_type = "light"
return device_type | [
"def",
"_map_device_to_type",
"(",
"device",
")",
":",
"# Use our lookup table to identify device type",
"device_type",
"=",
"None",
"if",
"\"type\"",
"in",
"device",
":",
"device_type",
"=",
"FIBARO_TYPEMAP",
".",
"get",
"(",
"device",
".",
"type",
")",
"if",
"device_type",
"is",
"None",
"and",
"\"baseType\"",
"in",
"device",
":",
"device_type",
"=",
"FIBARO_TYPEMAP",
".",
"get",
"(",
"device",
".",
"baseType",
")",
"# We can also identify device type by its capabilities",
"if",
"device_type",
"is",
"None",
":",
"if",
"\"setBrightness\"",
"in",
"device",
".",
"actions",
":",
"device_type",
"=",
"\"light\"",
"elif",
"\"turnOn\"",
"in",
"device",
".",
"actions",
":",
"device_type",
"=",
"\"switch\"",
"elif",
"\"open\"",
"in",
"device",
".",
"actions",
":",
"device_type",
"=",
"\"cover\"",
"elif",
"\"secure\"",
"in",
"device",
".",
"actions",
":",
"device_type",
"=",
"\"lock\"",
"elif",
"\"value\"",
"in",
"device",
".",
"properties",
":",
"if",
"device",
".",
"properties",
".",
"value",
"in",
"(",
"\"true\"",
",",
"\"false\"",
")",
":",
"device_type",
"=",
"\"binary_sensor\"",
"else",
":",
"device_type",
"=",
"\"sensor\"",
"# Switches that control lights should show up as lights",
"if",
"device_type",
"==",
"\"switch\"",
"and",
"device",
".",
"properties",
".",
"get",
"(",
"\"isLight\"",
",",
"False",
")",
":",
"device_type",
"=",
"\"light\"",
"return",
"device_type"
] | [
224,
4
] | [
252,
26
] | python | en | ['en', 'en', 'en'] | True |
FibaroController._read_devices | (self) | Read and process the device list. | Read and process the device list. | def _read_devices(self):
"""Read and process the device list."""
devices = self._client.devices.list()
self._device_map = {}
self.fibaro_devices = defaultdict(list)
last_climate_parent = None
last_endpoint = None
for device in devices:
try:
if "name" not in device or "id" not in device:
continue
device.fibaro_controller = self
if "roomID" not in device or device.roomID == 0:
room_name = "Unknown"
else:
room_name = self._room_map[device.roomID].name
device.room_name = room_name
device.friendly_name = f"{room_name} {device.name}"
device.ha_id = (
f"{slugify(room_name)}_{slugify(device.name)}_{device.id}"
)
if (
device.enabled
and (
"isPlugin" not in device
or (not device.isPlugin or self._import_plugins)
)
and device.ha_id not in self._excluded_devices
):
device.mapped_type = self._map_device_to_type(device)
device.device_config = self._device_config.get(device.ha_id, {})
else:
device.mapped_type = None
dtype = device.mapped_type
if dtype is None:
continue
device.unique_id_str = f"{self.hub_serial}.{device.id}"
self._device_map[device.id] = device
_LOGGER.debug(
"%s (%s, %s) -> %s %s",
device.ha_id,
device.type,
device.baseType,
dtype,
str(device),
)
if dtype != "climate":
self.fibaro_devices[dtype].append(device)
continue
# We group climate devices into groups with the same
# endPointID belonging to the same parent device.
if "endPointId" in device.properties:
_LOGGER.debug(
"climate device: %s, endPointId: %s",
device.ha_id,
device.properties.endPointId,
)
else:
_LOGGER.debug("climate device: %s, no endPointId", device.ha_id)
# If a sibling of this device has been added, skip this one
# otherwise add the first visible device in the group
# which is a hack, but solves a problem with FGT having
# hidden compatibility devices before the real device
if last_climate_parent != device.parentId or (
"endPointId" in device.properties
and last_endpoint != device.properties.endPointId
):
_LOGGER.debug("Handle separately")
self.fibaro_devices[dtype].append(device)
last_climate_parent = device.parentId
if "endPointId" in device.properties:
last_endpoint = device.properties.endPointId
else:
last_endpoint = 0
else:
_LOGGER.debug("not handling separately")
except (KeyError, ValueError):
pass | [
"def",
"_read_devices",
"(",
"self",
")",
":",
"devices",
"=",
"self",
".",
"_client",
".",
"devices",
".",
"list",
"(",
")",
"self",
".",
"_device_map",
"=",
"{",
"}",
"self",
".",
"fibaro_devices",
"=",
"defaultdict",
"(",
"list",
")",
"last_climate_parent",
"=",
"None",
"last_endpoint",
"=",
"None",
"for",
"device",
"in",
"devices",
":",
"try",
":",
"if",
"\"name\"",
"not",
"in",
"device",
"or",
"\"id\"",
"not",
"in",
"device",
":",
"continue",
"device",
".",
"fibaro_controller",
"=",
"self",
"if",
"\"roomID\"",
"not",
"in",
"device",
"or",
"device",
".",
"roomID",
"==",
"0",
":",
"room_name",
"=",
"\"Unknown\"",
"else",
":",
"room_name",
"=",
"self",
".",
"_room_map",
"[",
"device",
".",
"roomID",
"]",
".",
"name",
"device",
".",
"room_name",
"=",
"room_name",
"device",
".",
"friendly_name",
"=",
"f\"{room_name} {device.name}\"",
"device",
".",
"ha_id",
"=",
"(",
"f\"{slugify(room_name)}_{slugify(device.name)}_{device.id}\"",
")",
"if",
"(",
"device",
".",
"enabled",
"and",
"(",
"\"isPlugin\"",
"not",
"in",
"device",
"or",
"(",
"not",
"device",
".",
"isPlugin",
"or",
"self",
".",
"_import_plugins",
")",
")",
"and",
"device",
".",
"ha_id",
"not",
"in",
"self",
".",
"_excluded_devices",
")",
":",
"device",
".",
"mapped_type",
"=",
"self",
".",
"_map_device_to_type",
"(",
"device",
")",
"device",
".",
"device_config",
"=",
"self",
".",
"_device_config",
".",
"get",
"(",
"device",
".",
"ha_id",
",",
"{",
"}",
")",
"else",
":",
"device",
".",
"mapped_type",
"=",
"None",
"dtype",
"=",
"device",
".",
"mapped_type",
"if",
"dtype",
"is",
"None",
":",
"continue",
"device",
".",
"unique_id_str",
"=",
"f\"{self.hub_serial}.{device.id}\"",
"self",
".",
"_device_map",
"[",
"device",
".",
"id",
"]",
"=",
"device",
"_LOGGER",
".",
"debug",
"(",
"\"%s (%s, %s) -> %s %s\"",
",",
"device",
".",
"ha_id",
",",
"device",
".",
"type",
",",
"device",
".",
"baseType",
",",
"dtype",
",",
"str",
"(",
"device",
")",
",",
")",
"if",
"dtype",
"!=",
"\"climate\"",
":",
"self",
".",
"fibaro_devices",
"[",
"dtype",
"]",
".",
"append",
"(",
"device",
")",
"continue",
"# We group climate devices into groups with the same",
"# endPointID belonging to the same parent device.",
"if",
"\"endPointId\"",
"in",
"device",
".",
"properties",
":",
"_LOGGER",
".",
"debug",
"(",
"\"climate device: %s, endPointId: %s\"",
",",
"device",
".",
"ha_id",
",",
"device",
".",
"properties",
".",
"endPointId",
",",
")",
"else",
":",
"_LOGGER",
".",
"debug",
"(",
"\"climate device: %s, no endPointId\"",
",",
"device",
".",
"ha_id",
")",
"# If a sibling of this device has been added, skip this one",
"# otherwise add the first visible device in the group",
"# which is a hack, but solves a problem with FGT having",
"# hidden compatibility devices before the real device",
"if",
"last_climate_parent",
"!=",
"device",
".",
"parentId",
"or",
"(",
"\"endPointId\"",
"in",
"device",
".",
"properties",
"and",
"last_endpoint",
"!=",
"device",
".",
"properties",
".",
"endPointId",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Handle separately\"",
")",
"self",
".",
"fibaro_devices",
"[",
"dtype",
"]",
".",
"append",
"(",
"device",
")",
"last_climate_parent",
"=",
"device",
".",
"parentId",
"if",
"\"endPointId\"",
"in",
"device",
".",
"properties",
":",
"last_endpoint",
"=",
"device",
".",
"properties",
".",
"endPointId",
"else",
":",
"last_endpoint",
"=",
"0",
"else",
":",
"_LOGGER",
".",
"debug",
"(",
"\"not handling separately\"",
")",
"except",
"(",
"KeyError",
",",
"ValueError",
")",
":",
"pass"
] | [
275,
4
] | [
352,
20
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.__init__ | (self, fibaro_device) | Initialize the device. | Initialize the device. | def __init__(self, fibaro_device):
"""Initialize the device."""
self.fibaro_device = fibaro_device
self.controller = fibaro_device.fibaro_controller
self._name = fibaro_device.friendly_name
self.ha_id = fibaro_device.ha_id | [
"def",
"__init__",
"(",
"self",
",",
"fibaro_device",
")",
":",
"self",
".",
"fibaro_device",
"=",
"fibaro_device",
"self",
".",
"controller",
"=",
"fibaro_device",
".",
"fibaro_controller",
"self",
".",
"_name",
"=",
"fibaro_device",
".",
"friendly_name",
"self",
".",
"ha_id",
"=",
"fibaro_device",
".",
"ha_id"
] | [
393,
4
] | [
398,
40
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.async_added_to_hass | (self) | Call when entity is added to hass. | Call when entity is added to hass. | async def async_added_to_hass(self):
"""Call when entity is added to hass."""
self.controller.register(self.fibaro_device.id, self._update_callback) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"controller",
".",
"register",
"(",
"self",
".",
"fibaro_device",
".",
"id",
",",
"self",
".",
"_update_callback",
")"
] | [
400,
4
] | [
402,
78
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice._update_callback | (self) | Update the state. | Update the state. | def _update_callback(self):
"""Update the state."""
self.schedule_update_ha_state(True) | [
"def",
"_update_callback",
"(",
"self",
")",
":",
"self",
".",
"schedule_update_ha_state",
"(",
"True",
")"
] | [
404,
4
] | [
406,
43
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.level | (self) | Get the level of Fibaro device. | Get the level of Fibaro device. | def level(self):
"""Get the level of Fibaro device."""
if "value" in self.fibaro_device.properties:
return self.fibaro_device.properties.value
return None | [
"def",
"level",
"(",
"self",
")",
":",
"if",
"\"value\"",
"in",
"self",
".",
"fibaro_device",
".",
"properties",
":",
"return",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"value",
"return",
"None"
] | [
409,
4
] | [
413,
19
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.level2 | (self) | Get the tilt level of Fibaro device. | Get the tilt level of Fibaro device. | def level2(self):
"""Get the tilt level of Fibaro device."""
if "value2" in self.fibaro_device.properties:
return self.fibaro_device.properties.value2
return None | [
"def",
"level2",
"(",
"self",
")",
":",
"if",
"\"value2\"",
"in",
"self",
".",
"fibaro_device",
".",
"properties",
":",
"return",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"value2",
"return",
"None"
] | [
416,
4
] | [
420,
19
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.dont_know_message | (self, action) | Make a warning in case we don't know how to perform an action. | Make a warning in case we don't know how to perform an action. | def dont_know_message(self, action):
"""Make a warning in case we don't know how to perform an action."""
_LOGGER.warning(
"Not sure how to setValue: %s (available actions: %s)",
str(self.ha_id),
str(self.fibaro_device.actions),
) | [
"def",
"dont_know_message",
"(",
"self",
",",
"action",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Not sure how to setValue: %s (available actions: %s)\"",
",",
"str",
"(",
"self",
".",
"ha_id",
")",
",",
"str",
"(",
"self",
".",
"fibaro_device",
".",
"actions",
")",
",",
")"
] | [
422,
4
] | [
428,
9
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.set_level | (self, level) | Set the level of Fibaro device. | Set the level of Fibaro device. | def set_level(self, level):
"""Set the level of Fibaro device."""
self.action("setValue", level)
if "value" in self.fibaro_device.properties:
self.fibaro_device.properties.value = level
if "brightness" in self.fibaro_device.properties:
self.fibaro_device.properties.brightness = level | [
"def",
"set_level",
"(",
"self",
",",
"level",
")",
":",
"self",
".",
"action",
"(",
"\"setValue\"",
",",
"level",
")",
"if",
"\"value\"",
"in",
"self",
".",
"fibaro_device",
".",
"properties",
":",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"value",
"=",
"level",
"if",
"\"brightness\"",
"in",
"self",
".",
"fibaro_device",
".",
"properties",
":",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"brightness",
"=",
"level"
] | [
430,
4
] | [
436,
60
] | python | en | ['en', 'sr', 'en'] | True |
FibaroDevice.set_level2 | (self, level) | Set the level2 of Fibaro device. | Set the level2 of Fibaro device. | def set_level2(self, level):
"""Set the level2 of Fibaro device."""
self.action("setValue2", level)
if "value2" in self.fibaro_device.properties:
self.fibaro_device.properties.value2 = level | [
"def",
"set_level2",
"(",
"self",
",",
"level",
")",
":",
"self",
".",
"action",
"(",
"\"setValue2\"",
",",
"level",
")",
"if",
"\"value2\"",
"in",
"self",
".",
"fibaro_device",
".",
"properties",
":",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"value2",
"=",
"level"
] | [
438,
4
] | [
442,
56
] | python | en | ['en', 'sr', 'en'] | True |
FibaroDevice.call_turn_on | (self) | Turn on the Fibaro device. | Turn on the Fibaro device. | def call_turn_on(self):
"""Turn on the Fibaro device."""
self.action("turnOn") | [
"def",
"call_turn_on",
"(",
"self",
")",
":",
"self",
".",
"action",
"(",
"\"turnOn\"",
")"
] | [
444,
4
] | [
446,
29
] | python | en | ['en', 'yo', 'en'] | True |
FibaroDevice.call_turn_off | (self) | Turn off the Fibaro device. | Turn off the Fibaro device. | def call_turn_off(self):
"""Turn off the Fibaro device."""
self.action("turnOff") | [
"def",
"call_turn_off",
"(",
"self",
")",
":",
"self",
".",
"action",
"(",
"\"turnOff\"",
")"
] | [
448,
4
] | [
450,
30
] | python | en | ['en', 'yo', 'en'] | True |
FibaroDevice.call_set_color | (self, red, green, blue, white) | Set the color of Fibaro device. | Set the color of Fibaro device. | def call_set_color(self, red, green, blue, white):
"""Set the color of Fibaro device."""
red = int(max(0, min(255, red)))
green = int(max(0, min(255, green)))
blue = int(max(0, min(255, blue)))
white = int(max(0, min(255, white)))
color_str = f"{red},{green},{blue},{white}"
self.fibaro_device.properties.color = color_str
self.action("setColor", str(red), str(green), str(blue), str(white)) | [
"def",
"call_set_color",
"(",
"self",
",",
"red",
",",
"green",
",",
"blue",
",",
"white",
")",
":",
"red",
"=",
"int",
"(",
"max",
"(",
"0",
",",
"min",
"(",
"255",
",",
"red",
")",
")",
")",
"green",
"=",
"int",
"(",
"max",
"(",
"0",
",",
"min",
"(",
"255",
",",
"green",
")",
")",
")",
"blue",
"=",
"int",
"(",
"max",
"(",
"0",
",",
"min",
"(",
"255",
",",
"blue",
")",
")",
")",
"white",
"=",
"int",
"(",
"max",
"(",
"0",
",",
"min",
"(",
"255",
",",
"white",
")",
")",
")",
"color_str",
"=",
"f\"{red},{green},{blue},{white}\"",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"color",
"=",
"color_str",
"self",
".",
"action",
"(",
"\"setColor\"",
",",
"str",
"(",
"red",
")",
",",
"str",
"(",
"green",
")",
",",
"str",
"(",
"blue",
")",
",",
"str",
"(",
"white",
")",
")"
] | [
452,
4
] | [
460,
76
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.action | (self, cmd, *args) | Perform an action on the Fibaro HC. | Perform an action on the Fibaro HC. | def action(self, cmd, *args):
"""Perform an action on the Fibaro HC."""
if cmd in self.fibaro_device.actions:
getattr(self.fibaro_device, cmd)(*args)
_LOGGER.debug("-> %s.%s%s called", str(self.ha_id), str(cmd), str(args))
else:
self.dont_know_message(cmd) | [
"def",
"action",
"(",
"self",
",",
"cmd",
",",
"*",
"args",
")",
":",
"if",
"cmd",
"in",
"self",
".",
"fibaro_device",
".",
"actions",
":",
"getattr",
"(",
"self",
".",
"fibaro_device",
",",
"cmd",
")",
"(",
"*",
"args",
")",
"_LOGGER",
".",
"debug",
"(",
"\"-> %s.%s%s called\"",
",",
"str",
"(",
"self",
".",
"ha_id",
")",
",",
"str",
"(",
"cmd",
")",
",",
"str",
"(",
"args",
")",
")",
"else",
":",
"self",
".",
"dont_know_message",
"(",
"cmd",
")"
] | [
462,
4
] | [
468,
39
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.current_power_w | (self) | Return the current power usage in W. | Return the current power usage in W. | def current_power_w(self):
"""Return the current power usage in W."""
if "power" in self.fibaro_device.properties:
power = self.fibaro_device.properties.power
if power:
return convert(power, float, 0.0)
else:
return None | [
"def",
"current_power_w",
"(",
"self",
")",
":",
"if",
"\"power\"",
"in",
"self",
".",
"fibaro_device",
".",
"properties",
":",
"power",
"=",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"power",
"if",
"power",
":",
"return",
"convert",
"(",
"power",
",",
"float",
",",
"0.0",
")",
"else",
":",
"return",
"None"
] | [
471,
4
] | [
478,
23
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.current_binary_state | (self) | Return the current binary state. | Return the current binary state. | def current_binary_state(self):
"""Return the current binary state."""
if self.fibaro_device.properties.value == "false":
return False
if (
self.fibaro_device.properties.value == "true"
or int(self.fibaro_device.properties.value) > 0
):
return True
return False | [
"def",
"current_binary_state",
"(",
"self",
")",
":",
"if",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"value",
"==",
"\"false\"",
":",
"return",
"False",
"if",
"(",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"value",
"==",
"\"true\"",
"or",
"int",
"(",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"value",
")",
">",
"0",
")",
":",
"return",
"True",
"return",
"False"
] | [
481,
4
] | [
490,
20
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self) -> str:
"""Return a unique ID."""
return self.fibaro_device.unique_id_str | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"fibaro_device",
".",
"unique_id_str"
] | [
493,
4
] | [
495,
47
] | python | ca | ['fr', 'ca', 'en'] | False |
FibaroDevice.name | (self) | Return the name of the device. | Return the name of the device. | def name(self) -> Optional[str]:
"""Return the name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"self",
".",
"_name"
] | [
498,
4
] | [
500,
25
] | python | en | ['en', 'en', 'en'] | True |
FibaroDevice.should_poll | (self) | Get polling requirement from fibaro device. | Get polling requirement from fibaro device. | def should_poll(self):
"""Get polling requirement from fibaro device."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
503,
4
] | [
505,
20
] | python | en | ['eo', 'en', 'en'] | True |
FibaroDevice.device_state_attributes | (self) | Return the state attributes of the device. | Return the state attributes of the device. | def device_state_attributes(self):
"""Return the state attributes of the device."""
attr = {"fibaro_id": self.fibaro_device.id}
try:
if "battery" in self.fibaro_device.interfaces:
attr[ATTR_BATTERY_LEVEL] = int(
self.fibaro_device.properties.batteryLevel
)
if "fibaroAlarmArm" in self.fibaro_device.interfaces:
attr[ATTR_ARMED] = bool(self.fibaro_device.properties.armed)
if "power" in self.fibaro_device.interfaces:
attr[ATTR_CURRENT_POWER_W] = convert(
self.fibaro_device.properties.power, float, 0.0
)
if "energy" in self.fibaro_device.interfaces:
attr[ATTR_CURRENT_ENERGY_KWH] = convert(
self.fibaro_device.properties.energy, float, 0.0
)
except (ValueError, KeyError):
pass
return attr | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"attr",
"=",
"{",
"\"fibaro_id\"",
":",
"self",
".",
"fibaro_device",
".",
"id",
"}",
"try",
":",
"if",
"\"battery\"",
"in",
"self",
".",
"fibaro_device",
".",
"interfaces",
":",
"attr",
"[",
"ATTR_BATTERY_LEVEL",
"]",
"=",
"int",
"(",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"batteryLevel",
")",
"if",
"\"fibaroAlarmArm\"",
"in",
"self",
".",
"fibaro_device",
".",
"interfaces",
":",
"attr",
"[",
"ATTR_ARMED",
"]",
"=",
"bool",
"(",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"armed",
")",
"if",
"\"power\"",
"in",
"self",
".",
"fibaro_device",
".",
"interfaces",
":",
"attr",
"[",
"ATTR_CURRENT_POWER_W",
"]",
"=",
"convert",
"(",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"power",
",",
"float",
",",
"0.0",
")",
"if",
"\"energy\"",
"in",
"self",
".",
"fibaro_device",
".",
"interfaces",
":",
"attr",
"[",
"ATTR_CURRENT_ENERGY_KWH",
"]",
"=",
"convert",
"(",
"self",
".",
"fibaro_device",
".",
"properties",
".",
"energy",
",",
"float",
",",
"0.0",
")",
"except",
"(",
"ValueError",
",",
"KeyError",
")",
":",
"pass",
"return",
"attr"
] | [
508,
4
] | [
530,
19
] | python | en | ['en', 'en', 'en'] | True |
test_humidifier | (hass, hk_driver, events) | Test if humidifier accessory and HA are updated accordingly. | Test if humidifier accessory and HA are updated accordingly. | async def test_humidifier(hass, hk_driver, events):
"""Test if humidifier accessory and HA are updated accordingly."""
entity_id = "humidifier.test"
hass.states.async_set(entity_id, STATE_OFF)
await hass.async_block_till_done()
acc = HumidifierDehumidifier(
hass, hk_driver, "HumidifierDehumidifier", entity_id, 1, None
)
hk_driver.add_accessory(acc)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.aid == 1
assert acc.category == CATEGORY_HUMIDIFIER
assert acc.char_current_humidifier_dehumidifier.value == 0
assert acc.char_target_humidifier_dehumidifier.value == 1
assert acc.char_current_humidity.value == 0
assert acc.char_target_humidity.value == 45.0
assert acc.char_active.value == 0
assert acc.char_target_humidity.properties[PROP_MAX_VALUE] == DEFAULT_MAX_HUMIDITY
assert acc.char_target_humidity.properties[PROP_MIN_VALUE] == DEFAULT_MIN_HUMIDITY
assert acc.char_target_humidity.properties[PROP_MIN_STEP] == 1.0
assert acc.char_target_humidifier_dehumidifier.properties[PROP_VALID_VALUES] == {
"Humidifier": 1
}
hass.states.async_set(
entity_id,
STATE_ON,
{ATTR_HUMIDITY: 47},
)
await hass.async_block_till_done()
assert acc.char_target_humidity.value == 47.0
assert acc.char_current_humidifier_dehumidifier.value == 2
assert acc.char_target_humidifier_dehumidifier.value == 1
assert acc.char_active.value == 1
hass.states.async_set(
entity_id,
STATE_OFF,
{ATTR_HUMIDITY: 42, ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDIFIER},
)
await hass.async_block_till_done()
assert acc.char_target_humidity.value == 42.0
assert acc.char_current_humidifier_dehumidifier.value == 0
assert acc.char_target_humidifier_dehumidifier.value == 1
assert acc.char_active.value == 0
# Set from HomeKit
call_set_humidity = async_mock_service(hass, DOMAIN, SERVICE_SET_HUMIDITY)
char_target_humidity_iid = acc.char_target_humidity.to_HAP()[HAP_REPR_IID]
hk_driver.set_characteristics(
{
HAP_REPR_CHARS: [
{
HAP_REPR_AID: acc.aid,
HAP_REPR_IID: char_target_humidity_iid,
HAP_REPR_VALUE: 39.0,
},
]
},
"mock_addr",
)
await hass.async_block_till_done()
assert len(call_set_humidity) == 1
assert call_set_humidity[0].data[ATTR_ENTITY_ID] == entity_id
assert call_set_humidity[0].data[ATTR_HUMIDITY] == 39.0
assert acc.char_target_humidity.value == 39.0
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] == "RelativeHumidityHumidifierThreshold to 39.0%" | [
"async",
"def",
"test_humidifier",
"(",
"hass",
",",
"hk_driver",
",",
"events",
")",
":",
"entity_id",
"=",
"\"humidifier.test\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"HumidifierDehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"\"HumidifierDehumidifier\"",
",",
"entity_id",
",",
"1",
",",
"None",
")",
"hk_driver",
".",
"add_accessory",
"(",
"acc",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"aid",
"==",
"1",
"assert",
"acc",
".",
"category",
"==",
"CATEGORY_HUMIDIFIER",
"assert",
"acc",
".",
"char_current_humidifier_dehumidifier",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"1",
"assert",
"acc",
".",
"char_current_humidity",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidity",
".",
"value",
"==",
"45.0",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidity",
".",
"properties",
"[",
"PROP_MAX_VALUE",
"]",
"==",
"DEFAULT_MAX_HUMIDITY",
"assert",
"acc",
".",
"char_target_humidity",
".",
"properties",
"[",
"PROP_MIN_VALUE",
"]",
"==",
"DEFAULT_MIN_HUMIDITY",
"assert",
"acc",
".",
"char_target_humidity",
".",
"properties",
"[",
"PROP_MIN_STEP",
"]",
"==",
"1.0",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"properties",
"[",
"PROP_VALID_VALUES",
"]",
"==",
"{",
"\"Humidifier\"",
":",
"1",
"}",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_ON",
",",
"{",
"ATTR_HUMIDITY",
":",
"47",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_target_humidity",
".",
"value",
"==",
"47.0",
"assert",
"acc",
".",
"char_current_humidifier_dehumidifier",
".",
"value",
"==",
"2",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"1",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
",",
"{",
"ATTR_HUMIDITY",
":",
"42",
",",
"ATTR_DEVICE_CLASS",
":",
"DEVICE_CLASS_HUMIDIFIER",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_target_humidity",
".",
"value",
"==",
"42.0",
"assert",
"acc",
".",
"char_current_humidifier_dehumidifier",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"1",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"0",
"# Set from HomeKit",
"call_set_humidity",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"SERVICE_SET_HUMIDITY",
")",
"char_target_humidity_iid",
"=",
"acc",
".",
"char_target_humidity",
".",
"to_HAP",
"(",
")",
"[",
"HAP_REPR_IID",
"]",
"hk_driver",
".",
"set_characteristics",
"(",
"{",
"HAP_REPR_CHARS",
":",
"[",
"{",
"HAP_REPR_AID",
":",
"acc",
".",
"aid",
",",
"HAP_REPR_IID",
":",
"char_target_humidity_iid",
",",
"HAP_REPR_VALUE",
":",
"39.0",
",",
"}",
",",
"]",
"}",
",",
"\"mock_addr\"",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"call_set_humidity",
")",
"==",
"1",
"assert",
"call_set_humidity",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"call_set_humidity",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_HUMIDITY",
"]",
"==",
"39.0",
"assert",
"acc",
".",
"char_target_humidity",
".",
"value",
"==",
"39.0",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"==",
"\"RelativeHumidityHumidifierThreshold to 39.0%\""
] | [
45,
0
] | [
121,
88
] | python | en | ['en', 'en', 'en'] | True |
test_dehumidifier | (hass, hk_driver, events) | Test if dehumidifier accessory and HA are updated accordingly. | Test if dehumidifier accessory and HA are updated accordingly. | async def test_dehumidifier(hass, hk_driver, events):
"""Test if dehumidifier accessory and HA are updated accordingly."""
entity_id = "humidifier.test"
hass.states.async_set(
entity_id, STATE_OFF, {ATTR_DEVICE_CLASS: DEVICE_CLASS_DEHUMIDIFIER}
)
await hass.async_block_till_done()
acc = HumidifierDehumidifier(
hass, hk_driver, "HumidifierDehumidifier", entity_id, 1, None
)
hk_driver.add_accessory(acc)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.aid == 1
assert acc.category == CATEGORY_HUMIDIFIER
assert acc.char_current_humidifier_dehumidifier.value == 0
assert acc.char_target_humidifier_dehumidifier.value == 2
assert acc.char_current_humidity.value == 0
assert acc.char_target_humidity.value == 45.0
assert acc.char_active.value == 0
assert acc.char_target_humidity.properties[PROP_MAX_VALUE] == DEFAULT_MAX_HUMIDITY
assert acc.char_target_humidity.properties[PROP_MIN_VALUE] == DEFAULT_MIN_HUMIDITY
assert acc.char_target_humidity.properties[PROP_MIN_STEP] == 1.0
assert acc.char_target_humidifier_dehumidifier.properties[PROP_VALID_VALUES] == {
"Dehumidifier": 2
}
hass.states.async_set(
entity_id,
STATE_ON,
{ATTR_HUMIDITY: 30},
)
await hass.async_block_till_done()
assert acc.char_target_humidity.value == 30.0
assert acc.char_current_humidifier_dehumidifier.value == 3
assert acc.char_target_humidifier_dehumidifier.value == 2
assert acc.char_active.value == 1
hass.states.async_set(
entity_id,
STATE_OFF,
{ATTR_HUMIDITY: 42},
)
await hass.async_block_till_done()
assert acc.char_target_humidity.value == 42.0
assert acc.char_current_humidifier_dehumidifier.value == 0
assert acc.char_target_humidifier_dehumidifier.value == 2
assert acc.char_active.value == 0
# Set from HomeKit
call_set_humidity = async_mock_service(hass, DOMAIN, SERVICE_SET_HUMIDITY)
char_target_humidity_iid = acc.char_target_humidity.to_HAP()[HAP_REPR_IID]
hk_driver.set_characteristics(
{
HAP_REPR_CHARS: [
{
HAP_REPR_AID: acc.aid,
HAP_REPR_IID: char_target_humidity_iid,
HAP_REPR_VALUE: 39.0,
},
]
},
"mock_addr",
)
await hass.async_block_till_done()
assert len(call_set_humidity) == 1
assert call_set_humidity[0].data[ATTR_ENTITY_ID] == entity_id
assert call_set_humidity[0].data[ATTR_HUMIDITY] == 39.0
assert acc.char_target_humidity.value == 39.0
assert len(events) == 1
assert (
events[-1].data[ATTR_VALUE] == "RelativeHumidityDehumidifierThreshold to 39.0%"
) | [
"async",
"def",
"test_dehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"events",
")",
":",
"entity_id",
"=",
"\"humidifier.test\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
",",
"{",
"ATTR_DEVICE_CLASS",
":",
"DEVICE_CLASS_DEHUMIDIFIER",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"HumidifierDehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"\"HumidifierDehumidifier\"",
",",
"entity_id",
",",
"1",
",",
"None",
")",
"hk_driver",
".",
"add_accessory",
"(",
"acc",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"aid",
"==",
"1",
"assert",
"acc",
".",
"category",
"==",
"CATEGORY_HUMIDIFIER",
"assert",
"acc",
".",
"char_current_humidifier_dehumidifier",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"2",
"assert",
"acc",
".",
"char_current_humidity",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidity",
".",
"value",
"==",
"45.0",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidity",
".",
"properties",
"[",
"PROP_MAX_VALUE",
"]",
"==",
"DEFAULT_MAX_HUMIDITY",
"assert",
"acc",
".",
"char_target_humidity",
".",
"properties",
"[",
"PROP_MIN_VALUE",
"]",
"==",
"DEFAULT_MIN_HUMIDITY",
"assert",
"acc",
".",
"char_target_humidity",
".",
"properties",
"[",
"PROP_MIN_STEP",
"]",
"==",
"1.0",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"properties",
"[",
"PROP_VALID_VALUES",
"]",
"==",
"{",
"\"Dehumidifier\"",
":",
"2",
"}",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_ON",
",",
"{",
"ATTR_HUMIDITY",
":",
"30",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_target_humidity",
".",
"value",
"==",
"30.0",
"assert",
"acc",
".",
"char_current_humidifier_dehumidifier",
".",
"value",
"==",
"3",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"2",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
",",
"{",
"ATTR_HUMIDITY",
":",
"42",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_target_humidity",
".",
"value",
"==",
"42.0",
"assert",
"acc",
".",
"char_current_humidifier_dehumidifier",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"2",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"0",
"# Set from HomeKit",
"call_set_humidity",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"SERVICE_SET_HUMIDITY",
")",
"char_target_humidity_iid",
"=",
"acc",
".",
"char_target_humidity",
".",
"to_HAP",
"(",
")",
"[",
"HAP_REPR_IID",
"]",
"hk_driver",
".",
"set_characteristics",
"(",
"{",
"HAP_REPR_CHARS",
":",
"[",
"{",
"HAP_REPR_AID",
":",
"acc",
".",
"aid",
",",
"HAP_REPR_IID",
":",
"char_target_humidity_iid",
",",
"HAP_REPR_VALUE",
":",
"39.0",
",",
"}",
",",
"]",
"}",
",",
"\"mock_addr\"",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"call_set_humidity",
")",
"==",
"1",
"assert",
"call_set_humidity",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"call_set_humidity",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_HUMIDITY",
"]",
"==",
"39.0",
"assert",
"acc",
".",
"char_target_humidity",
".",
"value",
"==",
"39.0",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"(",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"==",
"\"RelativeHumidityDehumidifierThreshold to 39.0%\"",
")"
] | [
124,
0
] | [
204,
5
] | python | en | ['en', 'en', 'en'] | True |
test_hygrostat_power_state | (hass, hk_driver, events) | Test if accessory and HA are updated accordingly. | Test if accessory and HA are updated accordingly. | async def test_hygrostat_power_state(hass, hk_driver, events):
"""Test if accessory and HA are updated accordingly."""
entity_id = "humidifier.test"
hass.states.async_set(
entity_id,
STATE_ON,
{ATTR_HUMIDITY: 43},
)
await hass.async_block_till_done()
acc = HumidifierDehumidifier(
hass, hk_driver, "HumidifierDehumidifier", entity_id, 1, None
)
hk_driver.add_accessory(acc)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.char_current_humidifier_dehumidifier.value == 2
assert acc.char_target_humidifier_dehumidifier.value == 1
assert acc.char_active.value == 1
hass.states.async_set(
entity_id,
STATE_OFF,
{ATTR_HUMIDITY: 43},
)
await hass.async_block_till_done()
assert acc.char_current_humidifier_dehumidifier.value == 0
assert acc.char_target_humidifier_dehumidifier.value == 1
assert acc.char_active.value == 0
# Set from HomeKit
call_turn_on = async_mock_service(hass, DOMAIN, SERVICE_TURN_ON)
char_active_iid = acc.char_active.to_HAP()[HAP_REPR_IID]
hk_driver.set_characteristics(
{
HAP_REPR_CHARS: [
{
HAP_REPR_AID: acc.aid,
HAP_REPR_IID: char_active_iid,
HAP_REPR_VALUE: 1,
},
]
},
"mock_addr",
)
await hass.async_block_till_done()
assert len(call_turn_on) == 1
assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_active.value == 1
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] == "Active to 1"
call_turn_off = async_mock_service(hass, DOMAIN, SERVICE_TURN_OFF)
hk_driver.set_characteristics(
{
HAP_REPR_CHARS: [
{
HAP_REPR_AID: acc.aid,
HAP_REPR_IID: char_active_iid,
HAP_REPR_VALUE: 0,
},
]
},
"mock_addr",
)
await hass.async_block_till_done()
assert len(call_turn_off) == 1
assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_active.value == 0
assert len(events) == 2
assert events[-1].data[ATTR_VALUE] == "Active to 0" | [
"async",
"def",
"test_hygrostat_power_state",
"(",
"hass",
",",
"hk_driver",
",",
"events",
")",
":",
"entity_id",
"=",
"\"humidifier.test\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_ON",
",",
"{",
"ATTR_HUMIDITY",
":",
"43",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"HumidifierDehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"\"HumidifierDehumidifier\"",
",",
"entity_id",
",",
"1",
",",
"None",
")",
"hk_driver",
".",
"add_accessory",
"(",
"acc",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_humidifier_dehumidifier",
".",
"value",
"==",
"2",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"1",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
",",
"{",
"ATTR_HUMIDITY",
":",
"43",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_humidifier_dehumidifier",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"1",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"0",
"# Set from HomeKit",
"call_turn_on",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"SERVICE_TURN_ON",
")",
"char_active_iid",
"=",
"acc",
".",
"char_active",
".",
"to_HAP",
"(",
")",
"[",
"HAP_REPR_IID",
"]",
"hk_driver",
".",
"set_characteristics",
"(",
"{",
"HAP_REPR_CHARS",
":",
"[",
"{",
"HAP_REPR_AID",
":",
"acc",
".",
"aid",
",",
"HAP_REPR_IID",
":",
"char_active_iid",
",",
"HAP_REPR_VALUE",
":",
"1",
",",
"}",
",",
"]",
"}",
",",
"\"mock_addr\"",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"call_turn_on",
")",
"==",
"1",
"assert",
"call_turn_on",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"1",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"==",
"\"Active to 1\"",
"call_turn_off",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"SERVICE_TURN_OFF",
")",
"hk_driver",
".",
"set_characteristics",
"(",
"{",
"HAP_REPR_CHARS",
":",
"[",
"{",
"HAP_REPR_AID",
":",
"acc",
".",
"aid",
",",
"HAP_REPR_IID",
":",
"char_active_iid",
",",
"HAP_REPR_VALUE",
":",
"0",
",",
"}",
",",
"]",
"}",
",",
"\"mock_addr\"",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"call_turn_off",
")",
"==",
"1",
"assert",
"call_turn_off",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_active",
".",
"value",
"==",
"0",
"assert",
"len",
"(",
"events",
")",
"==",
"2",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"==",
"\"Active to 0\""
] | [
207,
0
] | [
284,
55
] | python | en | ['en', 'en', 'en'] | True |
test_hygrostat_get_humidity_range | (hass, hk_driver) | Test if humidity range is evaluated correctly. | Test if humidity range is evaluated correctly. | async def test_hygrostat_get_humidity_range(hass, hk_driver):
"""Test if humidity range is evaluated correctly."""
entity_id = "humidifier.test"
hass.states.async_set(
entity_id, STATE_OFF, {ATTR_MIN_HUMIDITY: 40, ATTR_MAX_HUMIDITY: 45}
)
await hass.async_block_till_done()
acc = HumidifierDehumidifier(
hass, hk_driver, "HumidifierDehumidifier", entity_id, 1, None
)
hk_driver.add_accessory(acc)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.char_target_humidity.properties[PROP_MAX_VALUE] == 45
assert acc.char_target_humidity.properties[PROP_MIN_VALUE] == 40 | [
"async",
"def",
"test_hygrostat_get_humidity_range",
"(",
"hass",
",",
"hk_driver",
")",
":",
"entity_id",
"=",
"\"humidifier.test\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
",",
"{",
"ATTR_MIN_HUMIDITY",
":",
"40",
",",
"ATTR_MAX_HUMIDITY",
":",
"45",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"HumidifierDehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"\"HumidifierDehumidifier\"",
",",
"entity_id",
",",
"1",
",",
"None",
")",
"hk_driver",
".",
"add_accessory",
"(",
"acc",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_target_humidity",
".",
"properties",
"[",
"PROP_MAX_VALUE",
"]",
"==",
"45",
"assert",
"acc",
".",
"char_target_humidity",
".",
"properties",
"[",
"PROP_MIN_VALUE",
"]",
"==",
"40"
] | [
287,
0
] | [
304,
68
] | python | en | ['en', 'zu', 'en'] | True |
test_humidifier_with_linked_humidity_sensor | (hass, hk_driver) | Test a humidifier with a linked humidity sensor can update. | Test a humidifier with a linked humidity sensor can update. | async def test_humidifier_with_linked_humidity_sensor(hass, hk_driver):
"""Test a humidifier with a linked humidity sensor can update."""
humidity_sensor_entity_id = "sensor.bedroom_humidity"
hass.states.async_set(
humidity_sensor_entity_id,
"42.0",
{
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
},
)
await hass.async_block_till_done()
entity_id = "humidifier.test"
hass.states.async_set(entity_id, STATE_OFF)
await hass.async_block_till_done()
acc = HumidifierDehumidifier(
hass,
hk_driver,
"HumidifierDehumidifier",
entity_id,
1,
{CONF_LINKED_HUMIDITY_SENSOR: humidity_sensor_entity_id},
)
hk_driver.add_accessory(acc)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.char_current_humidity.value == 42.0
hass.states.async_set(
humidity_sensor_entity_id,
"43.0",
{
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
},
)
await hass.async_block_till_done()
assert acc.char_current_humidity.value == 43.0
hass.states.async_set(
humidity_sensor_entity_id,
STATE_UNAVAILABLE,
{
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
},
)
await hass.async_block_till_done()
assert acc.char_current_humidity.value == 43.0
hass.states.async_remove(humidity_sensor_entity_id)
await hass.async_block_till_done()
assert acc.char_current_humidity.value == 43.0 | [
"async",
"def",
"test_humidifier_with_linked_humidity_sensor",
"(",
"hass",
",",
"hk_driver",
")",
":",
"humidity_sensor_entity_id",
"=",
"\"sensor.bedroom_humidity\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"humidity_sensor_entity_id",
",",
"\"42.0\"",
",",
"{",
"ATTR_DEVICE_CLASS",
":",
"DEVICE_CLASS_HUMIDITY",
",",
"ATTR_UNIT_OF_MEASUREMENT",
":",
"PERCENTAGE",
",",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_id",
"=",
"\"humidifier.test\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"HumidifierDehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"\"HumidifierDehumidifier\"",
",",
"entity_id",
",",
"1",
",",
"{",
"CONF_LINKED_HUMIDITY_SENSOR",
":",
"humidity_sensor_entity_id",
"}",
",",
")",
"hk_driver",
".",
"add_accessory",
"(",
"acc",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_humidity",
".",
"value",
"==",
"42.0",
"hass",
".",
"states",
".",
"async_set",
"(",
"humidity_sensor_entity_id",
",",
"\"43.0\"",
",",
"{",
"ATTR_DEVICE_CLASS",
":",
"DEVICE_CLASS_HUMIDITY",
",",
"ATTR_UNIT_OF_MEASUREMENT",
":",
"PERCENTAGE",
",",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_humidity",
".",
"value",
"==",
"43.0",
"hass",
".",
"states",
".",
"async_set",
"(",
"humidity_sensor_entity_id",
",",
"STATE_UNAVAILABLE",
",",
"{",
"ATTR_DEVICE_CLASS",
":",
"DEVICE_CLASS_HUMIDITY",
",",
"ATTR_UNIT_OF_MEASUREMENT",
":",
"PERCENTAGE",
",",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_humidity",
".",
"value",
"==",
"43.0",
"hass",
".",
"states",
".",
"async_remove",
"(",
"humidity_sensor_entity_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_humidity",
".",
"value",
"==",
"43.0"
] | [
307,
0
] | [
366,
50
] | python | en | ['en', 'en', 'en'] | True |
test_humidifier_with_a_missing_linked_humidity_sensor | (hass, hk_driver) | Test a humidifier with a configured linked motion sensor that is missing. | Test a humidifier with a configured linked motion sensor that is missing. | async def test_humidifier_with_a_missing_linked_humidity_sensor(hass, hk_driver):
"""Test a humidifier with a configured linked motion sensor that is missing."""
humidity_sensor_entity_id = "sensor.bedroom_humidity"
entity_id = "humidifier.test"
hass.states.async_set(entity_id, STATE_OFF)
await hass.async_block_till_done()
acc = HumidifierDehumidifier(
hass,
hk_driver,
"HumidifierDehumidifier",
entity_id,
1,
{CONF_LINKED_HUMIDITY_SENSOR: humidity_sensor_entity_id},
)
hk_driver.add_accessory(acc)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.char_current_humidity.value == 0 | [
"async",
"def",
"test_humidifier_with_a_missing_linked_humidity_sensor",
"(",
"hass",
",",
"hk_driver",
")",
":",
"humidity_sensor_entity_id",
"=",
"\"sensor.bedroom_humidity\"",
"entity_id",
"=",
"\"humidifier.test\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"HumidifierDehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"\"HumidifierDehumidifier\"",
",",
"entity_id",
",",
"1",
",",
"{",
"CONF_LINKED_HUMIDITY_SENSOR",
":",
"humidity_sensor_entity_id",
"}",
",",
")",
"hk_driver",
".",
"add_accessory",
"(",
"acc",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_humidity",
".",
"value",
"==",
"0"
] | [
369,
0
] | [
389,
47
] | python | en | ['en', 'en', 'en'] | True |
test_humidifier_as_dehumidifier | (hass, hk_driver, events, caplog) | Test an invalid char_target_humidifier_dehumidifier from HomeKit. | Test an invalid char_target_humidifier_dehumidifier from HomeKit. | async def test_humidifier_as_dehumidifier(hass, hk_driver, events, caplog):
"""Test an invalid char_target_humidifier_dehumidifier from HomeKit."""
entity_id = "humidifier.test"
hass.states.async_set(entity_id, STATE_OFF)
await hass.async_block_till_done()
acc = HumidifierDehumidifier(
hass, hk_driver, "HumidifierDehumidifier", entity_id, 1, None
)
hk_driver.add_accessory(acc)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.char_target_humidifier_dehumidifier.value == 1
# Set from HomeKit
char_target_humidifier_dehumidifier_iid = (
acc.char_target_humidifier_dehumidifier.to_HAP()[HAP_REPR_IID]
)
hk_driver.set_characteristics(
{
HAP_REPR_CHARS: [
{
HAP_REPR_AID: acc.aid,
HAP_REPR_IID: char_target_humidifier_dehumidifier_iid,
HAP_REPR_VALUE: 0,
},
]
},
"mock_addr",
)
await hass.async_block_till_done()
assert "TargetHumidifierDehumidifierState is not supported" in caplog.text
assert len(events) == 0 | [
"async",
"def",
"test_humidifier_as_dehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"events",
",",
"caplog",
")",
":",
"entity_id",
"=",
"\"humidifier.test\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OFF",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"HumidifierDehumidifier",
"(",
"hass",
",",
"hk_driver",
",",
"\"HumidifierDehumidifier\"",
",",
"entity_id",
",",
"1",
",",
"None",
")",
"hk_driver",
".",
"add_accessory",
"(",
"acc",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"value",
"==",
"1",
"# Set from HomeKit",
"char_target_humidifier_dehumidifier_iid",
"=",
"(",
"acc",
".",
"char_target_humidifier_dehumidifier",
".",
"to_HAP",
"(",
")",
"[",
"HAP_REPR_IID",
"]",
")",
"hk_driver",
".",
"set_characteristics",
"(",
"{",
"HAP_REPR_CHARS",
":",
"[",
"{",
"HAP_REPR_AID",
":",
"acc",
".",
"aid",
",",
"HAP_REPR_IID",
":",
"char_target_humidifier_dehumidifier_iid",
",",
"HAP_REPR_VALUE",
":",
"0",
",",
"}",
",",
"]",
"}",
",",
"\"mock_addr\"",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"\"TargetHumidifierDehumidifierState is not supported\"",
"in",
"caplog",
".",
"text",
"assert",
"len",
"(",
"events",
")",
"==",
"0"
] | [
392,
0
] | [
428,
27
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
) | Set up the Genius Hub water_heater entities. | Set up the Genius Hub water_heater entities. | async def async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
) -> None:
"""Set up the Genius Hub water_heater entities."""
if discovery_info is None:
return
broker = hass.data[DOMAIN]["broker"]
async_add_entities(
[
GeniusWaterHeater(broker, z)
for z in broker.client.zone_objs
if z.data["type"] in GH_HEATERS
]
) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config",
":",
"ConfigType",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
"->",
"None",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"broker",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"\"broker\"",
"]",
"async_add_entities",
"(",
"[",
"GeniusWaterHeater",
"(",
"broker",
",",
"z",
")",
"for",
"z",
"in",
"broker",
".",
"client",
".",
"zone_objs",
"if",
"z",
".",
"data",
"[",
"\"type\"",
"]",
"in",
"GH_HEATERS",
"]",
")"
] | [
33,
0
] | [
48,
5
] | python | en | ['en', 'af', 'en'] | True |
GeniusWaterHeater.__init__ | (self, broker, zone) | Initialize the water_heater device. | Initialize the water_heater device. | def __init__(self, broker, zone) -> None:
"""Initialize the water_heater device."""
super().__init__(broker, zone)
self._max_temp = 80.0
self._min_temp = 30.0
self._supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE | [
"def",
"__init__",
"(",
"self",
",",
"broker",
",",
"zone",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"broker",
",",
"zone",
")",
"self",
".",
"_max_temp",
"=",
"80.0",
"self",
".",
"_min_temp",
"=",
"30.0",
"self",
".",
"_supported_features",
"=",
"SUPPORT_TARGET_TEMPERATURE",
"|",
"SUPPORT_OPERATION_MODE"
] | [
54,
4
] | [
60,
86
] | python | en | ['en', 'en', 'en'] | True |
GeniusWaterHeater.operation_list | (self) | Return the list of available operation modes. | Return the list of available operation modes. | def operation_list(self) -> List[str]:
"""Return the list of available operation modes."""
return list(HA_OPMODE_TO_GH) | [
"def",
"operation_list",
"(",
"self",
")",
"->",
"List",
"[",
"str",
"]",
":",
"return",
"list",
"(",
"HA_OPMODE_TO_GH",
")"
] | [
63,
4
] | [
65,
36
] | python | en | ['en', 'en', 'en'] | True |
GeniusWaterHeater.current_operation | (self) | Return the current operation mode. | Return the current operation mode. | def current_operation(self) -> str:
"""Return the current operation mode."""
return GH_STATE_TO_HA[self._zone.data["mode"]] | [
"def",
"current_operation",
"(",
"self",
")",
"->",
"str",
":",
"return",
"GH_STATE_TO_HA",
"[",
"self",
".",
"_zone",
".",
"data",
"[",
"\"mode\"",
"]",
"]"
] | [
68,
4
] | [
70,
54
] | python | en | ['en', 'en', 'en'] | True |
GeniusWaterHeater.async_set_operation_mode | (self, operation_mode) | Set a new operation mode for this boiler. | Set a new operation mode for this boiler. | async def async_set_operation_mode(self, operation_mode) -> None:
"""Set a new operation mode for this boiler."""
await self._zone.set_mode(HA_OPMODE_TO_GH[operation_mode]) | [
"async",
"def",
"async_set_operation_mode",
"(",
"self",
",",
"operation_mode",
")",
"->",
"None",
":",
"await",
"self",
".",
"_zone",
".",
"set_mode",
"(",
"HA_OPMODE_TO_GH",
"[",
"operation_mode",
"]",
")"
] | [
72,
4
] | [
74,
66
] | python | en | ['en', 'en', 'en'] | True |
conv2d | (x_input, w_matrix) | conv2d returns a 2d convolution layer with full stride. | conv2d returns a 2d convolution layer with full stride. | def conv2d(x_input, w_matrix):
"""conv2d returns a 2d convolution layer with full stride."""
return tf.nn.conv2d(x_input, w_matrix, strides=[1, 1, 1, 1], padding='SAME') | [
"def",
"conv2d",
"(",
"x_input",
",",
"w_matrix",
")",
":",
"return",
"tf",
".",
"nn",
".",
"conv2d",
"(",
"x_input",
",",
"w_matrix",
",",
"strides",
"=",
"[",
"1",
",",
"1",
",",
"1",
",",
"1",
"]",
",",
"padding",
"=",
"'SAME'",
")"
] | [
124,
0
] | [
126,
80
] | python | en | ['en', 'en', 'en'] | True |
max_pool | (x_input, pool_size) | max_pool downsamples a feature map by 2X. | max_pool downsamples a feature map by 2X. | def max_pool(x_input, pool_size):
"""max_pool downsamples a feature map by 2X."""
return tf.nn.max_pool(x_input, ksize=[1, pool_size, pool_size, 1],
strides=[1, pool_size, pool_size, 1], padding='SAME') | [
"def",
"max_pool",
"(",
"x_input",
",",
"pool_size",
")",
":",
"return",
"tf",
".",
"nn",
".",
"max_pool",
"(",
"x_input",
",",
"ksize",
"=",
"[",
"1",
",",
"pool_size",
",",
"pool_size",
",",
"1",
"]",
",",
"strides",
"=",
"[",
"1",
",",
"pool_size",
",",
"pool_size",
",",
"1",
"]",
",",
"padding",
"=",
"'SAME'",
")"
] | [
129,
0
] | [
132,
79
] | python | en | ['en', 'en', 'en'] | True |
weight_variable | (shape) | weight_variable generates a weight variable of a given shape. | weight_variable generates a weight variable of a given shape. | def weight_variable(shape):
"""weight_variable generates a weight variable of a given shape."""
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial) | [
"def",
"weight_variable",
"(",
"shape",
")",
":",
"initial",
"=",
"tf",
".",
"truncated_normal",
"(",
"shape",
",",
"stddev",
"=",
"0.1",
")",
"return",
"tf",
".",
"Variable",
"(",
"initial",
")"
] | [
135,
0
] | [
138,
31
] | python | en | ['en', 'en', 'en'] | True |
bias_variable | (shape) | bias_variable generates a bias variable of a given shape. | bias_variable generates a bias variable of a given shape. | def bias_variable(shape):
"""bias_variable generates a bias variable of a given shape."""
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial) | [
"def",
"bias_variable",
"(",
"shape",
")",
":",
"initial",
"=",
"tf",
".",
"constant",
"(",
"0.1",
",",
"shape",
"=",
"shape",
")",
"return",
"tf",
".",
"Variable",
"(",
"initial",
")"
] | [
141,
0
] | [
144,
31
] | python | en | ['en', 'en', 'en'] | True |
download_mnist_retry | (data_dir, max_num_retries=20) | Try to download mnist dataset and avoid errors | Try to download mnist dataset and avoid errors | def download_mnist_retry(data_dir, max_num_retries=20):
"""Try to download mnist dataset and avoid errors"""
for _ in range(max_num_retries):
try:
return input_data.read_data_sets(data_dir, one_hot=True)
except tf.errors.AlreadyExistsError:
time.sleep(1)
raise Exception("Failed to download MNIST.") | [
"def",
"download_mnist_retry",
"(",
"data_dir",
",",
"max_num_retries",
"=",
"20",
")",
":",
"for",
"_",
"in",
"range",
"(",
"max_num_retries",
")",
":",
"try",
":",
"return",
"input_data",
".",
"read_data_sets",
"(",
"data_dir",
",",
"one_hot",
"=",
"True",
")",
"except",
"tf",
".",
"errors",
".",
"AlreadyExistsError",
":",
"time",
".",
"sleep",
"(",
"1",
")",
"raise",
"Exception",
"(",
"\"Failed to download MNIST.\"",
")"
] | [
146,
0
] | [
153,
48
] | python | en | ['en', 'en', 'en'] | True |
main | (params) |
Main function, build mnist network, run and send result to NNI.
|
Main function, build mnist network, run and send result to NNI.
| def main(params):
'''
Main function, build mnist network, run and send result to NNI.
'''
# Import data
mnist = download_mnist_retry(params['data_dir'])
print('Mnist download data done.')
logger.debug('Mnist download data done.')
# Create the model
# Build the graph for the deep net
mnist_network = MnistNetwork(channel_1_num=params['channel_1_num'],
channel_2_num=params['channel_2_num'],
conv_size=params['conv_size'],
hidden_size=params['hidden_size'],
pool_size=params['pool_size'],
learning_rate=params['learning_rate'])
mnist_network.build_network()
logger.debug('Mnist build network done.')
# Write log
graph_location = tempfile.mkdtemp()
logger.debug('Saving graph to: %s', graph_location)
train_writer = tf.summary.FileWriter(graph_location)
train_writer.add_graph(tf.get_default_graph())
test_acc = 0.0
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(params['batch_num']):
batch = mnist.train.next_batch(params['batch_size'])
mnist_network.train_step.run(feed_dict={mnist_network.images: batch[0],
mnist_network.labels: batch[1],
mnist_network.keep_prob: 1 - params['dropout_rate']}
)
if i % 100 == 0:
test_acc = mnist_network.accuracy.eval(
feed_dict={mnist_network.images: mnist.test.images,
mnist_network.labels: mnist.test.labels,
mnist_network.keep_prob: 1.0})
nni.report_intermediate_result(test_acc)
logger.debug('test accuracy %g', test_acc)
logger.debug('Pipe send intermediate result done.')
test_acc = mnist_network.accuracy.eval(
feed_dict={mnist_network.images: mnist.test.images,
mnist_network.labels: mnist.test.labels,
mnist_network.keep_prob: 1.0})
nni.report_final_result(test_acc)
logger.debug('Final result is %g', test_acc)
logger.debug('Send final result done.') | [
"def",
"main",
"(",
"params",
")",
":",
"# Import data",
"mnist",
"=",
"download_mnist_retry",
"(",
"params",
"[",
"'data_dir'",
"]",
")",
"print",
"(",
"'Mnist download data done.'",
")",
"logger",
".",
"debug",
"(",
"'Mnist download data done.'",
")",
"# Create the model",
"# Build the graph for the deep net",
"mnist_network",
"=",
"MnistNetwork",
"(",
"channel_1_num",
"=",
"params",
"[",
"'channel_1_num'",
"]",
",",
"channel_2_num",
"=",
"params",
"[",
"'channel_2_num'",
"]",
",",
"conv_size",
"=",
"params",
"[",
"'conv_size'",
"]",
",",
"hidden_size",
"=",
"params",
"[",
"'hidden_size'",
"]",
",",
"pool_size",
"=",
"params",
"[",
"'pool_size'",
"]",
",",
"learning_rate",
"=",
"params",
"[",
"'learning_rate'",
"]",
")",
"mnist_network",
".",
"build_network",
"(",
")",
"logger",
".",
"debug",
"(",
"'Mnist build network done.'",
")",
"# Write log",
"graph_location",
"=",
"tempfile",
".",
"mkdtemp",
"(",
")",
"logger",
".",
"debug",
"(",
"'Saving graph to: %s'",
",",
"graph_location",
")",
"train_writer",
"=",
"tf",
".",
"summary",
".",
"FileWriter",
"(",
"graph_location",
")",
"train_writer",
".",
"add_graph",
"(",
"tf",
".",
"get_default_graph",
"(",
")",
")",
"test_acc",
"=",
"0.0",
"with",
"tf",
".",
"Session",
"(",
")",
"as",
"sess",
":",
"sess",
".",
"run",
"(",
"tf",
".",
"global_variables_initializer",
"(",
")",
")",
"for",
"i",
"in",
"range",
"(",
"params",
"[",
"'batch_num'",
"]",
")",
":",
"batch",
"=",
"mnist",
".",
"train",
".",
"next_batch",
"(",
"params",
"[",
"'batch_size'",
"]",
")",
"mnist_network",
".",
"train_step",
".",
"run",
"(",
"feed_dict",
"=",
"{",
"mnist_network",
".",
"images",
":",
"batch",
"[",
"0",
"]",
",",
"mnist_network",
".",
"labels",
":",
"batch",
"[",
"1",
"]",
",",
"mnist_network",
".",
"keep_prob",
":",
"1",
"-",
"params",
"[",
"'dropout_rate'",
"]",
"}",
")",
"if",
"i",
"%",
"100",
"==",
"0",
":",
"test_acc",
"=",
"mnist_network",
".",
"accuracy",
".",
"eval",
"(",
"feed_dict",
"=",
"{",
"mnist_network",
".",
"images",
":",
"mnist",
".",
"test",
".",
"images",
",",
"mnist_network",
".",
"labels",
":",
"mnist",
".",
"test",
".",
"labels",
",",
"mnist_network",
".",
"keep_prob",
":",
"1.0",
"}",
")",
"nni",
".",
"report_intermediate_result",
"(",
"test_acc",
")",
"logger",
".",
"debug",
"(",
"'test accuracy %g'",
",",
"test_acc",
")",
"logger",
".",
"debug",
"(",
"'Pipe send intermediate result done.'",
")",
"test_acc",
"=",
"mnist_network",
".",
"accuracy",
".",
"eval",
"(",
"feed_dict",
"=",
"{",
"mnist_network",
".",
"images",
":",
"mnist",
".",
"test",
".",
"images",
",",
"mnist_network",
".",
"labels",
":",
"mnist",
".",
"test",
".",
"labels",
",",
"mnist_network",
".",
"keep_prob",
":",
"1.0",
"}",
")",
"nni",
".",
"report_final_result",
"(",
"test_acc",
")",
"logger",
".",
"debug",
"(",
"'Final result is %g'",
",",
"test_acc",
")",
"logger",
".",
"debug",
"(",
"'Send final result done.'",
")"
] | [
155,
0
] | [
208,
47
] | python | en | ['en', 'error', 'th'] | False |
get_params | () | Get parameters from command line | Get parameters from command line | def get_params():
''' Get parameters from command line '''
parser = argparse.ArgumentParser()
parser.add_argument("--data_dir", type=str, default='/tmp/tensorflow/mnist/input_data', help="data directory")
parser.add_argument("--dropout_rate", type=float, default=0.5, help="dropout rate")
parser.add_argument("--channel_1_num", type=int, default=32)
parser.add_argument("--channel_2_num", type=int, default=64)
parser.add_argument("--conv_size", type=int, default=5)
parser.add_argument("--pool_size", type=int, default=2)
parser.add_argument("--hidden_size", type=int, default=1024)
parser.add_argument("--learning_rate", type=float, default=1e-4)
parser.add_argument("--batch_num", type=int, default=2700)
parser.add_argument("--batch_size", type=int, default=32)
args, _ = parser.parse_known_args()
return args | [
"def",
"get_params",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"\"--data_dir\"",
",",
"type",
"=",
"str",
",",
"default",
"=",
"'/tmp/tensorflow/mnist/input_data'",
",",
"help",
"=",
"\"data directory\"",
")",
"parser",
".",
"add_argument",
"(",
"\"--dropout_rate\"",
",",
"type",
"=",
"float",
",",
"default",
"=",
"0.5",
",",
"help",
"=",
"\"dropout rate\"",
")",
"parser",
".",
"add_argument",
"(",
"\"--channel_1_num\"",
",",
"type",
"=",
"int",
",",
"default",
"=",
"32",
")",
"parser",
".",
"add_argument",
"(",
"\"--channel_2_num\"",
",",
"type",
"=",
"int",
",",
"default",
"=",
"64",
")",
"parser",
".",
"add_argument",
"(",
"\"--conv_size\"",
",",
"type",
"=",
"int",
",",
"default",
"=",
"5",
")",
"parser",
".",
"add_argument",
"(",
"\"--pool_size\"",
",",
"type",
"=",
"int",
",",
"default",
"=",
"2",
")",
"parser",
".",
"add_argument",
"(",
"\"--hidden_size\"",
",",
"type",
"=",
"int",
",",
"default",
"=",
"1024",
")",
"parser",
".",
"add_argument",
"(",
"\"--learning_rate\"",
",",
"type",
"=",
"float",
",",
"default",
"=",
"1e-4",
")",
"parser",
".",
"add_argument",
"(",
"\"--batch_num\"",
",",
"type",
"=",
"int",
",",
"default",
"=",
"2700",
")",
"parser",
".",
"add_argument",
"(",
"\"--batch_size\"",
",",
"type",
"=",
"int",
",",
"default",
"=",
"32",
")",
"args",
",",
"_",
"=",
"parser",
".",
"parse_known_args",
"(",
")",
"return",
"args"
] | [
210,
0
] | [
225,
15
] | python | en | ['en', 'en', 'en'] | True |
MnistNetwork.build_network | (self) |
Building network for mnist
|
Building network for mnist
| def build_network(self):
'''
Building network for mnist
'''
# Reshape to use within a convolutional neural net.
# Last dimension is for "features" - there is only one here, since images are
# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
with tf.name_scope('reshape'):
try:
input_dim = int(math.sqrt(self.x_dim))
except:
print(
'input dim cannot be sqrt and reshape. input dim: ' + str(self.x_dim))
logger.debug(
'input dim cannot be sqrt and reshape. input dim: %s', str(self.x_dim))
raise
x_image = tf.reshape(self.images, [-1, input_dim, input_dim, 1])
# First convolutional layer - maps one grayscale image to 32 feature maps.
with tf.name_scope('conv1'):
w_conv1 = weight_variable(
[self.conv_size, self.conv_size, 1, self.channel_1_num])
b_conv1 = bias_variable([self.channel_1_num])
h_conv1 = tf.nn.relu(conv2d(x_image, w_conv1) + b_conv1)
# Pooling layer - downsamples by 2X.
with tf.name_scope('pool1'):
h_pool1 = max_pool(h_conv1, self.pool_size)
# Second convolutional layer -- maps 32 feature maps to 64.
with tf.name_scope('conv2'):
w_conv2 = weight_variable([self.conv_size, self.conv_size,
self.channel_1_num, self.channel_2_num])
b_conv2 = bias_variable([self.channel_2_num])
h_conv2 = tf.nn.relu(conv2d(h_pool1, w_conv2) + b_conv2)
# Second pooling layer.
with tf.name_scope('pool2'):
h_pool2 = max_pool(h_conv2, self.pool_size)
# Fully connected layer 1 -- after 2 round of downsampling, our 28x28 image
# is down to 7x7x64 feature maps -- maps this to 1024 features.
last_dim = int(input_dim / (self.pool_size * self.pool_size))
with tf.name_scope('fc1'):
w_fc1 = weight_variable(
[last_dim * last_dim * self.channel_2_num, self.hidden_size])
b_fc1 = bias_variable([self.hidden_size])
h_pool2_flat = tf.reshape(
h_pool2, [-1, last_dim * last_dim * self.channel_2_num])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, w_fc1) + b_fc1)
# Dropout - controls the complexity of the model, prevents co-adaptation of features.
with tf.name_scope('dropout'):
h_fc1_drop = tf.nn.dropout(h_fc1, self.keep_prob)
# Map the 1024 features to 10 classes, one for each digit
with tf.name_scope('fc2'):
w_fc2 = weight_variable([self.hidden_size, self.y_dim])
b_fc2 = bias_variable([self.y_dim])
y_conv = tf.matmul(h_fc1_drop, w_fc2) + b_fc2
with tf.name_scope('loss'):
cross_entropy = tf.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits(labels=self.labels, logits=y_conv))
with tf.name_scope('adam_optimizer'):
self.train_step = tf.train.AdamOptimizer(
self.learning_rate).minimize(cross_entropy)
with tf.name_scope('accuracy'):
correct_prediction = tf.equal(
tf.argmax(y_conv, 1), tf.argmax(self.labels, 1))
self.accuracy = tf.reduce_mean(
tf.cast(correct_prediction, tf.float32)) | [
"def",
"build_network",
"(",
"self",
")",
":",
"# Reshape to use within a convolutional neural net.",
"# Last dimension is for \"features\" - there is only one here, since images are",
"# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.",
"with",
"tf",
".",
"name_scope",
"(",
"'reshape'",
")",
":",
"try",
":",
"input_dim",
"=",
"int",
"(",
"math",
".",
"sqrt",
"(",
"self",
".",
"x_dim",
")",
")",
"except",
":",
"print",
"(",
"'input dim cannot be sqrt and reshape. input dim: '",
"+",
"str",
"(",
"self",
".",
"x_dim",
")",
")",
"logger",
".",
"debug",
"(",
"'input dim cannot be sqrt and reshape. input dim: %s'",
",",
"str",
"(",
"self",
".",
"x_dim",
")",
")",
"raise",
"x_image",
"=",
"tf",
".",
"reshape",
"(",
"self",
".",
"images",
",",
"[",
"-",
"1",
",",
"input_dim",
",",
"input_dim",
",",
"1",
"]",
")",
"# First convolutional layer - maps one grayscale image to 32 feature maps.",
"with",
"tf",
".",
"name_scope",
"(",
"'conv1'",
")",
":",
"w_conv1",
"=",
"weight_variable",
"(",
"[",
"self",
".",
"conv_size",
",",
"self",
".",
"conv_size",
",",
"1",
",",
"self",
".",
"channel_1_num",
"]",
")",
"b_conv1",
"=",
"bias_variable",
"(",
"[",
"self",
".",
"channel_1_num",
"]",
")",
"h_conv1",
"=",
"tf",
".",
"nn",
".",
"relu",
"(",
"conv2d",
"(",
"x_image",
",",
"w_conv1",
")",
"+",
"b_conv1",
")",
"# Pooling layer - downsamples by 2X.",
"with",
"tf",
".",
"name_scope",
"(",
"'pool1'",
")",
":",
"h_pool1",
"=",
"max_pool",
"(",
"h_conv1",
",",
"self",
".",
"pool_size",
")",
"# Second convolutional layer -- maps 32 feature maps to 64.",
"with",
"tf",
".",
"name_scope",
"(",
"'conv2'",
")",
":",
"w_conv2",
"=",
"weight_variable",
"(",
"[",
"self",
".",
"conv_size",
",",
"self",
".",
"conv_size",
",",
"self",
".",
"channel_1_num",
",",
"self",
".",
"channel_2_num",
"]",
")",
"b_conv2",
"=",
"bias_variable",
"(",
"[",
"self",
".",
"channel_2_num",
"]",
")",
"h_conv2",
"=",
"tf",
".",
"nn",
".",
"relu",
"(",
"conv2d",
"(",
"h_pool1",
",",
"w_conv2",
")",
"+",
"b_conv2",
")",
"# Second pooling layer.",
"with",
"tf",
".",
"name_scope",
"(",
"'pool2'",
")",
":",
"h_pool2",
"=",
"max_pool",
"(",
"h_conv2",
",",
"self",
".",
"pool_size",
")",
"# Fully connected layer 1 -- after 2 round of downsampling, our 28x28 image",
"# is down to 7x7x64 feature maps -- maps this to 1024 features.",
"last_dim",
"=",
"int",
"(",
"input_dim",
"/",
"(",
"self",
".",
"pool_size",
"*",
"self",
".",
"pool_size",
")",
")",
"with",
"tf",
".",
"name_scope",
"(",
"'fc1'",
")",
":",
"w_fc1",
"=",
"weight_variable",
"(",
"[",
"last_dim",
"*",
"last_dim",
"*",
"self",
".",
"channel_2_num",
",",
"self",
".",
"hidden_size",
"]",
")",
"b_fc1",
"=",
"bias_variable",
"(",
"[",
"self",
".",
"hidden_size",
"]",
")",
"h_pool2_flat",
"=",
"tf",
".",
"reshape",
"(",
"h_pool2",
",",
"[",
"-",
"1",
",",
"last_dim",
"*",
"last_dim",
"*",
"self",
".",
"channel_2_num",
"]",
")",
"h_fc1",
"=",
"tf",
".",
"nn",
".",
"relu",
"(",
"tf",
".",
"matmul",
"(",
"h_pool2_flat",
",",
"w_fc1",
")",
"+",
"b_fc1",
")",
"# Dropout - controls the complexity of the model, prevents co-adaptation of features.",
"with",
"tf",
".",
"name_scope",
"(",
"'dropout'",
")",
":",
"h_fc1_drop",
"=",
"tf",
".",
"nn",
".",
"dropout",
"(",
"h_fc1",
",",
"self",
".",
"keep_prob",
")",
"# Map the 1024 features to 10 classes, one for each digit",
"with",
"tf",
".",
"name_scope",
"(",
"'fc2'",
")",
":",
"w_fc2",
"=",
"weight_variable",
"(",
"[",
"self",
".",
"hidden_size",
",",
"self",
".",
"y_dim",
"]",
")",
"b_fc2",
"=",
"bias_variable",
"(",
"[",
"self",
".",
"y_dim",
"]",
")",
"y_conv",
"=",
"tf",
".",
"matmul",
"(",
"h_fc1_drop",
",",
"w_fc2",
")",
"+",
"b_fc2",
"with",
"tf",
".",
"name_scope",
"(",
"'loss'",
")",
":",
"cross_entropy",
"=",
"tf",
".",
"reduce_mean",
"(",
"tf",
".",
"nn",
".",
"softmax_cross_entropy_with_logits",
"(",
"labels",
"=",
"self",
".",
"labels",
",",
"logits",
"=",
"y_conv",
")",
")",
"with",
"tf",
".",
"name_scope",
"(",
"'adam_optimizer'",
")",
":",
"self",
".",
"train_step",
"=",
"tf",
".",
"train",
".",
"AdamOptimizer",
"(",
"self",
".",
"learning_rate",
")",
".",
"minimize",
"(",
"cross_entropy",
")",
"with",
"tf",
".",
"name_scope",
"(",
"'accuracy'",
")",
":",
"correct_prediction",
"=",
"tf",
".",
"equal",
"(",
"tf",
".",
"argmax",
"(",
"y_conv",
",",
"1",
")",
",",
"tf",
".",
"argmax",
"(",
"self",
".",
"labels",
",",
"1",
")",
")",
"self",
".",
"accuracy",
"=",
"tf",
".",
"reduce_mean",
"(",
"tf",
".",
"cast",
"(",
"correct_prediction",
",",
"tf",
".",
"float32",
")",
")"
] | [
47,
4
] | [
121,
56
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.