Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
sequence
start_point
sequence
end_point
sequence
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
generate
(template: str, info: Info)
Generate a template.
Generate a template.
def generate(template: str, info: Info) -> None: """Generate a template.""" print(f"Scaffolding {template} for the {info.domain} integration...") _ensure_tests_dir_exists(info) _generate(TEMPLATE_DIR / template / "integration", info.integration_dir, info) _generate(TEMPLATE_DIR / template / "tests", info.tests_dir, info) _custom_tasks(template, info) print()
[ "def", "generate", "(", "template", ":", "str", ",", "info", ":", "Info", ")", "->", "None", ":", "print", "(", "f\"Scaffolding {template} for the {info.domain} integration...\"", ")", "_ensure_tests_dir_exists", "(", "info", ")", "_generate", "(", "TEMPLATE_DIR", "/", "template", "/", "\"integration\"", ",", "info", ".", "integration_dir", ",", "info", ")", "_generate", "(", "TEMPLATE_DIR", "/", "template", "/", "\"tests\"", ",", "info", ".", "tests_dir", ",", "info", ")", "_custom_tasks", "(", "template", ",", "info", ")", "print", "(", ")" ]
[ 10, 0 ]
[ 17, 11 ]
python
en
['en', 'co', 'en']
True
_generate
(src_dir, target_dir, info: Info)
Generate an integration.
Generate an integration.
def _generate(src_dir, target_dir, info: Info) -> None: """Generate an integration.""" replaces = {"NEW_DOMAIN": info.domain, "NEW_NAME": info.name} if not target_dir.exists(): target_dir.mkdir() for source_file in src_dir.glob("**/*"): content = source_file.read_text() for to_search, to_replace in replaces.items(): content = content.replace(to_search, to_replace) target_file = target_dir / source_file.relative_to(src_dir) # If the target file exists, create our template as EXAMPLE_<filename>. # Exception: If we are creating a new integration, we can end up running integration base # and a config flows on top of one another. In that case, we want to override the files. if not info.is_new and target_file.exists(): new_name = f"EXAMPLE_{target_file.name}" print(f"File {target_file} already exists, creating {new_name} instead.") target_file = target_file.parent / new_name info.examples_added.add(target_file) elif src_dir.name == "integration": info.files_added.add(target_file) else: info.tests_added.add(target_file) print(f"Writing {target_file}") target_file.write_text(content)
[ "def", "_generate", "(", "src_dir", ",", "target_dir", ",", "info", ":", "Info", ")", "->", "None", ":", "replaces", "=", "{", "\"NEW_DOMAIN\"", ":", "info", ".", "domain", ",", "\"NEW_NAME\"", ":", "info", ".", "name", "}", "if", "not", "target_dir", ".", "exists", "(", ")", ":", "target_dir", ".", "mkdir", "(", ")", "for", "source_file", "in", "src_dir", ".", "glob", "(", "\"**/*\"", ")", ":", "content", "=", "source_file", ".", "read_text", "(", ")", "for", "to_search", ",", "to_replace", "in", "replaces", ".", "items", "(", ")", ":", "content", "=", "content", ".", "replace", "(", "to_search", ",", "to_replace", ")", "target_file", "=", "target_dir", "/", "source_file", ".", "relative_to", "(", "src_dir", ")", "# If the target file exists, create our template as EXAMPLE_<filename>.", "# Exception: If we are creating a new integration, we can end up running integration base", "# and a config flows on top of one another. In that case, we want to override the files.", "if", "not", "info", ".", "is_new", "and", "target_file", ".", "exists", "(", ")", ":", "new_name", "=", "f\"EXAMPLE_{target_file.name}\"", "print", "(", "f\"File {target_file} already exists, creating {new_name} instead.\"", ")", "target_file", "=", "target_file", ".", "parent", "/", "new_name", "info", ".", "examples_added", ".", "add", "(", "target_file", ")", "elif", "src_dir", ".", "name", "==", "\"integration\"", ":", "info", ".", "files_added", ".", "add", "(", "target_file", ")", "else", ":", "info", ".", "tests_added", ".", "add", "(", "target_file", ")", "print", "(", "f\"Writing {target_file}\"", ")", "target_file", ".", "write_text", "(", "content", ")" ]
[ 20, 0 ]
[ 49, 39 ]
python
en
['en', 'lb', 'it']
False
_ensure_tests_dir_exists
(info: Info)
Ensure a test dir exists.
Ensure a test dir exists.
def _ensure_tests_dir_exists(info: Info) -> None: """Ensure a test dir exists.""" if info.tests_dir.exists(): return info.tests_dir.mkdir() print(f"Writing {info.tests_dir / '__init__.py'}") (info.tests_dir / "__init__.py").write_text( f'"""Tests for the {info.name} integration."""\n' )
[ "def", "_ensure_tests_dir_exists", "(", "info", ":", "Info", ")", "->", "None", ":", "if", "info", ".", "tests_dir", ".", "exists", "(", ")", ":", "return", "info", ".", "tests_dir", ".", "mkdir", "(", ")", "print", "(", "f\"Writing {info.tests_dir / '__init__.py'}\"", ")", "(", "info", ".", "tests_dir", "/", "\"__init__.py\"", ")", ".", "write_text", "(", "f'\"\"\"Tests for the {info.name} integration.\"\"\"\\n'", ")" ]
[ 52, 0 ]
[ 61, 5 ]
python
ca
['ca', 'fr', 'en']
False
_append
(path: Path, text)
Append some text to a path.
Append some text to a path.
def _append(path: Path, text): """Append some text to a path.""" path.write_text(path.read_text() + text)
[ "def", "_append", "(", "path", ":", "Path", ",", "text", ")", ":", "path", ".", "write_text", "(", "path", ".", "read_text", "(", ")", "+", "text", ")" ]
[ 64, 0 ]
[ 66, 44 ]
python
en
['en', 'en', 'en']
True
_custom_tasks
(template, info)
Handle custom tasks for templates.
Handle custom tasks for templates.
def _custom_tasks(template, info) -> None: """Handle custom tasks for templates.""" if template == "integration": changes = {"codeowners": [info.codeowner]} if info.requirement: changes["requirements"] = [info.requirement] info.update_manifest(**changes) elif template == "device_trigger": info.update_strings( device_automation={ **info.strings().get("device_automation", {}), "trigger_type": { "turned_on": "{entity_name} turned on", "turned_off": "{entity_name} turned off", }, } ) elif template == "device_condition": info.update_strings( device_automation={ **info.strings().get("device_automation", {}), "condition_type": { "is_on": "{entity_name} is on", "is_off": "{entity_name} is off", }, } ) elif template == "device_action": info.update_strings( device_automation={ **info.strings().get("device_automation", {}), "action_type": { "turn_on": "Turn on {entity_name}", "turn_off": "Turn off {entity_name}", }, } ) elif template == "config_flow": info.update_manifest(config_flow=True) info.update_strings( title=info.name, config={ "step": { "user": { "data": { "host": "[%key:common::config_flow::data::host%]", "username": "[%key:common::config_flow::data::username%]", "password": "[%key:common::config_flow::data::password%]", }, } }, "error": { "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", "unknown": "[%key:common::config_flow::error::unknown%]", }, "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" }, }, ) elif template == "config_flow_discovery": info.update_manifest(config_flow=True) info.update_strings( title=info.name, config={ "step": { "confirm": { "description": "[%key:common::config_flow::description::confirm_setup%]", } }, "abort": { "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]", "no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]", }, }, ) elif template == "config_flow_oauth2": info.update_manifest(config_flow=True, dependencies=["http"]) info.update_strings( title=info.name, config={ "step": { "pick_implementation": { "title": "[%key:common::config_flow::title::oauth2_pick_implementation%]" } }, "abort": { "missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]", "authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]", "no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]", }, "create_entry": { "default": "[%key:common::config_flow::create_entry::authenticated%]" }, }, )
[ "def", "_custom_tasks", "(", "template", ",", "info", ")", "->", "None", ":", "if", "template", "==", "\"integration\"", ":", "changes", "=", "{", "\"codeowners\"", ":", "[", "info", ".", "codeowner", "]", "}", "if", "info", ".", "requirement", ":", "changes", "[", "\"requirements\"", "]", "=", "[", "info", ".", "requirement", "]", "info", ".", "update_manifest", "(", "*", "*", "changes", ")", "elif", "template", "==", "\"device_trigger\"", ":", "info", ".", "update_strings", "(", "device_automation", "=", "{", "*", "*", "info", ".", "strings", "(", ")", ".", "get", "(", "\"device_automation\"", ",", "{", "}", ")", ",", "\"trigger_type\"", ":", "{", "\"turned_on\"", ":", "\"{entity_name} turned on\"", ",", "\"turned_off\"", ":", "\"{entity_name} turned off\"", ",", "}", ",", "}", ")", "elif", "template", "==", "\"device_condition\"", ":", "info", ".", "update_strings", "(", "device_automation", "=", "{", "*", "*", "info", ".", "strings", "(", ")", ".", "get", "(", "\"device_automation\"", ",", "{", "}", ")", ",", "\"condition_type\"", ":", "{", "\"is_on\"", ":", "\"{entity_name} is on\"", ",", "\"is_off\"", ":", "\"{entity_name} is off\"", ",", "}", ",", "}", ")", "elif", "template", "==", "\"device_action\"", ":", "info", ".", "update_strings", "(", "device_automation", "=", "{", "*", "*", "info", ".", "strings", "(", ")", ".", "get", "(", "\"device_automation\"", ",", "{", "}", ")", ",", "\"action_type\"", ":", "{", "\"turn_on\"", ":", "\"Turn on {entity_name}\"", ",", "\"turn_off\"", ":", "\"Turn off {entity_name}\"", ",", "}", ",", "}", ")", "elif", "template", "==", "\"config_flow\"", ":", "info", ".", "update_manifest", "(", "config_flow", "=", "True", ")", "info", ".", "update_strings", "(", "title", "=", "info", ".", "name", ",", "config", "=", "{", "\"step\"", ":", "{", "\"user\"", ":", "{", "\"data\"", ":", "{", "\"host\"", ":", "\"[%key:common::config_flow::data::host%]\"", ",", "\"username\"", ":", "\"[%key:common::config_flow::data::username%]\"", ",", "\"password\"", ":", "\"[%key:common::config_flow::data::password%]\"", ",", "}", ",", "}", "}", ",", "\"error\"", ":", "{", "\"cannot_connect\"", ":", "\"[%key:common::config_flow::error::cannot_connect%]\"", ",", "\"invalid_auth\"", ":", "\"[%key:common::config_flow::error::invalid_auth%]\"", ",", "\"unknown\"", ":", "\"[%key:common::config_flow::error::unknown%]\"", ",", "}", ",", "\"abort\"", ":", "{", "\"already_configured\"", ":", "\"[%key:common::config_flow::abort::already_configured_device%]\"", "}", ",", "}", ",", ")", "elif", "template", "==", "\"config_flow_discovery\"", ":", "info", ".", "update_manifest", "(", "config_flow", "=", "True", ")", "info", ".", "update_strings", "(", "title", "=", "info", ".", "name", ",", "config", "=", "{", "\"step\"", ":", "{", "\"confirm\"", ":", "{", "\"description\"", ":", "\"[%key:common::config_flow::description::confirm_setup%]\"", ",", "}", "}", ",", "\"abort\"", ":", "{", "\"single_instance_allowed\"", ":", "\"[%key:common::config_flow::abort::single_instance_allowed%]\"", ",", "\"no_devices_found\"", ":", "\"[%key:common::config_flow::abort::no_devices_found%]\"", ",", "}", ",", "}", ",", ")", "elif", "template", "==", "\"config_flow_oauth2\"", ":", "info", ".", "update_manifest", "(", "config_flow", "=", "True", ",", "dependencies", "=", "[", "\"http\"", "]", ")", "info", ".", "update_strings", "(", "title", "=", "info", ".", "name", ",", "config", "=", "{", "\"step\"", ":", "{", "\"pick_implementation\"", ":", "{", "\"title\"", ":", "\"[%key:common::config_flow::title::oauth2_pick_implementation%]\"", "}", "}", ",", "\"abort\"", ":", "{", "\"missing_configuration\"", ":", "\"[%key:common::config_flow::abort::oauth2_missing_configuration%]\"", ",", "\"authorize_url_timeout\"", ":", "\"[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]\"", ",", "\"no_url_available\"", ":", "\"[%key:common::config_flow::abort::oauth2_no_url_available%]\"", ",", "}", ",", "\"create_entry\"", ":", "{", "\"default\"", ":", "\"[%key:common::config_flow::create_entry::authenticated%]\"", "}", ",", "}", ",", ")" ]
[ 69, 0 ]
[ 173, 9 ]
python
en
['en', 'ga', 'en']
True
test_setup_params
(hass, mqtt_mock)
Test the initial parameters.
Test the initial parameters.
async def test_setup_params(hass, mqtt_mock): """Test the initial parameters.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 21 assert state.attributes.get("fan_mode") == "low" assert state.attributes.get("swing_mode") == "off" assert state.state == "off" assert state.attributes.get("min_temp") == DEFAULT_MIN_TEMP assert state.attributes.get("max_temp") == DEFAULT_MAX_TEMP
[ "async", "def", "test_setup_params", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "21", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "==", "\"low\"", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "==", "\"off\"", "assert", "state", ".", "state", "==", "\"off\"", "assert", "state", ".", "attributes", ".", "get", "(", "\"min_temp\"", ")", "==", "DEFAULT_MIN_TEMP", "assert", "state", ".", "attributes", ".", "get", "(", "\"max_temp\"", ")", "==", "DEFAULT_MAX_TEMP" ]
[ 74, 0 ]
[ 85, 63 ]
python
en
['en', 'en', 'en']
True
test_supported_features
(hass, mqtt_mock)
Test the supported_features.
Test the supported_features.
async def test_supported_features(hass, mqtt_mock): """Test the supported_features.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) support = ( SUPPORT_TARGET_TEMPERATURE | SUPPORT_SWING_MODE | SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE | SUPPORT_AUX_HEAT | SUPPORT_TARGET_TEMPERATURE_RANGE ) assert state.attributes.get("supported_features") == support
[ "async", "def", "test_supported_features", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "support", "=", "(", "SUPPORT_TARGET_TEMPERATURE", "|", "SUPPORT_SWING_MODE", "|", "SUPPORT_FAN_MODE", "|", "SUPPORT_PRESET_MODE", "|", "SUPPORT_AUX_HEAT", "|", "SUPPORT_TARGET_TEMPERATURE_RANGE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"supported_features\"", ")", "==", "support" ]
[ 88, 0 ]
[ 103, 64 ]
python
en
['en', 'en', 'en']
True
test_get_hvac_modes
(hass, mqtt_mock)
Test that the operation list returns the correct modes.
Test that the operation list returns the correct modes.
async def test_get_hvac_modes(hass, mqtt_mock): """Test that the operation list returns the correct modes.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) modes = state.attributes.get("hvac_modes") assert [ HVAC_MODE_AUTO, STATE_OFF, HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, ] == modes
[ "async", "def", "test_get_hvac_modes", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "modes", "=", "state", ".", "attributes", ".", "get", "(", "\"hvac_modes\"", ")", "assert", "[", "HVAC_MODE_AUTO", ",", "STATE_OFF", ",", "HVAC_MODE_COOL", ",", "HVAC_MODE_HEAT", ",", "HVAC_MODE_DRY", ",", "HVAC_MODE_FAN_ONLY", ",", "]", "==", "modes" ]
[ 106, 0 ]
[ 120, 14 ]
python
en
['en', 'en', 'en']
True
test_set_operation_bad_attr_and_state
(hass, mqtt_mock, caplog)
Test setting operation mode without required attribute. Also check the state.
Test setting operation mode without required attribute.
async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog): """Test setting operation mode without required attribute. Also check the state. """ assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off" with pytest.raises(vol.Invalid) as excinfo: await common.async_set_hvac_mode(hass, None, ENTITY_CLIMATE) assert ("value is not allowed for dictionary value @ data['hvac_mode']") in str( excinfo.value ) state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off"
[ "async", "def", "test_set_operation_bad_attr_and_state", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"off\"", "with", "pytest", ".", "raises", "(", "vol", ".", "Invalid", ")", "as", "excinfo", ":", "await", "common", ".", "async_set_hvac_mode", "(", "hass", ",", "None", ",", "ENTITY_CLIMATE", ")", "assert", "(", "\"value is not allowed for dictionary value @ data['hvac_mode']\"", ")", "in", "str", "(", "excinfo", ".", "value", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"off\"" ]
[ 123, 0 ]
[ 139, 31 ]
python
en
['en', 'en', 'en']
True
test_set_operation
(hass, mqtt_mock)
Test setting of new operation mode.
Test setting of new operation mode.
async def test_set_operation(hass, mqtt_mock): """Test setting of new operation mode.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off" await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.state == "cool" assert state.state == "cool" mqtt_mock.async_publish.assert_called_once_with("mode-topic", "cool", 0, False)
[ "async", "def", "test_set_operation", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"off\"", "await", "common", ".", "async_set_hvac_mode", "(", "hass", ",", "\"cool\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"cool\"", "assert", "state", ".", "state", "==", "\"cool\"", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"mode-topic\"", ",", "\"cool\"", ",", "0", ",", "False", ")" ]
[ 142, 0 ]
[ 153, 83 ]
python
en
['en', 'en', 'en']
True
test_set_operation_pessimistic
(hass, mqtt_mock)
Test setting operation mode in pessimistic mode.
Test setting operation mode in pessimistic mode.
async def test_set_operation_pessimistic(hass, mqtt_mock): """Test setting operation mode in pessimistic mode.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["mode_state_topic"] = "mode-state" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "unknown" await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.state == "unknown" async_fire_mqtt_message(hass, "mode-state", "cool") state = hass.states.get(ENTITY_CLIMATE) assert state.state == "cool" async_fire_mqtt_message(hass, "mode-state", "bogus mode") state = hass.states.get(ENTITY_CLIMATE) assert state.state == "cool"
[ "async", "def", "test_set_operation_pessimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"mode_state_topic\"", "]", "=", "\"mode-state\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"unknown\"", "await", "common", ".", "async_set_hvac_mode", "(", "hass", ",", "\"cool\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"unknown\"", "async_fire_mqtt_message", "(", "hass", ",", "\"mode-state\"", ",", "\"cool\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"cool\"", "async_fire_mqtt_message", "(", "hass", ",", "\"mode-state\"", ",", "\"bogus mode\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"cool\"" ]
[ 156, 0 ]
[ 176, 32 ]
python
en
['en', 'en', 'en']
True
test_set_operation_with_power_command
(hass, mqtt_mock)
Test setting of new operation mode with power command enabled.
Test setting of new operation mode with power command enabled.
async def test_set_operation_with_power_command(hass, mqtt_mock): """Test setting of new operation mode with power command enabled.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["power_command_topic"] = "power-command" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off" await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.state == "cool" mqtt_mock.async_publish.assert_has_calls( [call("power-command", "ON", 0, False), call("mode-topic", "cool", 0, False)] ) mqtt_mock.async_publish.reset_mock() await common.async_set_hvac_mode(hass, "off", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off" mqtt_mock.async_publish.assert_has_calls( [call("power-command", "OFF", 0, False), call("mode-topic", "off", 0, False)] ) mqtt_mock.async_publish.reset_mock()
[ "async", "def", "test_set_operation_with_power_command", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"power_command_topic\"", "]", "=", "\"power-command\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"off\"", "await", "common", ".", "async_set_hvac_mode", "(", "hass", ",", "\"cool\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"cool\"", "mqtt_mock", ".", "async_publish", ".", "assert_has_calls", "(", "[", "call", "(", "\"power-command\"", ",", "\"ON\"", ",", "0", ",", "False", ")", ",", "call", "(", "\"mode-topic\"", ",", "\"cool\"", ",", "0", ",", "False", ")", "]", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "await", "common", ".", "async_set_hvac_mode", "(", "hass", ",", "\"off\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"off\"", "mqtt_mock", ".", "async_publish", ".", "assert_has_calls", "(", "[", "call", "(", "\"power-command\"", ",", "\"OFF\"", ",", "0", ",", "False", ")", ",", "call", "(", "\"mode-topic\"", ",", "\"off\"", ",", "0", ",", "False", ")", "]", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")" ]
[ 179, 0 ]
[ 202, 40 ]
python
en
['en', 'en', 'en']
True
test_set_fan_mode_bad_attr
(hass, mqtt_mock, caplog)
Test setting fan mode without required attribute.
Test setting fan mode without required attribute.
async def test_set_fan_mode_bad_attr(hass, mqtt_mock, caplog): """Test setting fan mode without required attribute.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "low" with pytest.raises(vol.Invalid) as excinfo: await common.async_set_fan_mode(hass, None, ENTITY_CLIMATE) assert "string value is None for dictionary value @ data['fan_mode']" in str( excinfo.value ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "low"
[ "async", "def", "test_set_fan_mode_bad_attr", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "==", "\"low\"", "with", "pytest", ".", "raises", "(", "vol", ".", "Invalid", ")", "as", "excinfo", ":", "await", "common", ".", "async_set_fan_mode", "(", "hass", ",", "None", ",", "ENTITY_CLIMATE", ")", "assert", "\"string value is None for dictionary value @ data['fan_mode']\"", "in", "str", "(", "excinfo", ".", "value", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "==", "\"low\"" ]
[ 205, 0 ]
[ 218, 52 ]
python
en
['en', 'en', 'en']
True
test_set_fan_mode_pessimistic
(hass, mqtt_mock)
Test setting of new fan mode in pessimistic mode.
Test setting of new fan mode in pessimistic mode.
async def test_set_fan_mode_pessimistic(hass, mqtt_mock): """Test setting of new fan mode in pessimistic mode.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["fan_mode_state_topic"] = "fan-state" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") is None await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") is None async_fire_mqtt_message(hass, "fan-state", "high") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "high" async_fire_mqtt_message(hass, "fan-state", "bogus mode") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "high"
[ "async", "def", "test_set_fan_mode_pessimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"fan_mode_state_topic\"", "]", "=", "\"fan-state\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "is", "None", "await", "common", ".", "async_set_fan_mode", "(", "hass", ",", "\"high\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"fan-state\"", ",", "\"high\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "==", "\"high\"", "async_fire_mqtt_message", "(", "hass", ",", "\"fan-state\"", ",", "\"bogus mode\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "==", "\"high\"" ]
[ 221, 0 ]
[ 241, 53 ]
python
en
['en', 'en', 'en']
True
test_set_fan_mode
(hass, mqtt_mock)
Test setting of new fan mode.
Test setting of new fan mode.
async def test_set_fan_mode(hass, mqtt_mock): """Test setting of new fan mode.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "low" await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("fan-mode-topic", "high", 0, False) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "high"
[ "async", "def", "test_set_fan_mode", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "==", "\"low\"", "await", "common", ".", "async_set_fan_mode", "(", "hass", ",", "\"high\"", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"fan-mode-topic\"", ",", "\"high\"", ",", "0", ",", "False", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "==", "\"high\"" ]
[ 244, 0 ]
[ 254, 53 ]
python
en
['en', 'fy', 'en']
True
test_set_swing_mode_bad_attr
(hass, mqtt_mock, caplog)
Test setting swing mode without required attribute.
Test setting swing mode without required attribute.
async def test_set_swing_mode_bad_attr(hass, mqtt_mock, caplog): """Test setting swing mode without required attribute.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "off" with pytest.raises(vol.Invalid) as excinfo: await common.async_set_swing_mode(hass, None, ENTITY_CLIMATE) assert "string value is None for dictionary value @ data['swing_mode']" in str( excinfo.value ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "off"
[ "async", "def", "test_set_swing_mode_bad_attr", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "==", "\"off\"", "with", "pytest", ".", "raises", "(", "vol", ".", "Invalid", ")", "as", "excinfo", ":", "await", "common", ".", "async_set_swing_mode", "(", "hass", ",", "None", ",", "ENTITY_CLIMATE", ")", "assert", "\"string value is None for dictionary value @ data['swing_mode']\"", "in", "str", "(", "excinfo", ".", "value", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "==", "\"off\"" ]
[ 257, 0 ]
[ 270, 54 ]
python
en
['en', 'en', 'en']
True
test_set_swing_pessimistic
(hass, mqtt_mock)
Test setting swing mode in pessimistic mode.
Test setting swing mode in pessimistic mode.
async def test_set_swing_pessimistic(hass, mqtt_mock): """Test setting swing mode in pessimistic mode.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["swing_mode_state_topic"] = "swing-state" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") is None await common.async_set_swing_mode(hass, "on", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") is None async_fire_mqtt_message(hass, "swing-state", "on") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "on" async_fire_mqtt_message(hass, "swing-state", "bogus state") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "on"
[ "async", "def", "test_set_swing_pessimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"swing_mode_state_topic\"", "]", "=", "\"swing-state\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "is", "None", "await", "common", ".", "async_set_swing_mode", "(", "hass", ",", "\"on\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"swing-state\"", ",", "\"on\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "==", "\"on\"", "async_fire_mqtt_message", "(", "hass", ",", "\"swing-state\"", ",", "\"bogus state\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "==", "\"on\"" ]
[ 273, 0 ]
[ 293, 53 ]
python
en
['en', 'en', 'it']
True
test_set_swing
(hass, mqtt_mock)
Test setting of new swing mode.
Test setting of new swing mode.
async def test_set_swing(hass, mqtt_mock): """Test setting of new swing mode.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "off" await common.async_set_swing_mode(hass, "on", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("swing-mode-topic", "on", 0, False) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "on"
[ "async", "def", "test_set_swing", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "==", "\"off\"", "await", "common", ".", "async_set_swing_mode", "(", "hass", ",", "\"on\"", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"swing-mode-topic\"", ",", "\"on\"", ",", "0", ",", "False", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "==", "\"on\"" ]
[ 296, 0 ]
[ 306, 53 ]
python
en
['en', 'en', 'en']
True
test_set_target_temperature
(hass, mqtt_mock)
Test setting the target temperature.
Test setting the target temperature.
async def test_set_target_temperature(hass, mqtt_mock): """Test setting the target temperature.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 21 await common.async_set_hvac_mode(hass, "heat", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.state == "heat" mqtt_mock.async_publish.assert_called_once_with("mode-topic", "heat", 0, False) mqtt_mock.async_publish.reset_mock() await common.async_set_temperature(hass, temperature=47, entity_id=ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 47 mqtt_mock.async_publish.assert_called_once_with( "temperature-topic", "47.0", 0, False ) # also test directly supplying the operation mode to set_temperature mqtt_mock.async_publish.reset_mock() await common.async_set_temperature( hass, temperature=21, hvac_mode="cool", entity_id=ENTITY_CLIMATE ) state = hass.states.get(ENTITY_CLIMATE) assert state.state == "cool" assert state.attributes.get("temperature") == 21 mqtt_mock.async_publish.assert_has_calls( [ call("mode-topic", "cool", 0, False), call("temperature-topic", "21.0", 0, False), ] ) mqtt_mock.async_publish.reset_mock()
[ "async", "def", "test_set_target_temperature", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "21", "await", "common", ".", "async_set_hvac_mode", "(", "hass", ",", "\"heat\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"heat\"", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"mode-topic\"", ",", "\"heat\"", ",", "0", ",", "False", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "await", "common", ".", "async_set_temperature", "(", "hass", ",", "temperature", "=", "47", ",", "entity_id", "=", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "47", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"temperature-topic\"", ",", "\"47.0\"", ",", "0", ",", "False", ")", "# also test directly supplying the operation mode to set_temperature", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "await", "common", ".", "async_set_temperature", "(", "hass", ",", "temperature", "=", "21", ",", "hvac_mode", "=", "\"cool\"", ",", "entity_id", "=", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"cool\"", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "21", "mqtt_mock", ".", "async_publish", ".", "assert_has_calls", "(", "[", "call", "(", "\"mode-topic\"", ",", "\"cool\"", ",", "0", ",", "False", ")", ",", "call", "(", "\"temperature-topic\"", ",", "\"21.0\"", ",", "0", ",", "False", ")", ",", "]", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")" ]
[ 309, 0 ]
[ 342, 40 ]
python
en
['en', 'en', 'en']
True
test_set_target_temperature_pessimistic
(hass, mqtt_mock)
Test setting the target temperature.
Test setting the target temperature.
async def test_set_target_temperature_pessimistic(hass, mqtt_mock): """Test setting the target temperature.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["temperature_state_topic"] = "temperature-state" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") is None await common.async_set_hvac_mode(hass, "heat", ENTITY_CLIMATE) await common.async_set_temperature(hass, temperature=47, entity_id=ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") is None async_fire_mqtt_message(hass, "temperature-state", "1701") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 1701 async_fire_mqtt_message(hass, "temperature-state", "not a number") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 1701
[ "async", "def", "test_set_target_temperature_pessimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"temperature_state_topic\"", "]", "=", "\"temperature-state\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "is", "None", "await", "common", ".", "async_set_hvac_mode", "(", "hass", ",", "\"heat\"", ",", "ENTITY_CLIMATE", ")", "await", "common", ".", "async_set_temperature", "(", "hass", ",", "temperature", "=", "47", ",", "entity_id", "=", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-state\"", ",", "\"1701\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "1701", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-state\"", ",", "\"not a number\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "1701" ]
[ 345, 0 ]
[ 365, 54 ]
python
en
['en', 'en', 'en']
True
test_set_target_temperature_low_high
(hass, mqtt_mock)
Test setting the low/high target temperature.
Test setting the low/high target temperature.
async def test_set_target_temperature_low_high(hass, mqtt_mock): """Test setting the low/high target temperature.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() await common.async_set_temperature( hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") == 20 assert state.attributes.get("target_temp_high") == 23 mqtt_mock.async_publish.assert_any_call("temperature-low-topic", "20.0", 0, False) mqtt_mock.async_publish.assert_any_call("temperature-high-topic", "23.0", 0, False)
[ "async", "def", "test_set_target_temperature_low_high", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "common", ".", "async_set_temperature", "(", "hass", ",", "target_temp_low", "=", "20", ",", "target_temp_high", "=", "23", ",", "entity_id", "=", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "==", "20", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "==", "23", "mqtt_mock", ".", "async_publish", ".", "assert_any_call", "(", "\"temperature-low-topic\"", ",", "\"20.0\"", ",", "0", ",", "False", ")", "mqtt_mock", ".", "async_publish", ".", "assert_any_call", "(", "\"temperature-high-topic\"", ",", "\"23.0\"", ",", "0", ",", "False", ")" ]
[ 368, 0 ]
[ 380, 87 ]
python
en
['en', 'en', 'en']
True
test_set_target_temperature_low_highpessimistic
(hass, mqtt_mock)
Test setting the low/high target temperature.
Test setting the low/high target temperature.
async def test_set_target_temperature_low_highpessimistic(hass, mqtt_mock): """Test setting the low/high target temperature.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["temperature_low_state_topic"] = "temperature-low-state" config["climate"]["temperature_high_state_topic"] = "temperature-high-state" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") is None assert state.attributes.get("target_temp_high") is None await common.async_set_temperature( hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") is None assert state.attributes.get("target_temp_high") is None async_fire_mqtt_message(hass, "temperature-low-state", "1701") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") == 1701 assert state.attributes.get("target_temp_high") is None async_fire_mqtt_message(hass, "temperature-high-state", "1703") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") == 1701 assert state.attributes.get("target_temp_high") == 1703 async_fire_mqtt_message(hass, "temperature-low-state", "not a number") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") == 1701 async_fire_mqtt_message(hass, "temperature-high-state", "not a number") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_high") == 1703
[ "async", "def", "test_set_target_temperature_low_highpessimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"temperature_low_state_topic\"", "]", "=", "\"temperature-low-state\"", "config", "[", "\"climate\"", "]", "[", "\"temperature_high_state_topic\"", "]", "=", "\"temperature-high-state\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "is", "None", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "is", "None", "await", "common", ".", "async_set_temperature", "(", "hass", ",", "target_temp_low", "=", "20", ",", "target_temp_high", "=", "23", ",", "entity_id", "=", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "is", "None", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-low-state\"", ",", "\"1701\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "==", "1701", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-high-state\"", ",", "\"1703\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "==", "1701", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "==", "1703", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-low-state\"", ",", "\"not a number\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "==", "1701", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-high-state\"", ",", "\"not a number\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "==", "1703" ]
[ 383, 0 ]
[ 417, 59 ]
python
en
['en', 'en', 'en']
True
test_receive_mqtt_temperature
(hass, mqtt_mock)
Test getting the current temperature via MQTT.
Test getting the current temperature via MQTT.
async def test_receive_mqtt_temperature(hass, mqtt_mock): """Test getting the current temperature via MQTT.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["current_temperature_topic"] = "current_temperature" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() async_fire_mqtt_message(hass, "current_temperature", "47") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("current_temperature") == 47
[ "async", "def", "test_receive_mqtt_temperature", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"current_temperature_topic\"", "]", "=", "\"current_temperature\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "async_fire_mqtt_message", "(", "hass", ",", "\"current_temperature\"", ",", "\"47\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_temperature\"", ")", "==", "47" ]
[ 420, 0 ]
[ 429, 60 ]
python
en
['en', 'co', 'en']
True
test_set_away_mode_pessimistic
(hass, mqtt_mock)
Test setting of the away mode.
Test setting of the away mode.
async def test_set_away_mode_pessimistic(hass, mqtt_mock): """Test setting of the away mode.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["away_mode_state_topic"] = "away-state" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" async_fire_mqtt_message(hass, "away-state", "ON") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "away" async_fire_mqtt_message(hass, "away-state", "OFF") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" async_fire_mqtt_message(hass, "away-state", "nonsense") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none"
[ "async", "def", "test_set_away_mode_pessimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"away_mode_state_topic\"", "]", "=", "\"away-state\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "\"away\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "async_fire_mqtt_message", "(", "hass", ",", "\"away-state\"", ",", "\"ON\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"away\"", "async_fire_mqtt_message", "(", "hass", ",", "\"away-state\"", ",", "\"OFF\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "async_fire_mqtt_message", "(", "hass", ",", "\"away-state\"", ",", "\"nonsense\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"" ]
[ 432, 0 ]
[ 456, 56 ]
python
en
['en', 'en', 'en']
True
test_set_away_mode
(hass, mqtt_mock)
Test setting of the away mode.
Test setting of the away mode.
async def test_set_away_mode(hass, mqtt_mock): """Test setting of the away mode.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["payload_on"] = "AN" config["climate"]["payload_off"] = "AUS" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("away-mode-topic", "AN", 0, False) mqtt_mock.async_publish.reset_mock() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "away" await common.async_set_preset_mode(hass, PRESET_NONE, ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("away-mode-topic", "AUS", 0, False) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE) mqtt_mock.async_publish.reset_mock() await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_has_calls( [call("hold-topic", "off", 0, False), call("away-mode-topic", "AN", 0, False)] ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "away"
[ "async", "def", "test_set_away_mode", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"payload_on\"", "]", "=", "\"AN\"", "config", "[", "\"climate\"", "]", "[", "\"payload_off\"", "]", "=", "\"AUS\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "\"away\"", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"away-mode-topic\"", ",", "\"AN\"", ",", "0", ",", "False", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"away\"", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "PRESET_NONE", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"away-mode-topic\"", ",", "\"AUS\"", ",", "0", ",", "False", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "\"hold-on\"", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "\"away\"", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_has_calls", "(", "[", "call", "(", "\"hold-topic\"", ",", "\"off\"", ",", "0", ",", "False", ")", ",", "call", "(", "\"away-mode-topic\"", ",", "\"AN\"", ",", "0", ",", "False", ")", "]", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"away\"" ]
[ 459, 0 ]
[ 489, 56 ]
python
en
['en', 'en', 'en']
True
test_set_hvac_action
(hass, mqtt_mock)
Test setting of the HVAC action.
Test setting of the HVAC action.
async def test_set_hvac_action(hass, mqtt_mock): """Test setting of the HVAC action.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["action_topic"] = "action" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("hvac_action") is None async_fire_mqtt_message(hass, "action", "cool") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("hvac_action") == "cool"
[ "async", "def", "test_set_hvac_action", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"action_topic\"", "]", "=", "\"action\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"hvac_action\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"action\"", ",", "\"cool\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"hvac_action\"", ")", "==", "\"cool\"" ]
[ 492, 0 ]
[ 504, 56 ]
python
en
['en', 'en', 'en']
True
test_set_hold_pessimistic
(hass, mqtt_mock)
Test setting the hold mode in pessimistic mode.
Test setting the hold mode in pessimistic mode.
async def test_set_hold_pessimistic(hass, mqtt_mock): """Test setting the hold mode in pessimistic mode.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["hold_state_topic"] = "hold-state" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("hold_mode") is None await common.async_set_preset_mode(hass, "hold", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("hold_mode") is None async_fire_mqtt_message(hass, "hold-state", "on") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "on" async_fire_mqtt_message(hass, "hold-state", "off") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none"
[ "async", "def", "test_set_hold_pessimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"hold_state_topic\"", "]", "=", "\"hold-state\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"hold_mode\"", ")", "is", "None", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "\"hold\"", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"hold_mode\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"hold-state\"", ",", "\"on\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"on\"", "async_fire_mqtt_message", "(", "hass", ",", "\"hold-state\"", ",", "\"off\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"" ]
[ 507, 0 ]
[ 527, 56 ]
python
en
['en', 'en', 'en']
True
test_set_hold
(hass, mqtt_mock)
Test setting the hold mode.
Test setting the hold mode.
async def test_set_hold(hass, mqtt_mock): """Test setting the hold mode.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("hold-topic", "hold-on", 0, False) mqtt_mock.async_publish.reset_mock() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "hold-on" await common.async_set_preset_mode(hass, PRESET_ECO, ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("hold-topic", "eco", 0, False) mqtt_mock.async_publish.reset_mock() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == PRESET_ECO await common.async_set_preset_mode(hass, PRESET_NONE, ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("hold-topic", "off", 0, False) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none"
[ "async", "def", "test_set_hold", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "\"hold-on\"", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"hold-topic\"", ",", "\"hold-on\"", ",", "0", ",", "False", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"hold-on\"", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "PRESET_ECO", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"hold-topic\"", ",", "\"eco\"", ",", "0", ",", "False", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "PRESET_ECO", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "PRESET_NONE", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"hold-topic\"", ",", "\"off\"", ",", "0", ",", "False", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"" ]
[ 530, 0 ]
[ 552, 56 ]
python
en
['en', 'en', 'en']
True
test_set_preset_mode_twice
(hass, mqtt_mock)
Test setting of the same mode twice only publishes once.
Test setting of the same mode twice only publishes once.
async def test_set_preset_mode_twice(hass, mqtt_mock): """Test setting of the same mode twice only publishes once.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("hold-topic", "hold-on", 0, False) mqtt_mock.async_publish.reset_mock() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "hold-on" await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_not_called()
[ "async", "def", "test_set_preset_mode_twice", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "\"hold-on\"", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"hold-topic\"", ",", "\"hold-on\"", ",", "0", ",", "False", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"hold-on\"", "await", "common", ".", "async_set_preset_mode", "(", "hass", ",", "\"hold-on\"", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_not_called", "(", ")" ]
[ 555, 0 ]
[ 569, 47 ]
python
en
['en', 'en', 'en']
True
test_set_aux_pessimistic
(hass, mqtt_mock)
Test setting of the aux heating in pessimistic mode.
Test setting of the aux heating in pessimistic mode.
async def test_set_aux_pessimistic(hass, mqtt_mock): """Test setting of the aux heating in pessimistic mode.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["aux_state_topic"] = "aux-state" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off" await common.async_set_aux_heat(hass, True, ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off" async_fire_mqtt_message(hass, "aux-state", "ON") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "on" async_fire_mqtt_message(hass, "aux-state", "OFF") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off" async_fire_mqtt_message(hass, "aux-state", "nonsense") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off"
[ "async", "def", "test_set_aux_pessimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"aux_state_topic\"", "]", "=", "\"aux-state\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"off\"", "await", "common", ".", "async_set_aux_heat", "(", "hass", ",", "True", ",", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"off\"", "async_fire_mqtt_message", "(", "hass", ",", "\"aux-state\"", ",", "\"ON\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"on\"", "async_fire_mqtt_message", "(", "hass", ",", "\"aux-state\"", ",", "\"OFF\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"off\"", "async_fire_mqtt_message", "(", "hass", ",", "\"aux-state\"", ",", "\"nonsense\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"off\"" ]
[ 572, 0 ]
[ 596, 52 ]
python
en
['en', 'en', 'en']
True
test_set_aux
(hass, mqtt_mock)
Test setting of the aux heating.
Test setting of the aux heating.
async def test_set_aux(hass, mqtt_mock): """Test setting of the aux heating.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off" await common.async_set_aux_heat(hass, True, ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("aux-topic", "ON", 0, False) mqtt_mock.async_publish.reset_mock() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "on" await common.async_set_aux_heat(hass, False, ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("aux-topic", "OFF", 0, False) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off"
[ "async", "def", "test_set_aux", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"off\"", "await", "common", ".", "async_set_aux_heat", "(", "hass", ",", "True", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"aux-topic\"", ",", "\"ON\"", ",", "0", ",", "False", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"on\"", "await", "common", ".", "async_set_aux_heat", "(", "hass", ",", "False", ",", "ENTITY_CLIMATE", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"aux-topic\"", ",", "\"OFF\"", ",", "0", ",", "False", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"off\"" ]
[ 599, 0 ]
[ 615, 52 ]
python
en
['en', 'en', 'en']
True
test_availability_when_connection_lost
(hass, mqtt_mock)
Test availability after MQTT disconnection.
Test availability after MQTT disconnection.
async def test_availability_when_connection_lost(hass, mqtt_mock): """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_availability_when_connection_lost", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_availability_when_connection_lost", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 618, 0 ]
[ 622, 5 ]
python
en
['en', 'en', 'en']
True
test_availability_without_topic
(hass, mqtt_mock)
Test availability without defined availability topic.
Test availability without defined availability topic.
async def test_availability_without_topic(hass, mqtt_mock): """Test availability without defined availability topic.""" await help_test_availability_without_topic( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_availability_without_topic", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_availability_without_topic", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 625, 0 ]
[ 629, 5 ]
python
en
['en', 'en', 'en']
True
test_default_availability_payload
(hass, mqtt_mock)
Test availability by default payload with defined topic.
Test availability by default payload with defined topic.
async def test_default_availability_payload(hass, mqtt_mock): """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_default_availability_payload", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_default_availability_payload", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 632, 0 ]
[ 636, 5 ]
python
en
['en', 'en', 'en']
True
test_custom_availability_payload
(hass, mqtt_mock)
Test availability by custom payload with defined topic.
Test availability by custom payload with defined topic.
async def test_custom_availability_payload(hass, mqtt_mock): """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_custom_availability_payload", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_custom_availability_payload", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 639, 0 ]
[ 643, 5 ]
python
en
['en', 'en', 'en']
True
test_set_target_temperature_low_high_with_templates
(hass, mqtt_mock, caplog)
Test setting of temperature high/low templates.
Test setting of temperature high/low templates.
async def test_set_target_temperature_low_high_with_templates(hass, mqtt_mock, caplog): """Test setting of temperature high/low templates.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["temperature_low_state_topic"] = "temperature-state" config["climate"]["temperature_high_state_topic"] = "temperature-state" config["climate"]["temperature_low_state_template"] = "{{ value_json.temp_low }}" config["climate"]["temperature_high_state_template"] = "{{ value_json.temp_high }}" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) # Temperature - with valid value assert state.attributes.get("target_temp_low") is None assert state.attributes.get("target_temp_high") is None async_fire_mqtt_message( hass, "temperature-state", '{"temp_low": "1031", "temp_high": "1032"}' ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") == 1031 assert state.attributes.get("target_temp_high") == 1032 # Temperature - with invalid value async_fire_mqtt_message(hass, "temperature-state", '"-INVALID-"') state = hass.states.get(ENTITY_CLIMATE) # make sure, the invalid value gets logged... assert "Could not parse temperature from" in caplog.text # ... but the actual value stays unchanged. assert state.attributes.get("target_temp_low") == 1031 assert state.attributes.get("target_temp_high") == 1032
[ "async", "def", "test_set_target_temperature_low_high_with_templates", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"temperature_low_state_topic\"", "]", "=", "\"temperature-state\"", "config", "[", "\"climate\"", "]", "[", "\"temperature_high_state_topic\"", "]", "=", "\"temperature-state\"", "config", "[", "\"climate\"", "]", "[", "\"temperature_low_state_template\"", "]", "=", "\"{{ value_json.temp_low }}\"", "config", "[", "\"climate\"", "]", "[", "\"temperature_high_state_template\"", "]", "=", "\"{{ value_json.temp_high }}\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "# Temperature - with valid value", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "is", "None", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-state\"", ",", "'{\"temp_low\": \"1031\", \"temp_high\": \"1032\"}'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "==", "1031", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "==", "1032", "# Temperature - with invalid value", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-state\"", ",", "'\"-INVALID-\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "# make sure, the invalid value gets logged...", "assert", "\"Could not parse temperature from\"", "in", "caplog", ".", "text", "# ... but the actual value stays unchanged.", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_low\"", ")", "==", "1031", "assert", "state", ".", "attributes", ".", "get", "(", "\"target_temp_high\"", ")", "==", "1032" ]
[ 646, 0 ]
[ 677, 59 ]
python
en
['en', 'en', 'en']
True
test_set_with_templates
(hass, mqtt_mock, caplog)
Test setting of new fan mode in pessimistic mode.
Test setting of new fan mode in pessimistic mode.
async def test_set_with_templates(hass, mqtt_mock, caplog): """Test setting of new fan mode in pessimistic mode.""" config = copy.deepcopy(DEFAULT_CONFIG) # By default, just unquote the JSON-strings config["climate"]["value_template"] = "{{ value_json }}" config["climate"]["action_template"] = "{{ value_json }}" # Something more complicated for hold mode config["climate"]["hold_state_template"] = "{{ value_json.attribute }}" # Rendering to a bool for aux heat config["climate"]["aux_state_template"] = "{{ value == 'switchmeon' }}" config["climate"]["action_topic"] = "action" config["climate"]["mode_state_topic"] = "mode-state" config["climate"]["fan_mode_state_topic"] = "fan-state" config["climate"]["swing_mode_state_topic"] = "swing-state" config["climate"]["temperature_state_topic"] = "temperature-state" config["climate"]["away_mode_state_topic"] = "away-state" config["climate"]["hold_state_topic"] = "hold-state" config["climate"]["aux_state_topic"] = "aux-state" config["climate"]["current_temperature_topic"] = "current-temperature" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() # Operation Mode state = hass.states.get(ENTITY_CLIMATE) async_fire_mqtt_message(hass, "mode-state", '"cool"') state = hass.states.get(ENTITY_CLIMATE) assert state.state == "cool" # Fan Mode assert state.attributes.get("fan_mode") is None async_fire_mqtt_message(hass, "fan-state", '"high"') state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "high" # Swing Mode assert state.attributes.get("swing_mode") is None async_fire_mqtt_message(hass, "swing-state", '"on"') state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "on" # Temperature - with valid value assert state.attributes.get("temperature") is None async_fire_mqtt_message(hass, "temperature-state", '"1031"') state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 1031 # Temperature - with invalid value async_fire_mqtt_message(hass, "temperature-state", '"-INVALID-"') state = hass.states.get(ENTITY_CLIMATE) # make sure, the invalid value gets logged... assert "Could not parse temperature from -INVALID-" in caplog.text # ... but the actual value stays unchanged. assert state.attributes.get("temperature") == 1031 # Away Mode assert state.attributes.get("preset_mode") == "none" async_fire_mqtt_message(hass, "away-state", '"ON"') state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "away" # Away Mode with JSON values async_fire_mqtt_message(hass, "away-state", "false") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" async_fire_mqtt_message(hass, "away-state", "true") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "away" # Hold Mode async_fire_mqtt_message( hass, "hold-state", """ { "attribute": "somemode" } """, ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "somemode" # Aux mode assert state.attributes.get("aux_heat") == "off" async_fire_mqtt_message(hass, "aux-state", "switchmeon") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "on" # anything other than 'switchmeon' should turn Aux mode off async_fire_mqtt_message(hass, "aux-state", "somerandomstring") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off" # Current temperature async_fire_mqtt_message(hass, "current-temperature", '"74656"') state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("current_temperature") == 74656 # Action async_fire_mqtt_message(hass, "action", '"cool"') state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("hvac_action") == "cool"
[ "async", "def", "test_set_with_templates", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "# By default, just unquote the JSON-strings", "config", "[", "\"climate\"", "]", "[", "\"value_template\"", "]", "=", "\"{{ value_json }}\"", "config", "[", "\"climate\"", "]", "[", "\"action_template\"", "]", "=", "\"{{ value_json }}\"", "# Something more complicated for hold mode", "config", "[", "\"climate\"", "]", "[", "\"hold_state_template\"", "]", "=", "\"{{ value_json.attribute }}\"", "# Rendering to a bool for aux heat", "config", "[", "\"climate\"", "]", "[", "\"aux_state_template\"", "]", "=", "\"{{ value == 'switchmeon' }}\"", "config", "[", "\"climate\"", "]", "[", "\"action_topic\"", "]", "=", "\"action\"", "config", "[", "\"climate\"", "]", "[", "\"mode_state_topic\"", "]", "=", "\"mode-state\"", "config", "[", "\"climate\"", "]", "[", "\"fan_mode_state_topic\"", "]", "=", "\"fan-state\"", "config", "[", "\"climate\"", "]", "[", "\"swing_mode_state_topic\"", "]", "=", "\"swing-state\"", "config", "[", "\"climate\"", "]", "[", "\"temperature_state_topic\"", "]", "=", "\"temperature-state\"", "config", "[", "\"climate\"", "]", "[", "\"away_mode_state_topic\"", "]", "=", "\"away-state\"", "config", "[", "\"climate\"", "]", "[", "\"hold_state_topic\"", "]", "=", "\"hold-state\"", "config", "[", "\"climate\"", "]", "[", "\"aux_state_topic\"", "]", "=", "\"aux-state\"", "config", "[", "\"climate\"", "]", "[", "\"current_temperature_topic\"", "]", "=", "\"current-temperature\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "# Operation Mode", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "async_fire_mqtt_message", "(", "hass", ",", "\"mode-state\"", ",", "'\"cool\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "state", "==", "\"cool\"", "# Fan Mode", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"fan-state\"", ",", "'\"high\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"fan_mode\"", ")", "==", "\"high\"", "# Swing Mode", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"swing-state\"", ",", "'\"on\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"swing_mode\"", ")", "==", "\"on\"", "# Temperature - with valid value", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "is", "None", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-state\"", ",", "'\"1031\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "1031", "# Temperature - with invalid value", "async_fire_mqtt_message", "(", "hass", ",", "\"temperature-state\"", ",", "'\"-INVALID-\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "# make sure, the invalid value gets logged...", "assert", "\"Could not parse temperature from -INVALID-\"", "in", "caplog", ".", "text", "# ... but the actual value stays unchanged.", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "1031", "# Away Mode", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "async_fire_mqtt_message", "(", "hass", ",", "\"away-state\"", ",", "'\"ON\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"away\"", "# Away Mode with JSON values", "async_fire_mqtt_message", "(", "hass", ",", "\"away-state\"", ",", "\"false\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"none\"", "async_fire_mqtt_message", "(", "hass", ",", "\"away-state\"", ",", "\"true\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"away\"", "# Hold Mode", "async_fire_mqtt_message", "(", "hass", ",", "\"hold-state\"", ",", "\"\"\"\n { \"attribute\": \"somemode\" }\n \"\"\"", ",", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"preset_mode\"", ")", "==", "\"somemode\"", "# Aux mode", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"off\"", "async_fire_mqtt_message", "(", "hass", ",", "\"aux-state\"", ",", "\"switchmeon\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"on\"", "# anything other than 'switchmeon' should turn Aux mode off", "async_fire_mqtt_message", "(", "hass", ",", "\"aux-state\"", ",", "\"somerandomstring\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"aux_heat\"", ")", "==", "\"off\"", "# Current temperature", "async_fire_mqtt_message", "(", "hass", ",", "\"current-temperature\"", ",", "'\"74656\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_temperature\"", ")", "==", "74656", "# Action", "async_fire_mqtt_message", "(", "hass", ",", "\"action\"", ",", "'\"cool\"'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"hvac_action\"", ")", "==", "\"cool\"" ]
[ 680, 0 ]
[ 781, 56 ]
python
en
['en', 'en', 'en']
True
test_min_temp_custom
(hass, mqtt_mock)
Test a custom min temp.
Test a custom min temp.
async def test_min_temp_custom(hass, mqtt_mock): """Test a custom min temp.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["min_temp"] = 26 assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) min_temp = state.attributes.get("min_temp") assert isinstance(min_temp, float) assert state.attributes.get("min_temp") == 26
[ "async", "def", "test_min_temp_custom", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"min_temp\"", "]", "=", "26", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "min_temp", "=", "state", ".", "attributes", ".", "get", "(", "\"min_temp\"", ")", "assert", "isinstance", "(", "min_temp", ",", "float", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"min_temp\"", ")", "==", "26" ]
[ 784, 0 ]
[ 796, 49 ]
python
en
['en', 'ga', 'en']
True
test_max_temp_custom
(hass, mqtt_mock)
Test a custom max temp.
Test a custom max temp.
async def test_max_temp_custom(hass, mqtt_mock): """Test a custom max temp.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["max_temp"] = 60 assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) max_temp = state.attributes.get("max_temp") assert isinstance(max_temp, float) assert max_temp == 60
[ "async", "def", "test_max_temp_custom", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"max_temp\"", "]", "=", "60", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "max_temp", "=", "state", ".", "attributes", ".", "get", "(", "\"max_temp\"", ")", "assert", "isinstance", "(", "max_temp", ",", "float", ")", "assert", "max_temp", "==", "60" ]
[ 799, 0 ]
[ 811, 25 ]
python
en
['en', 'gd', 'en']
True
test_temp_step_custom
(hass, mqtt_mock)
Test a custom temp step.
Test a custom temp step.
async def test_temp_step_custom(hass, mqtt_mock): """Test a custom temp step.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["temp_step"] = 0.01 assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) temp_step = state.attributes.get("target_temp_step") assert isinstance(temp_step, float) assert temp_step == 0.01
[ "async", "def", "test_temp_step_custom", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"temp_step\"", "]", "=", "0.01", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "temp_step", "=", "state", ".", "attributes", ".", "get", "(", "\"target_temp_step\"", ")", "assert", "isinstance", "(", "temp_step", ",", "float", ")", "assert", "temp_step", "==", "0.01" ]
[ 814, 0 ]
[ 826, 28 ]
python
en
['it', 'ga', 'en']
False
test_temperature_unit
(hass, mqtt_mock)
Test that setting temperature unit converts temperature values.
Test that setting temperature unit converts temperature values.
async def test_temperature_unit(hass, mqtt_mock): """Test that setting temperature unit converts temperature values.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["temperature_unit"] = "F" config["climate"]["current_temperature_topic"] = "current_temperature" assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() async_fire_mqtt_message(hass, "current_temperature", "77") state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("current_temperature") == 25
[ "async", "def", "test_temperature_unit", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"temperature_unit\"", "]", "=", "\"F\"", "config", "[", "\"climate\"", "]", "[", "\"current_temperature_topic\"", "]", "=", "\"current_temperature\"", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "async_fire_mqtt_message", "(", "hass", ",", "\"current_temperature\"", ",", "\"77\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"current_temperature\"", ")", "==", "25" ]
[ 829, 0 ]
[ 841, 60 ]
python
en
['en', 'la', 'en']
True
test_setting_attribute_via_mqtt_json_message
(hass, mqtt_mock)
Test the setting of attribute via MQTT with JSON payload.
Test the setting of attribute via MQTT with JSON payload.
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock): """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_setting_attribute_via_mqtt_json_message", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_setting_attribute_via_mqtt_json_message", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 844, 0 ]
[ 848, 5 ]
python
en
['en', 'en', 'en']
True
test_setting_attribute_with_template
(hass, mqtt_mock)
Test the setting of attribute via MQTT with JSON payload.
Test the setting of attribute via MQTT with JSON payload.
async def test_setting_attribute_with_template(hass, mqtt_mock): """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_setting_attribute_with_template", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_setting_attribute_with_template", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 851, 0 ]
[ 855, 5 ]
python
en
['en', 'en', 'en']
True
test_update_with_json_attrs_not_dict
(hass, mqtt_mock, caplog)
Test attributes get extracted from a JSON result.
Test attributes get extracted from a JSON result.
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog): """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, mqtt_mock, caplog, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_update_with_json_attrs_not_dict", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "await", "help_test_update_with_json_attrs_not_dict", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 858, 0 ]
[ 862, 5 ]
python
en
['en', 'en', 'en']
True
test_update_with_json_attrs_bad_JSON
(hass, mqtt_mock, caplog)
Test attributes get extracted from a JSON result.
Test attributes get extracted from a JSON result.
async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog): """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_JSON( hass, mqtt_mock, caplog, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_update_with_json_attrs_bad_JSON", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "await", "help_test_update_with_json_attrs_bad_JSON", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 865, 0 ]
[ 869, 5 ]
python
en
['en', 'en', 'en']
True
test_discovery_update_attr
(hass, mqtt_mock, caplog)
Test update of discovered MQTTAttributes.
Test update of discovered MQTTAttributes.
async def test_discovery_update_attr(hass, mqtt_mock, caplog): """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, mqtt_mock, caplog, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_discovery_update_attr", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "await", "help_test_discovery_update_attr", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 872, 0 ]
[ 876, 5 ]
python
en
['en', 'en', 'en']
True
test_unique_id
(hass, mqtt_mock)
Test unique id option only creates one climate per unique_id.
Test unique id option only creates one climate per unique_id.
async def test_unique_id(hass, mqtt_mock): """Test unique id option only creates one climate per unique_id.""" config = { CLIMATE_DOMAIN: [ { "platform": "mqtt", "name": "Test 1", "power_state_topic": "test-topic", "power_command_topic": "test_topic", "unique_id": "TOTALLY_UNIQUE", }, { "platform": "mqtt", "name": "Test 2", "power_state_topic": "test-topic", "power_command_topic": "test_topic", "unique_id": "TOTALLY_UNIQUE", }, ] } await help_test_unique_id(hass, mqtt_mock, CLIMATE_DOMAIN, config)
[ "async", "def", "test_unique_id", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "{", "CLIMATE_DOMAIN", ":", "[", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"Test 1\"", ",", "\"power_state_topic\"", ":", "\"test-topic\"", ",", "\"power_command_topic\"", ":", "\"test_topic\"", ",", "\"unique_id\"", ":", "\"TOTALLY_UNIQUE\"", ",", "}", ",", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"Test 2\"", ",", "\"power_state_topic\"", ":", "\"test-topic\"", ",", "\"power_command_topic\"", ":", "\"test_topic\"", ",", "\"unique_id\"", ":", "\"TOTALLY_UNIQUE\"", ",", "}", ",", "]", "}", "await", "help_test_unique_id", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "config", ")" ]
[ 879, 0 ]
[ 899, 70 ]
python
en
['en', 'fr', 'en']
True
test_discovery_removal_climate
(hass, mqtt_mock, caplog)
Test removal of discovered climate.
Test removal of discovered climate.
async def test_discovery_removal_climate(hass, mqtt_mock, caplog): """Test removal of discovered climate.""" data = json.dumps(DEFAULT_CONFIG[CLIMATE_DOMAIN]) await help_test_discovery_removal(hass, mqtt_mock, caplog, CLIMATE_DOMAIN, data)
[ "async", "def", "test_discovery_removal_climate", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "data", "=", "json", ".", "dumps", "(", "DEFAULT_CONFIG", "[", "CLIMATE_DOMAIN", "]", ")", "await", "help_test_discovery_removal", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "CLIMATE_DOMAIN", ",", "data", ")" ]
[ 902, 0 ]
[ 905, 84 ]
python
en
['en', 'en', 'en']
True
test_discovery_update_climate
(hass, mqtt_mock, caplog)
Test update of discovered climate.
Test update of discovered climate.
async def test_discovery_update_climate(hass, mqtt_mock, caplog): """Test update of discovered climate.""" data1 = '{ "name": "Beer" }' data2 = '{ "name": "Milk" }' await help_test_discovery_update( hass, mqtt_mock, caplog, CLIMATE_DOMAIN, data1, data2 )
[ "async", "def", "test_discovery_update_climate", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "data1", "=", "'{ \"name\": \"Beer\" }'", "data2", "=", "'{ \"name\": \"Milk\" }'", "await", "help_test_discovery_update", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "CLIMATE_DOMAIN", ",", "data1", ",", "data2", ")" ]
[ 908, 0 ]
[ 914, 5 ]
python
en
['en', 'en', 'en']
True
test_discovery_update_unchanged_climate
(hass, mqtt_mock, caplog)
Test update of discovered climate.
Test update of discovered climate.
async def test_discovery_update_unchanged_climate(hass, mqtt_mock, caplog): """Test update of discovered climate.""" data1 = '{ "name": "Beer" }' with patch( "homeassistant.components.mqtt.climate.MqttClimate.discovery_update" ) as discovery_update: await help_test_discovery_update_unchanged( hass, mqtt_mock, caplog, CLIMATE_DOMAIN, data1, discovery_update )
[ "async", "def", "test_discovery_update_unchanged_climate", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "data1", "=", "'{ \"name\": \"Beer\" }'", "with", "patch", "(", "\"homeassistant.components.mqtt.climate.MqttClimate.discovery_update\"", ")", "as", "discovery_update", ":", "await", "help_test_discovery_update_unchanged", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "CLIMATE_DOMAIN", ",", "data1", ",", "discovery_update", ")" ]
[ 917, 0 ]
[ 925, 9 ]
python
en
['en', 'en', 'en']
True
test_discovery_broken
(hass, mqtt_mock, caplog)
Test handling of bad discovery message.
Test handling of bad discovery message.
async def test_discovery_broken(hass, mqtt_mock, caplog): """Test handling of bad discovery message.""" data1 = '{ "name": "Beer", "power_command_topic": "test_topic#" }' data2 = '{ "name": "Milk", "power_command_topic": "test_topic" }' await help_test_discovery_broken( hass, mqtt_mock, caplog, CLIMATE_DOMAIN, data1, data2 )
[ "async", "def", "test_discovery_broken", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "data1", "=", "'{ \"name\": \"Beer\", \"power_command_topic\": \"test_topic#\" }'", "data2", "=", "'{ \"name\": \"Milk\", \"power_command_topic\": \"test_topic\" }'", "await", "help_test_discovery_broken", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "CLIMATE_DOMAIN", ",", "data1", ",", "data2", ")" ]
[ 929, 0 ]
[ 935, 5 ]
python
en
['en', 'en', 'en']
True
test_entity_device_info_with_connection
(hass, mqtt_mock)
Test MQTT climate device registry integration.
Test MQTT climate device registry integration.
async def test_entity_device_info_with_connection(hass, mqtt_mock): """Test MQTT climate device registry integration.""" await help_test_entity_device_info_with_connection( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_device_info_with_connection", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_device_info_with_connection", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 938, 0 ]
[ 942, 5 ]
python
da
['it', 'da', 'en']
False
test_entity_device_info_with_identifier
(hass, mqtt_mock)
Test MQTT climate device registry integration.
Test MQTT climate device registry integration.
async def test_entity_device_info_with_identifier(hass, mqtt_mock): """Test MQTT climate device registry integration.""" await help_test_entity_device_info_with_identifier( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_device_info_with_identifier", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_device_info_with_identifier", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 945, 0 ]
[ 949, 5 ]
python
da
['it', 'da', 'en']
False
test_entity_device_info_update
(hass, mqtt_mock)
Test device registry update.
Test device registry update.
async def test_entity_device_info_update(hass, mqtt_mock): """Test device registry update.""" await help_test_entity_device_info_update( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_device_info_update", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_device_info_update", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 952, 0 ]
[ 956, 5 ]
python
en
['fr', 'fy', 'en']
False
test_entity_device_info_remove
(hass, mqtt_mock)
Test device registry remove.
Test device registry remove.
async def test_entity_device_info_remove(hass, mqtt_mock): """Test device registry remove.""" await help_test_entity_device_info_remove( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_device_info_remove", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_device_info_remove", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 959, 0 ]
[ 963, 5 ]
python
en
['fr', 'en', 'en']
True
test_entity_id_update_subscriptions
(hass, mqtt_mock)
Test MQTT subscriptions are managed when entity_id is updated.
Test MQTT subscriptions are managed when entity_id is updated.
async def test_entity_id_update_subscriptions(hass, mqtt_mock): """Test MQTT subscriptions are managed when entity_id is updated.""" config = { CLIMATE_DOMAIN: { "platform": "mqtt", "name": "test", "mode_state_topic": "test-topic", "availability_topic": "avty-topic", } } await help_test_entity_id_update_subscriptions( hass, mqtt_mock, CLIMATE_DOMAIN, config, ["test-topic", "avty-topic"] )
[ "async", "def", "test_entity_id_update_subscriptions", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "{", "CLIMATE_DOMAIN", ":", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"test\"", ",", "\"mode_state_topic\"", ":", "\"test-topic\"", ",", "\"availability_topic\"", ":", "\"avty-topic\"", ",", "}", "}", "await", "help_test_entity_id_update_subscriptions", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "config", ",", "[", "\"test-topic\"", ",", "\"avty-topic\"", "]", ")" ]
[ 966, 0 ]
[ 978, 5 ]
python
en
['en', 'en', 'en']
True
test_entity_id_update_discovery_update
(hass, mqtt_mock)
Test MQTT discovery update when entity_id is updated.
Test MQTT discovery update when entity_id is updated.
async def test_entity_id_update_discovery_update(hass, mqtt_mock): """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_id_update_discovery_update", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_id_update_discovery_update", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 981, 0 ]
[ 985, 5 ]
python
en
['en', 'en', 'en']
True
test_entity_debug_info_message
(hass, mqtt_mock)
Test MQTT debug info.
Test MQTT debug info.
async def test_entity_debug_info_message(hass, mqtt_mock): """Test MQTT debug info.""" config = { CLIMATE_DOMAIN: { "platform": "mqtt", "name": "test", "mode_state_topic": "test-topic", } } await help_test_entity_debug_info_message( hass, mqtt_mock, CLIMATE_DOMAIN, config, "test-topic" )
[ "async", "def", "test_entity_debug_info_message", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "{", "CLIMATE_DOMAIN", ":", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"test\"", ",", "\"mode_state_topic\"", ":", "\"test-topic\"", ",", "}", "}", "await", "help_test_entity_debug_info_message", "(", "hass", ",", "mqtt_mock", ",", "CLIMATE_DOMAIN", ",", "config", ",", "\"test-topic\"", ")" ]
[ 988, 0 ]
[ 999, 5 ]
python
es
['es', 'mt', 'it']
False
test_precision_default
(hass, mqtt_mock)
Test that setting precision to tenths works as intended.
Test that setting precision to tenths works as intended.
async def test_precision_default(hass, mqtt_mock): """Test that setting precision to tenths works as intended.""" assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG) await hass.async_block_till_done() await common.async_set_temperature( hass, temperature=23.67, entity_id=ENTITY_CLIMATE ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 23.7 mqtt_mock.async_publish.reset_mock()
[ "async", "def", "test_precision_default", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "DEFAULT_CONFIG", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "common", ".", "async_set_temperature", "(", "hass", ",", "temperature", "=", "23.67", ",", "entity_id", "=", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "23.7", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")" ]
[ 1002, 0 ]
[ 1012, 40 ]
python
en
['en', 'en', 'en']
True
test_precision_halves
(hass, mqtt_mock)
Test that setting precision to halves works as intended.
Test that setting precision to halves works as intended.
async def test_precision_halves(hass, mqtt_mock): """Test that setting precision to halves works as intended.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["precision"] = 0.5 assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() await common.async_set_temperature( hass, temperature=23.67, entity_id=ENTITY_CLIMATE ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 23.5 mqtt_mock.async_publish.reset_mock()
[ "async", "def", "test_precision_halves", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"precision\"", "]", "=", "0.5", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "common", ".", "async_set_temperature", "(", "hass", ",", "temperature", "=", "23.67", ",", "entity_id", "=", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "23.5", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")" ]
[ 1015, 0 ]
[ 1027, 40 ]
python
en
['en', 'en', 'en']
True
test_precision_whole
(hass, mqtt_mock)
Test that setting precision to whole works as intended.
Test that setting precision to whole works as intended.
async def test_precision_whole(hass, mqtt_mock): """Test that setting precision to whole works as intended.""" config = copy.deepcopy(DEFAULT_CONFIG) config["climate"]["precision"] = 1.0 assert await async_setup_component(hass, CLIMATE_DOMAIN, config) await hass.async_block_till_done() await common.async_set_temperature( hass, temperature=23.67, entity_id=ENTITY_CLIMATE ) state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 24.0 mqtt_mock.async_publish.reset_mock()
[ "async", "def", "test_precision_whole", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", ")", "config", "[", "\"climate\"", "]", "[", "\"precision\"", "]", "=", "1.0", "assert", "await", "async_setup_component", "(", "hass", ",", "CLIMATE_DOMAIN", ",", "config", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "common", ".", "async_set_temperature", "(", "hass", ",", "temperature", "=", "23.67", ",", "entity_id", "=", "ENTITY_CLIMATE", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "ENTITY_CLIMATE", ")", "assert", "state", ".", "attributes", ".", "get", "(", "\"temperature\"", ")", "==", "24.0", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")" ]
[ 1030, 0 ]
[ 1042, 40 ]
python
en
['en', 'en', 'en']
True
async_register_implementation
( hass: HomeAssistant, domain: str, implementation: AbstractOAuth2Implementation )
Register an OAuth2 flow implementation for an integration.
Register an OAuth2 flow implementation for an integration.
def async_register_implementation( hass: HomeAssistant, domain: str, implementation: AbstractOAuth2Implementation ) -> None: """Register an OAuth2 flow implementation for an integration.""" if isinstance(implementation, LocalOAuth2Implementation) and not hass.data.get( DATA_VIEW_REGISTERED, False ): hass.http.register_view(OAuth2AuthorizeCallbackView()) # type: ignore hass.data[DATA_VIEW_REGISTERED] = True implementations = hass.data.setdefault(DATA_IMPLEMENTATIONS, {}) implementations.setdefault(domain, {})[implementation.domain] = implementation
[ "def", "async_register_implementation", "(", "hass", ":", "HomeAssistant", ",", "domain", ":", "str", ",", "implementation", ":", "AbstractOAuth2Implementation", ")", "->", "None", ":", "if", "isinstance", "(", "implementation", ",", "LocalOAuth2Implementation", ")", "and", "not", "hass", ".", "data", ".", "get", "(", "DATA_VIEW_REGISTERED", ",", "False", ")", ":", "hass", ".", "http", ".", "register_view", "(", "OAuth2AuthorizeCallbackView", "(", ")", ")", "# type: ignore", "hass", ".", "data", "[", "DATA_VIEW_REGISTERED", "]", "=", "True", "implementations", "=", "hass", ".", "data", ".", "setdefault", "(", "DATA_IMPLEMENTATIONS", ",", "{", "}", ")", "implementations", ".", "setdefault", "(", "domain", ",", "{", "}", ")", "[", "implementation", ".", "domain", "]", "=", "implementation" ]
[ 320, 0 ]
[ 331, 82 ]
python
en
['en', 'en', 'en']
True
async_get_implementations
( hass: HomeAssistant, domain: str )
Return OAuth2 implementations for specified domain.
Return OAuth2 implementations for specified domain.
async def async_get_implementations( hass: HomeAssistant, domain: str ) -> Dict[str, AbstractOAuth2Implementation]: """Return OAuth2 implementations for specified domain.""" registered = cast( Dict[str, AbstractOAuth2Implementation], hass.data.setdefault(DATA_IMPLEMENTATIONS, {}).get(domain, {}), ) if DATA_PROVIDERS not in hass.data: return registered registered = dict(registered) for provider_domain, get_impl in hass.data[DATA_PROVIDERS].items(): implementation = await get_impl(hass, domain) if implementation is not None: registered[provider_domain] = implementation return registered
[ "async", "def", "async_get_implementations", "(", "hass", ":", "HomeAssistant", ",", "domain", ":", "str", ")", "->", "Dict", "[", "str", ",", "AbstractOAuth2Implementation", "]", ":", "registered", "=", "cast", "(", "Dict", "[", "str", ",", "AbstractOAuth2Implementation", "]", ",", "hass", ".", "data", ".", "setdefault", "(", "DATA_IMPLEMENTATIONS", ",", "{", "}", ")", ".", "get", "(", "domain", ",", "{", "}", ")", ",", ")", "if", "DATA_PROVIDERS", "not", "in", "hass", ".", "data", ":", "return", "registered", "registered", "=", "dict", "(", "registered", ")", "for", "provider_domain", ",", "get_impl", "in", "hass", ".", "data", "[", "DATA_PROVIDERS", "]", ".", "items", "(", ")", ":", "implementation", "=", "await", "get_impl", "(", "hass", ",", "domain", ")", "if", "implementation", "is", "not", "None", ":", "registered", "[", "provider_domain", "]", "=", "implementation", "return", "registered" ]
[ 334, 0 ]
[ 353, 21 ]
python
en
['en', 'en', 'en']
True
async_get_config_entry_implementation
( hass: HomeAssistant, config_entry: config_entries.ConfigEntry )
Return the implementation for this config entry.
Return the implementation for this config entry.
async def async_get_config_entry_implementation( hass: HomeAssistant, config_entry: config_entries.ConfigEntry ) -> AbstractOAuth2Implementation: """Return the implementation for this config entry.""" implementations = await async_get_implementations(hass, config_entry.domain) implementation = implementations.get(config_entry.data["auth_implementation"]) if implementation is None: raise ValueError("Implementation not available") return implementation
[ "async", "def", "async_get_config_entry_implementation", "(", "hass", ":", "HomeAssistant", ",", "config_entry", ":", "config_entries", ".", "ConfigEntry", ")", "->", "AbstractOAuth2Implementation", ":", "implementations", "=", "await", "async_get_implementations", "(", "hass", ",", "config_entry", ".", "domain", ")", "implementation", "=", "implementations", ".", "get", "(", "config_entry", ".", "data", "[", "\"auth_implementation\"", "]", ")", "if", "implementation", "is", "None", ":", "raise", "ValueError", "(", "\"Implementation not available\"", ")", "return", "implementation" ]
[ 356, 0 ]
[ 366, 25 ]
python
en
['en', 'en', 'en']
True
async_add_implementation_provider
( hass: HomeAssistant, provider_domain: str, async_provide_implementation: Callable[ [HomeAssistant, str], Awaitable[Optional[AbstractOAuth2Implementation]] ], )
Add an implementation provider. If no implementation found, return None.
Add an implementation provider.
def async_add_implementation_provider( hass: HomeAssistant, provider_domain: str, async_provide_implementation: Callable[ [HomeAssistant, str], Awaitable[Optional[AbstractOAuth2Implementation]] ], ) -> None: """Add an implementation provider. If no implementation found, return None. """ hass.data.setdefault(DATA_PROVIDERS, {})[ provider_domain ] = async_provide_implementation
[ "def", "async_add_implementation_provider", "(", "hass", ":", "HomeAssistant", ",", "provider_domain", ":", "str", ",", "async_provide_implementation", ":", "Callable", "[", "[", "HomeAssistant", ",", "str", "]", ",", "Awaitable", "[", "Optional", "[", "AbstractOAuth2Implementation", "]", "]", "]", ",", ")", "->", "None", ":", "hass", ".", "data", ".", "setdefault", "(", "DATA_PROVIDERS", ",", "{", "}", ")", "[", "provider_domain", "]", "=", "async_provide_implementation" ]
[ 370, 0 ]
[ 383, 36 ]
python
en
['en', 'en', 'en']
True
async_oauth2_request
( hass: HomeAssistant, token: dict, method: str, url: str, **kwargs: Any )
Make an OAuth2 authenticated request. This method will not refresh tokens. Use OAuth2 session for that.
Make an OAuth2 authenticated request.
async def async_oauth2_request( hass: HomeAssistant, token: dict, method: str, url: str, **kwargs: Any ) -> client.ClientResponse: """Make an OAuth2 authenticated request. This method will not refresh tokens. Use OAuth2 session for that. """ session = async_get_clientsession(hass) return await session.request( method, url, **kwargs, headers={ **(kwargs.get("headers") or {}), "authorization": f"Bearer {token['access_token']}", }, )
[ "async", "def", "async_oauth2_request", "(", "hass", ":", "HomeAssistant", ",", "token", ":", "dict", ",", "method", ":", "str", ",", "url", ":", "str", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "client", ".", "ClientResponse", ":", "session", "=", "async_get_clientsession", "(", "hass", ")", "return", "await", "session", ".", "request", "(", "method", ",", "url", ",", "*", "*", "kwargs", ",", "headers", "=", "{", "*", "*", "(", "kwargs", ".", "get", "(", "\"headers\"", ")", "or", "{", "}", ")", ",", "\"authorization\"", ":", "f\"Bearer {token['access_token']}\"", ",", "}", ",", ")" ]
[ 465, 0 ]
[ 482, 5 ]
python
en
['en', 'en', 'en']
True
_encode_jwt
(hass: HomeAssistant, data: dict)
JWT encode data.
JWT encode data.
def _encode_jwt(hass: HomeAssistant, data: dict) -> str: """JWT encode data.""" secret = hass.data.get(DATA_JWT_SECRET) if secret is None: secret = hass.data[DATA_JWT_SECRET] = secrets.token_hex() return jwt.encode(data, secret, algorithm="HS256").decode()
[ "def", "_encode_jwt", "(", "hass", ":", "HomeAssistant", ",", "data", ":", "dict", ")", "->", "str", ":", "secret", "=", "hass", ".", "data", ".", "get", "(", "DATA_JWT_SECRET", ")", "if", "secret", "is", "None", ":", "secret", "=", "hass", ".", "data", "[", "DATA_JWT_SECRET", "]", "=", "secrets", ".", "token_hex", "(", ")", "return", "jwt", ".", "encode", "(", "data", ",", "secret", ",", "algorithm", "=", "\"HS256\"", ")", ".", "decode", "(", ")" ]
[ 486, 0 ]
[ 493, 63 ]
python
fr
['fr', 'id', 'nl']
False
_decode_jwt
(hass: HomeAssistant, encoded: str)
JWT encode data.
JWT encode data.
def _decode_jwt(hass: HomeAssistant, encoded: str) -> Optional[dict]: """JWT encode data.""" secret = cast(str, hass.data.get(DATA_JWT_SECRET)) try: return jwt.decode(encoded, secret, algorithms=["HS256"]) except jwt.InvalidTokenError: return None
[ "def", "_decode_jwt", "(", "hass", ":", "HomeAssistant", ",", "encoded", ":", "str", ")", "->", "Optional", "[", "dict", "]", ":", "secret", "=", "cast", "(", "str", ",", "hass", ".", "data", ".", "get", "(", "DATA_JWT_SECRET", ")", ")", "try", ":", "return", "jwt", ".", "decode", "(", "encoded", ",", "secret", ",", "algorithms", "=", "[", "\"HS256\"", "]", ")", "except", "jwt", ".", "InvalidTokenError", ":", "return", "None" ]
[ 497, 0 ]
[ 504, 19 ]
python
fr
['fr', 'id', 'nl']
False
AbstractOAuth2Implementation.name
(self)
Name of the implementation.
Name of the implementation.
def name(self) -> str: """Name of the implementation."""
[ "def", "name", "(", "self", ")", "->", "str", ":" ]
[ 43, 4 ]
[ 44, 41 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2Implementation.domain
(self)
Domain that is providing the implementation.
Domain that is providing the implementation.
def domain(self) -> str: """Domain that is providing the implementation."""
[ "def", "domain", "(", "self", ")", "->", "str", ":" ]
[ 48, 4 ]
[ 49, 58 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2Implementation.async_generate_authorize_url
(self, flow_id: str)
Generate a url for the user to authorize. This step is called when a config flow is initialized. It should redirect the user to the vendor website where they can authorize Home Assistant. The implementation is responsible to get notified when the user is authorized and pass this to the specified config flow. Do as little work as possible once notified. You can do the work inside async_resolve_external_data. This will give the best UX. Pass external data in with: await hass.config_entries.flow.async_configure( flow_id=flow_id, user_input=external_data )
Generate a url for the user to authorize.
async def async_generate_authorize_url(self, flow_id: str) -> str: """Generate a url for the user to authorize. This step is called when a config flow is initialized. It should redirect the user to the vendor website where they can authorize Home Assistant. The implementation is responsible to get notified when the user is authorized and pass this to the specified config flow. Do as little work as possible once notified. You can do the work inside async_resolve_external_data. This will give the best UX. Pass external data in with: await hass.config_entries.flow.async_configure( flow_id=flow_id, user_input=external_data ) """
[ "async", "def", "async_generate_authorize_url", "(", "self", ",", "flow_id", ":", "str", ")", "->", "str", ":" ]
[ 52, 4 ]
[ 69, 11 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2Implementation.async_resolve_external_data
(self, external_data: Any)
Resolve external data to tokens. Turn the data that the implementation passed to the config flow as external step data into tokens. These tokens will be stored as 'token' in the config entry data.
Resolve external data to tokens.
async def async_resolve_external_data(self, external_data: Any) -> dict: """Resolve external data to tokens. Turn the data that the implementation passed to the config flow as external step data into tokens. These tokens will be stored as 'token' in the config entry data. """
[ "async", "def", "async_resolve_external_data", "(", "self", ",", "external_data", ":", "Any", ")", "->", "dict", ":" ]
[ 72, 4 ]
[ 78, 11 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2Implementation.async_refresh_token
(self, token: dict)
Refresh a token and update expires info.
Refresh a token and update expires info.
async def async_refresh_token(self, token: dict) -> dict: """Refresh a token and update expires info.""" new_token = await self._async_refresh_token(token) # Force int for non-compliant oauth2 providers new_token["expires_in"] = int(new_token["expires_in"]) new_token["expires_at"] = time.time() + new_token["expires_in"] return new_token
[ "async", "def", "async_refresh_token", "(", "self", ",", "token", ":", "dict", ")", "->", "dict", ":", "new_token", "=", "await", "self", ".", "_async_refresh_token", "(", "token", ")", "# Force int for non-compliant oauth2 providers", "new_token", "[", "\"expires_in\"", "]", "=", "int", "(", "new_token", "[", "\"expires_in\"", "]", ")", "new_token", "[", "\"expires_at\"", "]", "=", "time", ".", "time", "(", ")", "+", "new_token", "[", "\"expires_in\"", "]", "return", "new_token" ]
[ 80, 4 ]
[ 86, 24 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2Implementation._async_refresh_token
(self, token: dict)
Refresh a token.
Refresh a token.
async def _async_refresh_token(self, token: dict) -> dict: """Refresh a token."""
[ "async", "def", "_async_refresh_token", "(", "self", ",", "token", ":", "dict", ")", "->", "dict", ":" ]
[ 89, 4 ]
[ 90, 30 ]
python
en
['en', 'gl', 'en']
True
LocalOAuth2Implementation.__init__
( self, hass: HomeAssistant, domain: str, client_id: str, client_secret: str, authorize_url: str, token_url: str, )
Initialize local auth implementation.
Initialize local auth implementation.
def __init__( self, hass: HomeAssistant, domain: str, client_id: str, client_secret: str, authorize_url: str, token_url: str, ): """Initialize local auth implementation.""" self.hass = hass self._domain = domain self.client_id = client_id self.client_secret = client_secret self.authorize_url = authorize_url self.token_url = token_url
[ "def", "__init__", "(", "self", ",", "hass", ":", "HomeAssistant", ",", "domain", ":", "str", ",", "client_id", ":", "str", ",", "client_secret", ":", "str", ",", "authorize_url", ":", "str", ",", "token_url", ":", "str", ",", ")", ":", "self", ".", "hass", "=", "hass", "self", ".", "_domain", "=", "domain", "self", ".", "client_id", "=", "client_id", "self", ".", "client_secret", "=", "client_secret", "self", ".", "authorize_url", "=", "authorize_url", "self", ".", "token_url", "=", "token_url" ]
[ 96, 4 ]
[ 111, 34 ]
python
en
['en', 'en', 'en']
True
LocalOAuth2Implementation.name
(self)
Name of the implementation.
Name of the implementation.
def name(self) -> str: """Name of the implementation.""" return "Configuration.yaml"
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "\"Configuration.yaml\"" ]
[ 114, 4 ]
[ 116, 35 ]
python
en
['en', 'en', 'en']
True
LocalOAuth2Implementation.domain
(self)
Domain providing the implementation.
Domain providing the implementation.
def domain(self) -> str: """Domain providing the implementation.""" return self._domain
[ "def", "domain", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_domain" ]
[ 119, 4 ]
[ 121, 27 ]
python
en
['en', 'en', 'en']
True
LocalOAuth2Implementation.redirect_uri
(self)
Return the redirect uri.
Return the redirect uri.
def redirect_uri(self) -> str: """Return the redirect uri.""" return f"{get_url(self.hass, require_current_request=True)}{AUTH_CALLBACK_PATH}"
[ "def", "redirect_uri", "(", "self", ")", "->", "str", ":", "return", "f\"{get_url(self.hass, require_current_request=True)}{AUTH_CALLBACK_PATH}\"" ]
[ 124, 4 ]
[ 126, 88 ]
python
en
['en', 'hr', 'en']
True
LocalOAuth2Implementation.extra_authorize_data
(self)
Extra data that needs to be appended to the authorize url.
Extra data that needs to be appended to the authorize url.
def extra_authorize_data(self) -> dict: """Extra data that needs to be appended to the authorize url.""" return {}
[ "def", "extra_authorize_data", "(", "self", ")", "->", "dict", ":", "return", "{", "}" ]
[ 129, 4 ]
[ 131, 17 ]
python
en
['en', 'en', 'en']
True
LocalOAuth2Implementation.async_generate_authorize_url
(self, flow_id: str)
Generate a url for the user to authorize.
Generate a url for the user to authorize.
async def async_generate_authorize_url(self, flow_id: str) -> str: """Generate a url for the user to authorize.""" return str( URL(self.authorize_url) .with_query( { "response_type": "code", "client_id": self.client_id, "redirect_uri": self.redirect_uri, "state": _encode_jwt(self.hass, {"flow_id": flow_id}), } ) .update_query(self.extra_authorize_data) )
[ "async", "def", "async_generate_authorize_url", "(", "self", ",", "flow_id", ":", "str", ")", "->", "str", ":", "return", "str", "(", "URL", "(", "self", ".", "authorize_url", ")", ".", "with_query", "(", "{", "\"response_type\"", ":", "\"code\"", ",", "\"client_id\"", ":", "self", ".", "client_id", ",", "\"redirect_uri\"", ":", "self", ".", "redirect_uri", ",", "\"state\"", ":", "_encode_jwt", "(", "self", ".", "hass", ",", "{", "\"flow_id\"", ":", "flow_id", "}", ")", ",", "}", ")", ".", "update_query", "(", "self", ".", "extra_authorize_data", ")", ")" ]
[ 133, 4 ]
[ 146, 9 ]
python
en
['en', 'en', 'en']
True
LocalOAuth2Implementation.async_resolve_external_data
(self, external_data: Any)
Resolve the authorization code to tokens.
Resolve the authorization code to tokens.
async def async_resolve_external_data(self, external_data: Any) -> dict: """Resolve the authorization code to tokens.""" return await self._token_request( { "grant_type": "authorization_code", "code": external_data, "redirect_uri": self.redirect_uri, } )
[ "async", "def", "async_resolve_external_data", "(", "self", ",", "external_data", ":", "Any", ")", "->", "dict", ":", "return", "await", "self", ".", "_token_request", "(", "{", "\"grant_type\"", ":", "\"authorization_code\"", ",", "\"code\"", ":", "external_data", ",", "\"redirect_uri\"", ":", "self", ".", "redirect_uri", ",", "}", ")" ]
[ 148, 4 ]
[ 156, 9 ]
python
en
['en', 'en', 'en']
True
LocalOAuth2Implementation._async_refresh_token
(self, token: dict)
Refresh tokens.
Refresh tokens.
async def _async_refresh_token(self, token: dict) -> dict: """Refresh tokens.""" new_token = await self._token_request( { "grant_type": "refresh_token", "client_id": self.client_id, "refresh_token": token["refresh_token"], } ) return {**token, **new_token}
[ "async", "def", "_async_refresh_token", "(", "self", ",", "token", ":", "dict", ")", "->", "dict", ":", "new_token", "=", "await", "self", ".", "_token_request", "(", "{", "\"grant_type\"", ":", "\"refresh_token\"", ",", "\"client_id\"", ":", "self", ".", "client_id", ",", "\"refresh_token\"", ":", "token", "[", "\"refresh_token\"", "]", ",", "}", ")", "return", "{", "*", "*", "token", ",", "*", "*", "new_token", "}" ]
[ 158, 4 ]
[ 167, 37 ]
python
en
['en', 'en', 'en']
False
LocalOAuth2Implementation._token_request
(self, data: dict)
Make a token request.
Make a token request.
async def _token_request(self, data: dict) -> dict: """Make a token request.""" session = async_get_clientsession(self.hass) data["client_id"] = self.client_id if self.client_secret is not None: data["client_secret"] = self.client_secret resp = await session.post(self.token_url, data=data) resp.raise_for_status() return cast(dict, await resp.json())
[ "async", "def", "_token_request", "(", "self", ",", "data", ":", "dict", ")", "->", "dict", ":", "session", "=", "async_get_clientsession", "(", "self", ".", "hass", ")", "data", "[", "\"client_id\"", "]", "=", "self", ".", "client_id", "if", "self", ".", "client_secret", "is", "not", "None", ":", "data", "[", "\"client_secret\"", "]", "=", "self", ".", "client_secret", "resp", "=", "await", "session", ".", "post", "(", "self", ".", "token_url", ",", "data", "=", "data", ")", "resp", ".", "raise_for_status", "(", ")", "return", "cast", "(", "dict", ",", "await", "resp", ".", "json", "(", ")", ")" ]
[ 169, 4 ]
[ 180, 44 ]
python
en
['en', 'de', 'en']
True
AbstractOAuth2FlowHandler.__init__
(self)
Instantiate config flow.
Instantiate config flow.
def __init__(self) -> None: """Instantiate config flow.""" if self.DOMAIN == "": raise TypeError( f"Can't instantiate class {self.__class__.__name__} without DOMAIN being set" ) self.external_data: Any = None self.flow_impl: AbstractOAuth2Implementation = None
[ "def", "__init__", "(", "self", ")", "->", "None", ":", "if", "self", ".", "DOMAIN", "==", "\"\"", ":", "raise", "TypeError", "(", "f\"Can't instantiate class {self.__class__.__name__} without DOMAIN being set\"", ")", "self", ".", "external_data", ":", "Any", "=", "None", "self", ".", "flow_impl", ":", "AbstractOAuth2Implementation", "=", "None" ]
[ 191, 4 ]
[ 199, 59 ]
python
en
['en', 'nl', 'en']
True
AbstractOAuth2FlowHandler.logger
(self)
Return logger.
Return logger.
def logger(self) -> logging.Logger: """Return logger."""
[ "def", "logger", "(", "self", ")", "->", "logging", ".", "Logger", ":" ]
[ 203, 4 ]
[ 204, 28 ]
python
en
['es', 'no', 'en']
False
AbstractOAuth2FlowHandler.extra_authorize_data
(self)
Extra data that needs to be appended to the authorize url.
Extra data that needs to be appended to the authorize url.
def extra_authorize_data(self) -> dict: """Extra data that needs to be appended to the authorize url.""" return {}
[ "def", "extra_authorize_data", "(", "self", ")", "->", "dict", ":", "return", "{", "}" ]
[ 207, 4 ]
[ 209, 17 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2FlowHandler.async_step_pick_implementation
( self, user_input: Optional[dict] = None )
Handle a flow start.
Handle a flow start.
async def async_step_pick_implementation( self, user_input: Optional[dict] = None ) -> dict: """Handle a flow start.""" assert self.hass implementations = await async_get_implementations(self.hass, self.DOMAIN) if user_input is not None: self.flow_impl = implementations[user_input["implementation"]] return await self.async_step_auth() if not implementations: return self.async_abort(reason="missing_configuration") if len(implementations) == 1: # Pick first implementation as we have only one. self.flow_impl = list(implementations.values())[0] return await self.async_step_auth() return self.async_show_form( step_id="pick_implementation", data_schema=vol.Schema( { vol.Required( "implementation", default=list(implementations)[0] ): vol.In({key: impl.name for key, impl in implementations.items()}) } ), )
[ "async", "def", "async_step_pick_implementation", "(", "self", ",", "user_input", ":", "Optional", "[", "dict", "]", "=", "None", ")", "->", "dict", ":", "assert", "self", ".", "hass", "implementations", "=", "await", "async_get_implementations", "(", "self", ".", "hass", ",", "self", ".", "DOMAIN", ")", "if", "user_input", "is", "not", "None", ":", "self", ".", "flow_impl", "=", "implementations", "[", "user_input", "[", "\"implementation\"", "]", "]", "return", "await", "self", ".", "async_step_auth", "(", ")", "if", "not", "implementations", ":", "return", "self", ".", "async_abort", "(", "reason", "=", "\"missing_configuration\"", ")", "if", "len", "(", "implementations", ")", "==", "1", ":", "# Pick first implementation as we have only one.", "self", ".", "flow_impl", "=", "list", "(", "implementations", ".", "values", "(", ")", ")", "[", "0", "]", "return", "await", "self", ".", "async_step_auth", "(", ")", "return", "self", ".", "async_show_form", "(", "step_id", "=", "\"pick_implementation\"", ",", "data_schema", "=", "vol", ".", "Schema", "(", "{", "vol", ".", "Required", "(", "\"implementation\"", ",", "default", "=", "list", "(", "implementations", ")", "[", "0", "]", ")", ":", "vol", ".", "In", "(", "{", "key", ":", "impl", ".", "name", "for", "key", ",", "impl", "in", "implementations", ".", "items", "(", ")", "}", ")", "}", ")", ",", ")" ]
[ 211, 4 ]
[ 239, 9 ]
python
en
['en', 'lb', 'en']
True
AbstractOAuth2FlowHandler.async_step_auth
( self, user_input: Optional[Dict[str, Any]] = None )
Create an entry for auth.
Create an entry for auth.
async def async_step_auth( self, user_input: Optional[Dict[str, Any]] = None ) -> Dict[str, Any]: """Create an entry for auth.""" # Flow has been triggered by external data if user_input: self.external_data = user_input return self.async_external_step_done(next_step_id="creation") try: with async_timeout.timeout(10): url = await self.flow_impl.async_generate_authorize_url(self.flow_id) except asyncio.TimeoutError: return self.async_abort(reason="authorize_url_timeout") except NoURLAvailableError: return self.async_abort( reason="no_url_available", description_placeholders={ "docs_url": "https://www.home-assistant.io/more-info/no-url-available" }, ) url = str(URL(url).update_query(self.extra_authorize_data)) return self.async_external_step(step_id="auth", url=url)
[ "async", "def", "async_step_auth", "(", "self", ",", "user_input", ":", "Optional", "[", "Dict", "[", "str", ",", "Any", "]", "]", "=", "None", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "# Flow has been triggered by external data", "if", "user_input", ":", "self", ".", "external_data", "=", "user_input", "return", "self", ".", "async_external_step_done", "(", "next_step_id", "=", "\"creation\"", ")", "try", ":", "with", "async_timeout", ".", "timeout", "(", "10", ")", ":", "url", "=", "await", "self", ".", "flow_impl", ".", "async_generate_authorize_url", "(", "self", ".", "flow_id", ")", "except", "asyncio", ".", "TimeoutError", ":", "return", "self", ".", "async_abort", "(", "reason", "=", "\"authorize_url_timeout\"", ")", "except", "NoURLAvailableError", ":", "return", "self", ".", "async_abort", "(", "reason", "=", "\"no_url_available\"", ",", "description_placeholders", "=", "{", "\"docs_url\"", ":", "\"https://www.home-assistant.io/more-info/no-url-available\"", "}", ",", ")", "url", "=", "str", "(", "URL", "(", "url", ")", ".", "update_query", "(", "self", ".", "extra_authorize_data", ")", ")", "return", "self", ".", "async_external_step", "(", "step_id", "=", "\"auth\"", ",", "url", "=", "url", ")" ]
[ 241, 4 ]
[ 265, 64 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2FlowHandler.async_step_creation
( self, user_input: Optional[Dict[str, Any]] = None )
Create config entry from external data.
Create config entry from external data.
async def async_step_creation( self, user_input: Optional[Dict[str, Any]] = None ) -> Dict[str, Any]: """Create config entry from external data.""" token = await self.flow_impl.async_resolve_external_data(self.external_data) # Force int for non-compliant oauth2 providers try: token["expires_in"] = int(token["expires_in"]) except ValueError as err: _LOGGER.warning("Error converting expires_in to int: %s", err) return self.async_abort(reason="oauth_error") token["expires_at"] = time.time() + token["expires_in"] self.logger.info("Successfully authenticated") return await self.async_oauth_create_entry( {"auth_implementation": self.flow_impl.domain, "token": token} )
[ "async", "def", "async_step_creation", "(", "self", ",", "user_input", ":", "Optional", "[", "Dict", "[", "str", ",", "Any", "]", "]", "=", "None", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "token", "=", "await", "self", ".", "flow_impl", ".", "async_resolve_external_data", "(", "self", ".", "external_data", ")", "# Force int for non-compliant oauth2 providers", "try", ":", "token", "[", "\"expires_in\"", "]", "=", "int", "(", "token", "[", "\"expires_in\"", "]", ")", "except", "ValueError", "as", "err", ":", "_LOGGER", ".", "warning", "(", "\"Error converting expires_in to int: %s\"", ",", "err", ")", "return", "self", ".", "async_abort", "(", "reason", "=", "\"oauth_error\"", ")", "token", "[", "\"expires_at\"", "]", "=", "time", ".", "time", "(", ")", "+", "token", "[", "\"expires_in\"", "]", "self", ".", "logger", ".", "info", "(", "\"Successfully authenticated\"", ")", "return", "await", "self", ".", "async_oauth_create_entry", "(", "{", "\"auth_implementation\"", ":", "self", ".", "flow_impl", ".", "domain", ",", "\"token\"", ":", "token", "}", ")" ]
[ 267, 4 ]
[ 284, 9 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2FlowHandler.async_oauth_create_entry
(self, data: dict)
Create an entry for the flow. Ok to override if you want to fetch extra info or even add another step.
Create an entry for the flow.
async def async_oauth_create_entry(self, data: dict) -> dict: """Create an entry for the flow. Ok to override if you want to fetch extra info or even add another step. """ return self.async_create_entry(title=self.flow_impl.name, data=data)
[ "async", "def", "async_oauth_create_entry", "(", "self", ",", "data", ":", "dict", ")", "->", "dict", ":", "return", "self", ".", "async_create_entry", "(", "title", "=", "self", ".", "flow_impl", ".", "name", ",", "data", "=", "data", ")" ]
[ 286, 4 ]
[ 291, 76 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2FlowHandler.async_step_discovery
( self, discovery_info: Dict[str, Any] )
Handle a flow initialized by discovery.
Handle a flow initialized by discovery.
async def async_step_discovery( self, discovery_info: Dict[str, Any] ) -> Dict[str, Any]: """Handle a flow initialized by discovery.""" await self.async_set_unique_id(self.DOMAIN) assert self.hass is not None if self.hass.config_entries.async_entries(self.DOMAIN): return self.async_abort(reason="already_configured") return await self.async_step_pick_implementation()
[ "async", "def", "async_step_discovery", "(", "self", ",", "discovery_info", ":", "Dict", "[", "str", ",", "Any", "]", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "await", "self", ".", "async_set_unique_id", "(", "self", ".", "DOMAIN", ")", "assert", "self", ".", "hass", "is", "not", "None", "if", "self", ".", "hass", ".", "config_entries", ".", "async_entries", "(", "self", ".", "DOMAIN", ")", ":", "return", "self", ".", "async_abort", "(", "reason", "=", "\"already_configured\"", ")", "return", "await", "self", ".", "async_step_pick_implementation", "(", ")" ]
[ 293, 4 ]
[ 303, 58 ]
python
en
['en', 'en', 'en']
True
AbstractOAuth2FlowHandler.async_register_implementation
( cls, hass: HomeAssistant, local_impl: LocalOAuth2Implementation )
Register a local implementation.
Register a local implementation.
def async_register_implementation( cls, hass: HomeAssistant, local_impl: LocalOAuth2Implementation ) -> None: """Register a local implementation.""" async_register_implementation(hass, cls.DOMAIN, local_impl)
[ "def", "async_register_implementation", "(", "cls", ",", "hass", ":", "HomeAssistant", ",", "local_impl", ":", "LocalOAuth2Implementation", ")", "->", "None", ":", "async_register_implementation", "(", "hass", ",", "cls", ".", "DOMAIN", ",", "local_impl", ")" ]
[ 312, 4 ]
[ 316, 67 ]
python
en
['en', 'en', 'en']
True
OAuth2AuthorizeCallbackView.get
(self, request: web.Request)
Receive authorization code.
Receive authorization code.
async def get(self, request: web.Request) -> web.Response: """Receive authorization code.""" if "code" not in request.query or "state" not in request.query: return web.Response( text=f"Missing code or state parameter in {request.url}" ) hass = request.app["hass"] state = _decode_jwt(hass, request.query["state"]) if state is None: return web.Response(text="Invalid state") await hass.config_entries.flow.async_configure( flow_id=state["flow_id"], user_input=request.query["code"] ) return web.Response( headers={"content-type": "text/html"}, text="<script>window.close()</script>", )
[ "async", "def", "get", "(", "self", ",", "request", ":", "web", ".", "Request", ")", "->", "web", ".", "Response", ":", "if", "\"code\"", "not", "in", "request", ".", "query", "or", "\"state\"", "not", "in", "request", ".", "query", ":", "return", "web", ".", "Response", "(", "text", "=", "f\"Missing code or state parameter in {request.url}\"", ")", "hass", "=", "request", ".", "app", "[", "\"hass\"", "]", "state", "=", "_decode_jwt", "(", "hass", ",", "request", ".", "query", "[", "\"state\"", "]", ")", "if", "state", "is", "None", ":", "return", "web", ".", "Response", "(", "text", "=", "\"Invalid state\"", ")", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "flow_id", "=", "state", "[", "\"flow_id\"", "]", ",", "user_input", "=", "request", ".", "query", "[", "\"code\"", "]", ")", "return", "web", ".", "Response", "(", "headers", "=", "{", "\"content-type\"", ":", "\"text/html\"", "}", ",", "text", "=", "\"<script>window.close()</script>\"", ",", ")" ]
[ 393, 4 ]
[ 414, 9 ]
python
de
['de', 'sr', 'en']
False
OAuth2Session.__init__
( self, hass: HomeAssistant, config_entry: config_entries.ConfigEntry, implementation: AbstractOAuth2Implementation, )
Initialize an OAuth2 session.
Initialize an OAuth2 session.
def __init__( self, hass: HomeAssistant, config_entry: config_entries.ConfigEntry, implementation: AbstractOAuth2Implementation, ): """Initialize an OAuth2 session.""" self.hass = hass self.config_entry = config_entry self.implementation = implementation
[ "def", "__init__", "(", "self", ",", "hass", ":", "HomeAssistant", ",", "config_entry", ":", "config_entries", ".", "ConfigEntry", ",", "implementation", ":", "AbstractOAuth2Implementation", ",", ")", ":", "self", ".", "hass", "=", "hass", "self", ".", "config_entry", "=", "config_entry", "self", ".", "implementation", "=", "implementation" ]
[ 420, 4 ]
[ 429, 44 ]
python
en
['en', 'en', 'en']
True
OAuth2Session.token
(self)
Return the token.
Return the token.
def token(self) -> dict: """Return the token.""" return cast(dict, self.config_entry.data["token"])
[ "def", "token", "(", "self", ")", "->", "dict", ":", "return", "cast", "(", "dict", ",", "self", ".", "config_entry", ".", "data", "[", "\"token\"", "]", ")" ]
[ 432, 4 ]
[ 434, 58 ]
python
en
['en', 'no', 'en']
True
OAuth2Session.valid_token
(self)
Return if token is still valid.
Return if token is still valid.
def valid_token(self) -> bool: """Return if token is still valid.""" return ( cast(float, self.token["expires_at"]) > time.time() + CLOCK_OUT_OF_SYNC_MAX_SEC )
[ "def", "valid_token", "(", "self", ")", "->", "bool", ":", "return", "(", "cast", "(", "float", ",", "self", ".", "token", "[", "\"expires_at\"", "]", ")", ">", "time", ".", "time", "(", ")", "+", "CLOCK_OUT_OF_SYNC_MAX_SEC", ")" ]
[ 437, 4 ]
[ 442, 9 ]
python
en
['en', 'sv', 'en']
True
OAuth2Session.async_ensure_token_valid
(self)
Ensure that the current token is valid.
Ensure that the current token is valid.
async def async_ensure_token_valid(self) -> None: """Ensure that the current token is valid.""" if self.valid_token: return new_token = await self.implementation.async_refresh_token(self.token) self.hass.config_entries.async_update_entry( self.config_entry, data={**self.config_entry.data, "token": new_token} )
[ "async", "def", "async_ensure_token_valid", "(", "self", ")", "->", "None", ":", "if", "self", ".", "valid_token", ":", "return", "new_token", "=", "await", "self", ".", "implementation", ".", "async_refresh_token", "(", "self", ".", "token", ")", "self", ".", "hass", ".", "config_entries", ".", "async_update_entry", "(", "self", ".", "config_entry", ",", "data", "=", "{", "*", "*", "self", ".", "config_entry", ".", "data", ",", "\"token\"", ":", "new_token", "}", ")" ]
[ 444, 4 ]
[ 453, 9 ]
python
en
['en', 'en', 'en']
True
OAuth2Session.async_request
( self, method: str, url: str, **kwargs: Any )
Make a request.
Make a request.
async def async_request( self, method: str, url: str, **kwargs: Any ) -> client.ClientResponse: """Make a request.""" await self.async_ensure_token_valid() return await async_oauth2_request( self.hass, self.config_entry.data["token"], method, url, **kwargs )
[ "async", "def", "async_request", "(", "self", ",", "method", ":", "str", ",", "url", ":", "str", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "client", ".", "ClientResponse", ":", "await", "self", ".", "async_ensure_token_valid", "(", ")", "return", "await", "async_oauth2_request", "(", "self", ".", "hass", ",", "self", ".", "config_entry", ".", "data", "[", "\"token\"", "]", ",", "method", ",", "url", ",", "*", "*", "kwargs", ")" ]
[ 455, 4 ]
[ 462, 9 ]
python
en
['en', 'co', 'en']
True
WLEDFlowHandler.async_step_user
( self, user_input: Optional[ConfigType] = None )
Handle a flow initiated by the user.
Handle a flow initiated by the user.
async def async_step_user( self, user_input: Optional[ConfigType] = None ) -> Dict[str, Any]: """Handle a flow initiated by the user.""" return await self._handle_config_flow(user_input)
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", ":", "Optional", "[", "ConfigType", "]", "=", "None", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "return", "await", "self", ".", "_handle_config_flow", "(", "user_input", ")" ]
[ 24, 4 ]
[ 28, 57 ]
python
en
['en', 'en', 'en']
True
WLEDFlowHandler.async_step_zeroconf
( self, user_input: Optional[ConfigType] = None )
Handle zeroconf discovery.
Handle zeroconf discovery.
async def async_step_zeroconf( self, user_input: Optional[ConfigType] = None ) -> Dict[str, Any]: """Handle zeroconf discovery.""" if user_input is None: return self.async_abort(reason="cannot_connect") # Hostname is format: wled-livingroom.local. host = user_input["hostname"].rstrip(".") name, _ = host.rsplit(".") # pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167 self.context.update( { CONF_HOST: user_input["host"], CONF_NAME: name, CONF_MAC: user_input["properties"].get(CONF_MAC), "title_placeholders": {"name": name}, } ) # Prepare configuration flow return await self._handle_config_flow(user_input, True)
[ "async", "def", "async_step_zeroconf", "(", "self", ",", "user_input", ":", "Optional", "[", "ConfigType", "]", "=", "None", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "if", "user_input", "is", "None", ":", "return", "self", ".", "async_abort", "(", "reason", "=", "\"cannot_connect\"", ")", "# Hostname is format: wled-livingroom.local.", "host", "=", "user_input", "[", "\"hostname\"", "]", ".", "rstrip", "(", "\".\"", ")", "name", ",", "_", "=", "host", ".", "rsplit", "(", "\".\"", ")", "# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167", "self", ".", "context", ".", "update", "(", "{", "CONF_HOST", ":", "user_input", "[", "\"host\"", "]", ",", "CONF_NAME", ":", "name", ",", "CONF_MAC", ":", "user_input", "[", "\"properties\"", "]", ".", "get", "(", "CONF_MAC", ")", ",", "\"title_placeholders\"", ":", "{", "\"name\"", ":", "name", "}", ",", "}", ")", "# Prepare configuration flow", "return", "await", "self", ".", "_handle_config_flow", "(", "user_input", ",", "True", ")" ]
[ 30, 4 ]
[ 52, 63 ]
python
de
['de', 'sr', 'en']
False