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
GPT2Tokenizer._convert_id_to_token
(self, index)
Converts an index (integer) in a token (str) using the vocab.
Converts an index (integer) in a token (str) using the vocab.
def _convert_id_to_token(self, index): """Converts an index (integer) in a token (str) using the vocab.""" return self.decoder.get(index)
[ "def", "_convert_id_to_token", "(", "self", ",", "index", ")", ":", "return", "self", ".", "decoder", ".", "get", "(", "index", ")" ]
[ 257, 4 ]
[ 259, 38 ]
python
en
['en', 'en', 'en']
True
GPT2Tokenizer.convert_tokens_to_string
(self, tokens)
Converts a sequence of tokens (string) in a single string.
Converts a sequence of tokens (string) in a single string.
def convert_tokens_to_string(self, tokens): """ Converts a sequence of tokens (string) in a single string. """ text = "".join(tokens) text = bytearray([self.byte_decoder[c] for c in text]).decode("utf-8", errors=self.errors) return text
[ "def", "convert_tokens_to_string", "(", "self", ",", "tokens", ")", ":", "text", "=", "\"\"", ".", "join", "(", "tokens", ")", "text", "=", "bytearray", "(", "[", "self", ".", "byte_decoder", "[", "c", "]", "for", "c", "in", "text", "]", ")", ".", "decode", "(", "\"utf-8\"", ",", "errors", "=", "self", ".", "errors", ")", "return", "text" ]
[ 261, 4 ]
[ 265, 19 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up tuya sensors dynamically through tuya discovery.
Set up tuya sensors dynamically through tuya discovery.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up tuya sensors dynamically through tuya discovery.""" platform = config_entry.data[CONF_PLATFORM] async def async_discover_sensor(dev_ids): """Discover and add a discovered tuya sensor.""" if not dev_ids: return entities = await hass.async_add_executor_job( _setup_entities, hass, dev_ids, platform, ) async_add_entities(entities) async_dispatcher_connect( hass, TUYA_DISCOVERY_NEW.format(SENSOR_DOMAIN), async_discover_sensor ) devices_ids = hass.data[DOMAIN]["pending"].pop(SENSOR_DOMAIN) await async_discover_sensor(devices_ids)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "platform", "=", "config_entry", ".", "data", "[", "CONF_PLATFORM", "]", "async", "def", "async_discover_sensor", "(", "dev_ids", ")", ":", "\"\"\"Discover and add a discovered tuya sensor.\"\"\"", "if", "not", "dev_ids", ":", "return", "entities", "=", "await", "hass", ".", "async_add_executor_job", "(", "_setup_entities", ",", "hass", ",", "dev_ids", ",", "platform", ",", ")", "async_add_entities", "(", "entities", ")", "async_dispatcher_connect", "(", "hass", ",", "TUYA_DISCOVERY_NEW", ".", "format", "(", "SENSOR_DOMAIN", ")", ",", "async_discover_sensor", ")", "devices_ids", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "\"pending\"", "]", ".", "pop", "(", "SENSOR_DOMAIN", ")", "await", "async_discover_sensor", "(", "devices_ids", ")" ]
[ 44, 0 ]
[ 66, 44 ]
python
en
['en', 'zu', 'en']
True
_setup_entities
(hass, dev_ids, platform)
Set up Tuya Light device.
Set up Tuya Light device.
def _setup_entities(hass, dev_ids, platform): """Set up Tuya Light device.""" tuya = hass.data[DOMAIN][TUYA_DATA] entities = [] for dev_id in dev_ids: device = tuya.get_device_by_id(dev_id) if device is None: continue entities.append(TuyaLight(device, platform)) return entities
[ "def", "_setup_entities", "(", "hass", ",", "dev_ids", ",", "platform", ")", ":", "tuya", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "TUYA_DATA", "]", "entities", "=", "[", "]", "for", "dev_id", "in", "dev_ids", ":", "device", "=", "tuya", ".", "get_device_by_id", "(", "dev_id", ")", "if", "device", "is", "None", ":", "continue", "entities", ".", "append", "(", "TuyaLight", "(", "device", ",", "platform", ")", ")", "return", "entities" ]
[ 69, 0 ]
[ 78, 19 ]
python
en
['en', 'zu', 'en']
True
TuyaLight.__init__
(self, tuya, platform)
Init Tuya light device.
Init Tuya light device.
def __init__(self, tuya, platform): """Init Tuya light device.""" super().__init__(tuya, platform) self.entity_id = ENTITY_ID_FORMAT.format(tuya.object_id()) self._min_kelvin = tuya.max_color_temp() self._max_kelvin = tuya.min_color_temp()
[ "def", "__init__", "(", "self", ",", "tuya", ",", "platform", ")", ":", "super", "(", ")", ".", "__init__", "(", "tuya", ",", "platform", ")", "self", ".", "entity_id", "=", "ENTITY_ID_FORMAT", ".", "format", "(", "tuya", ".", "object_id", "(", ")", ")", "self", ".", "_min_kelvin", "=", "tuya", ".", "max_color_temp", "(", ")", "self", ".", "_max_kelvin", "=", "tuya", ".", "min_color_temp", "(", ")" ]
[ 84, 4 ]
[ 89, 48 ]
python
ca
['ca', 'zh', 'en']
False
TuyaLight._process_config
(self)
Set device config parameter.
Set device config parameter.
def _process_config(self): """Set device config parameter.""" config = self._get_device_config() if not config: return # support color config supp_color = config.get(CONF_SUPPORT_COLOR, False) if supp_color: self._tuya.force_support_color() # brightness range config self._tuya.brightness_white_range = BRIGHTNESS_MODES.get( config.get(CONF_BRIGHTNESS_RANGE_MODE, 0), TUYA_BRIGHTNESS_RANGE0, ) # color set temp range min_tuya = self._tuya.max_color_temp() min_kelvin = config.get(CONF_MIN_KELVIN, min_tuya) max_tuya = self._tuya.min_color_temp() max_kelvin = config.get(CONF_MAX_KELVIN, max_tuya) self._min_kelvin = min(max(min_kelvin, min_tuya), max_tuya) self._max_kelvin = min(max(max_kelvin, self._min_kelvin), max_tuya) # color shown temp range max_color_temp = max( config.get(CONF_TUYA_MAX_COLTEMP, DEFAULT_TUYA_MAX_COLTEMP), DEFAULT_TUYA_MAX_COLTEMP, ) self._tuya.color_temp_range = (1000, max_color_temp)
[ "def", "_process_config", "(", "self", ")", ":", "config", "=", "self", ".", "_get_device_config", "(", ")", "if", "not", "config", ":", "return", "# support color config", "supp_color", "=", "config", ".", "get", "(", "CONF_SUPPORT_COLOR", ",", "False", ")", "if", "supp_color", ":", "self", ".", "_tuya", ".", "force_support_color", "(", ")", "# brightness range config", "self", ".", "_tuya", ".", "brightness_white_range", "=", "BRIGHTNESS_MODES", ".", "get", "(", "config", ".", "get", "(", "CONF_BRIGHTNESS_RANGE_MODE", ",", "0", ")", ",", "TUYA_BRIGHTNESS_RANGE0", ",", ")", "# color set temp range", "min_tuya", "=", "self", ".", "_tuya", ".", "max_color_temp", "(", ")", "min_kelvin", "=", "config", ".", "get", "(", "CONF_MIN_KELVIN", ",", "min_tuya", ")", "max_tuya", "=", "self", ".", "_tuya", ".", "min_color_temp", "(", ")", "max_kelvin", "=", "config", ".", "get", "(", "CONF_MAX_KELVIN", ",", "max_tuya", ")", "self", ".", "_min_kelvin", "=", "min", "(", "max", "(", "min_kelvin", ",", "min_tuya", ")", ",", "max_tuya", ")", "self", ".", "_max_kelvin", "=", "min", "(", "max", "(", "max_kelvin", ",", "self", ".", "_min_kelvin", ")", ",", "max_tuya", ")", "# color shown temp range", "max_color_temp", "=", "max", "(", "config", ".", "get", "(", "CONF_TUYA_MAX_COLTEMP", ",", "DEFAULT_TUYA_MAX_COLTEMP", ")", ",", "DEFAULT_TUYA_MAX_COLTEMP", ",", ")", "self", ".", "_tuya", ".", "color_temp_range", "=", "(", "1000", ",", "max_color_temp", ")" ]
[ 92, 4 ]
[ 119, 60 ]
python
en
['nl', 'pt', 'en']
False
TuyaLight.async_added_to_hass
(self)
Set config parameter when add to hass.
Set config parameter when add to hass.
async def async_added_to_hass(self): """Set config parameter when add to hass.""" await super().async_added_to_hass() self._process_config() self.async_on_remove( async_dispatcher_connect( self.hass, SIGNAL_CONFIG_ENTITY, self._process_config ) ) return
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "await", "super", "(", ")", ".", "async_added_to_hass", "(", ")", "self", ".", "_process_config", "(", ")", "self", ".", "async_on_remove", "(", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "SIGNAL_CONFIG_ENTITY", ",", "self", ".", "_process_config", ")", ")", "return" ]
[ 121, 4 ]
[ 130, 14 ]
python
en
['en', 'en', 'en']
True
TuyaLight.brightness
(self)
Return the brightness of the light.
Return the brightness of the light.
def brightness(self): """Return the brightness of the light.""" if self._tuya.brightness() is None: return None return int(self._tuya.brightness())
[ "def", "brightness", "(", "self", ")", ":", "if", "self", ".", "_tuya", ".", "brightness", "(", ")", "is", "None", ":", "return", "None", "return", "int", "(", "self", ".", "_tuya", ".", "brightness", "(", ")", ")" ]
[ 133, 4 ]
[ 137, 43 ]
python
en
['en', 'no', 'en']
True
TuyaLight.hs_color
(self)
Return the hs_color of the light.
Return the hs_color of the light.
def hs_color(self): """Return the hs_color of the light.""" return tuple(map(int, self._tuya.hs_color()))
[ "def", "hs_color", "(", "self", ")", ":", "return", "tuple", "(", "map", "(", "int", ",", "self", ".", "_tuya", ".", "hs_color", "(", ")", ")", ")" ]
[ 140, 4 ]
[ 142, 53 ]
python
en
['en', 'en', 'en']
True
TuyaLight.color_temp
(self)
Return the color_temp of the light.
Return the color_temp of the light.
def color_temp(self): """Return the color_temp of the light.""" color_temp = int(self._tuya.color_temp()) if color_temp is None: return None return colorutil.color_temperature_kelvin_to_mired(color_temp)
[ "def", "color_temp", "(", "self", ")", ":", "color_temp", "=", "int", "(", "self", ".", "_tuya", ".", "color_temp", "(", ")", ")", "if", "color_temp", "is", "None", ":", "return", "None", "return", "colorutil", ".", "color_temperature_kelvin_to_mired", "(", "color_temp", ")" ]
[ 145, 4 ]
[ 150, 70 ]
python
en
['en', 'en', 'en']
True
TuyaLight.is_on
(self)
Return true if light is on.
Return true if light is on.
def is_on(self): """Return true if light is on.""" return self._tuya.state()
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "_tuya", ".", "state", "(", ")" ]
[ 153, 4 ]
[ 155, 33 ]
python
en
['en', 'et', 'en']
True
TuyaLight.min_mireds
(self)
Return color temperature min mireds.
Return color temperature min mireds.
def min_mireds(self): """Return color temperature min mireds.""" return colorutil.color_temperature_kelvin_to_mired(self._max_kelvin)
[ "def", "min_mireds", "(", "self", ")", ":", "return", "colorutil", ".", "color_temperature_kelvin_to_mired", "(", "self", ".", "_max_kelvin", ")" ]
[ 158, 4 ]
[ 160, 76 ]
python
en
['en', 'la', 'it']
False
TuyaLight.max_mireds
(self)
Return color temperature max mireds.
Return color temperature max mireds.
def max_mireds(self): """Return color temperature max mireds.""" return colorutil.color_temperature_kelvin_to_mired(self._min_kelvin)
[ "def", "max_mireds", "(", "self", ")", ":", "return", "colorutil", ".", "color_temperature_kelvin_to_mired", "(", "self", ".", "_min_kelvin", ")" ]
[ 163, 4 ]
[ 165, 76 ]
python
en
['en', 'la', 'it']
False
TuyaLight.turn_on
(self, **kwargs)
Turn on or control the light.
Turn on or control the light.
def turn_on(self, **kwargs): """Turn on or control the light.""" if ( ATTR_BRIGHTNESS not in kwargs and ATTR_HS_COLOR not in kwargs and ATTR_COLOR_TEMP not in kwargs ): self._tuya.turn_on() if ATTR_BRIGHTNESS in kwargs: self._tuya.set_brightness(kwargs[ATTR_BRIGHTNESS]) if ATTR_HS_COLOR in kwargs: self._tuya.set_color(kwargs[ATTR_HS_COLOR]) if ATTR_COLOR_TEMP in kwargs: color_temp = colorutil.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP] ) self._tuya.set_color_temp(color_temp)
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "(", "ATTR_BRIGHTNESS", "not", "in", "kwargs", "and", "ATTR_HS_COLOR", "not", "in", "kwargs", "and", "ATTR_COLOR_TEMP", "not", "in", "kwargs", ")", ":", "self", ".", "_tuya", ".", "turn_on", "(", ")", "if", "ATTR_BRIGHTNESS", "in", "kwargs", ":", "self", ".", "_tuya", ".", "set_brightness", "(", "kwargs", "[", "ATTR_BRIGHTNESS", "]", ")", "if", "ATTR_HS_COLOR", "in", "kwargs", ":", "self", ".", "_tuya", ".", "set_color", "(", "kwargs", "[", "ATTR_HS_COLOR", "]", ")", "if", "ATTR_COLOR_TEMP", "in", "kwargs", ":", "color_temp", "=", "colorutil", ".", "color_temperature_mired_to_kelvin", "(", "kwargs", "[", "ATTR_COLOR_TEMP", "]", ")", "self", ".", "_tuya", ".", "set_color_temp", "(", "color_temp", ")" ]
[ 167, 4 ]
[ 183, 49 ]
python
en
['en', 'en', 'en']
True
TuyaLight.turn_off
(self, **kwargs)
Instruct the light to turn off.
Instruct the light to turn off.
def turn_off(self, **kwargs): """Instruct the light to turn off.""" self._tuya.turn_off()
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_tuya", ".", "turn_off", "(", ")" ]
[ 185, 4 ]
[ 187, 29 ]
python
en
['en', 'en', 'en']
True
TuyaLight.supported_features
(self)
Flag supported features.
Flag supported features.
def supported_features(self): """Flag supported features.""" supports = SUPPORT_BRIGHTNESS if self._tuya.support_color(): supports = supports | SUPPORT_COLOR if self._tuya.support_color_temp(): supports = supports | SUPPORT_COLOR_TEMP return supports
[ "def", "supported_features", "(", "self", ")", ":", "supports", "=", "SUPPORT_BRIGHTNESS", "if", "self", ".", "_tuya", ".", "support_color", "(", ")", ":", "supports", "=", "supports", "|", "SUPPORT_COLOR", "if", "self", ".", "_tuya", ".", "support_color_temp", "(", ")", ":", "supports", "=", "supports", "|", "SUPPORT_COLOR_TEMP", "return", "supports" ]
[ 190, 4 ]
[ 197, 23 ]
python
en
['da', 'en', 'en']
True
test_config_with_accesspoint_passed_to_config_entry
( hass, mock_connection, simple_mock_home )
Test that config for a accesspoint are loaded via config entry.
Test that config for a accesspoint are loaded via config entry.
async def test_config_with_accesspoint_passed_to_config_entry( hass, mock_connection, simple_mock_home ): """Test that config for a accesspoint are loaded via config entry.""" entry_config = { CONF_ACCESSPOINT: "ABC123", CONF_AUTHTOKEN: "123", CONF_NAME: "name", } # no config_entry exists assert len(hass.config_entries.async_entries(HMIPC_DOMAIN)) == 0 # no acccesspoint exists assert not hass.data.get(HMIPC_DOMAIN) with patch( "homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect", ): assert await async_setup_component( hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config} ) # config_entry created for access point config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN) assert len(config_entries) == 1 assert config_entries[0].data == { "authtoken": "123", "hapid": "ABC123", "name": "name", } # defined access_point created for config_entry assert isinstance(hass.data[HMIPC_DOMAIN]["ABC123"], HomematicipHAP)
[ "async", "def", "test_config_with_accesspoint_passed_to_config_entry", "(", "hass", ",", "mock_connection", ",", "simple_mock_home", ")", ":", "entry_config", "=", "{", "CONF_ACCESSPOINT", ":", "\"ABC123\"", ",", "CONF_AUTHTOKEN", ":", "\"123\"", ",", "CONF_NAME", ":", "\"name\"", ",", "}", "# no config_entry exists", "assert", "len", "(", "hass", ".", "config_entries", ".", "async_entries", "(", "HMIPC_DOMAIN", ")", ")", "==", "0", "# no acccesspoint exists", "assert", "not", "hass", ".", "data", ".", "get", "(", "HMIPC_DOMAIN", ")", "with", "patch", "(", "\"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect\"", ",", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "HMIPC_DOMAIN", ",", "{", "HMIPC_DOMAIN", ":", "entry_config", "}", ")", "# config_entry created for access point", "config_entries", "=", "hass", ".", "config_entries", ".", "async_entries", "(", "HMIPC_DOMAIN", ")", "assert", "len", "(", "config_entries", ")", "==", "1", "assert", "config_entries", "[", "0", "]", ".", "data", "==", "{", "\"authtoken\"", ":", "\"123\"", ",", "\"hapid\"", ":", "\"ABC123\"", ",", "\"name\"", ":", "\"name\"", ",", "}", "# defined access_point created for config_entry", "assert", "isinstance", "(", "hass", ".", "data", "[", "HMIPC_DOMAIN", "]", "[", "\"ABC123\"", "]", ",", "HomematicipHAP", ")" ]
[ 26, 0 ]
[ 57, 72 ]
python
en
['en', 'en', 'en']
True
test_config_already_registered_not_passed_to_config_entry
( hass, simple_mock_home )
Test that an already registered accesspoint does not get imported.
Test that an already registered accesspoint does not get imported.
async def test_config_already_registered_not_passed_to_config_entry( hass, simple_mock_home ): """Test that an already registered accesspoint does not get imported.""" mock_config = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC123", HMIPC_NAME: "name"} MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config).add_to_hass(hass) # one config_entry exists config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN) assert len(config_entries) == 1 assert config_entries[0].data == { "authtoken": "123", "hapid": "ABC123", "name": "name", } # config_enty has no unique_id assert not config_entries[0].unique_id entry_config = { CONF_ACCESSPOINT: "ABC123", CONF_AUTHTOKEN: "123", CONF_NAME: "name", } with patch( "homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect", ): assert await async_setup_component( hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config} ) # no new config_entry created / still one config_entry config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN) assert len(config_entries) == 1 assert config_entries[0].data == { "authtoken": "123", "hapid": "ABC123", "name": "name", } # config_enty updated with unique_id assert config_entries[0].unique_id == "ABC123"
[ "async", "def", "test_config_already_registered_not_passed_to_config_entry", "(", "hass", ",", "simple_mock_home", ")", ":", "mock_config", "=", "{", "HMIPC_AUTHTOKEN", ":", "\"123\"", ",", "HMIPC_HAPID", ":", "\"ABC123\"", ",", "HMIPC_NAME", ":", "\"name\"", "}", "MockConfigEntry", "(", "domain", "=", "HMIPC_DOMAIN", ",", "data", "=", "mock_config", ")", ".", "add_to_hass", "(", "hass", ")", "# one config_entry exists", "config_entries", "=", "hass", ".", "config_entries", ".", "async_entries", "(", "HMIPC_DOMAIN", ")", "assert", "len", "(", "config_entries", ")", "==", "1", "assert", "config_entries", "[", "0", "]", ".", "data", "==", "{", "\"authtoken\"", ":", "\"123\"", ",", "\"hapid\"", ":", "\"ABC123\"", ",", "\"name\"", ":", "\"name\"", ",", "}", "# config_enty has no unique_id", "assert", "not", "config_entries", "[", "0", "]", ".", "unique_id", "entry_config", "=", "{", "CONF_ACCESSPOINT", ":", "\"ABC123\"", ",", "CONF_AUTHTOKEN", ":", "\"123\"", ",", "CONF_NAME", ":", "\"name\"", ",", "}", "with", "patch", "(", "\"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect\"", ",", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "HMIPC_DOMAIN", ",", "{", "HMIPC_DOMAIN", ":", "entry_config", "}", ")", "# no new config_entry created / still one config_entry", "config_entries", "=", "hass", ".", "config_entries", ".", "async_entries", "(", "HMIPC_DOMAIN", ")", "assert", "len", "(", "config_entries", ")", "==", "1", "assert", "config_entries", "[", "0", "]", ".", "data", "==", "{", "\"authtoken\"", ":", "\"123\"", ",", "\"hapid\"", ":", "\"ABC123\"", ",", "\"name\"", ":", "\"name\"", ",", "}", "# config_enty updated with unique_id", "assert", "config_entries", "[", "0", "]", ".", "unique_id", "==", "\"ABC123\"" ]
[ 60, 0 ]
[ 101, 50 ]
python
en
['en', 'en', 'en']
True
test_load_entry_fails_due_to_connection_error
( hass, hmip_config_entry, mock_connection_init )
Test load entry fails due to connection error.
Test load entry fails due to connection error.
async def test_load_entry_fails_due_to_connection_error( hass, hmip_config_entry, mock_connection_init ): """Test load entry fails due to connection error.""" hmip_config_entry.add_to_hass(hass) with patch( "homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state", side_effect=HmipConnectionError, ): assert await async_setup_component(hass, HMIPC_DOMAIN, {}) assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id] assert hmip_config_entry.state == ENTRY_STATE_SETUP_RETRY
[ "async", "def", "test_load_entry_fails_due_to_connection_error", "(", "hass", ",", "hmip_config_entry", ",", "mock_connection_init", ")", ":", "hmip_config_entry", ".", "add_to_hass", "(", "hass", ")", "with", "patch", "(", "\"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state\"", ",", "side_effect", "=", "HmipConnectionError", ",", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "HMIPC_DOMAIN", ",", "{", "}", ")", "assert", "hass", ".", "data", "[", "HMIPC_DOMAIN", "]", "[", "hmip_config_entry", ".", "unique_id", "]", "assert", "hmip_config_entry", ".", "state", "==", "ENTRY_STATE_SETUP_RETRY" ]
[ 104, 0 ]
[ 117, 61 ]
python
en
['en', 'en', 'en']
True
test_load_entry_fails_due_to_generic_exception
(hass, hmip_config_entry)
Test load entry fails due to generic exception.
Test load entry fails due to generic exception.
async def test_load_entry_fails_due_to_generic_exception(hass, hmip_config_entry): """Test load entry fails due to generic exception.""" hmip_config_entry.add_to_hass(hass) with patch( "homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state", side_effect=Exception, ), patch( "homematicip.aio.connection.AsyncConnection.init", ): assert await async_setup_component(hass, HMIPC_DOMAIN, {}) assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id] assert hmip_config_entry.state == ENTRY_STATE_SETUP_ERROR
[ "async", "def", "test_load_entry_fails_due_to_generic_exception", "(", "hass", ",", "hmip_config_entry", ")", ":", "hmip_config_entry", ".", "add_to_hass", "(", "hass", ")", "with", "patch", "(", "\"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state\"", ",", "side_effect", "=", "Exception", ",", ")", ",", "patch", "(", "\"homematicip.aio.connection.AsyncConnection.init\"", ",", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "HMIPC_DOMAIN", ",", "{", "}", ")", "assert", "hass", ".", "data", "[", "HMIPC_DOMAIN", "]", "[", "hmip_config_entry", ".", "unique_id", "]", "assert", "hmip_config_entry", ".", "state", "==", "ENTRY_STATE_SETUP_ERROR" ]
[ 120, 0 ]
[ 133, 61 ]
python
en
['en', 'en', 'en']
True
test_unload_entry
(hass)
Test being able to unload an entry.
Test being able to unload an entry.
async def test_unload_entry(hass): """Test being able to unload an entry.""" mock_config = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC123", HMIPC_NAME: "name"} MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config).add_to_hass(hass) with patch("homeassistant.components.homematicip_cloud.HomematicipHAP") as mock_hap: instance = mock_hap.return_value instance.async_setup = AsyncMock(return_value=True) instance.home.id = "1" instance.home.modelType = "mock-type" instance.home.name = "mock-name" instance.home.label = "mock-label" instance.home.currentAPVersion = "mock-ap-version" instance.async_reset = AsyncMock(return_value=True) assert await async_setup_component(hass, HMIPC_DOMAIN, {}) assert mock_hap.return_value.mock_calls[0][0] == "async_setup" assert hass.data[HMIPC_DOMAIN]["ABC123"] config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN) assert len(config_entries) == 1 assert config_entries[0].state == ENTRY_STATE_LOADED await hass.config_entries.async_unload(config_entries[0].entry_id) assert config_entries[0].state == ENTRY_STATE_NOT_LOADED assert mock_hap.return_value.mock_calls[2][0] == "async_reset" # entry is unloaded assert hass.data[HMIPC_DOMAIN] == {}
[ "async", "def", "test_unload_entry", "(", "hass", ")", ":", "mock_config", "=", "{", "HMIPC_AUTHTOKEN", ":", "\"123\"", ",", "HMIPC_HAPID", ":", "\"ABC123\"", ",", "HMIPC_NAME", ":", "\"name\"", "}", "MockConfigEntry", "(", "domain", "=", "HMIPC_DOMAIN", ",", "data", "=", "mock_config", ")", ".", "add_to_hass", "(", "hass", ")", "with", "patch", "(", "\"homeassistant.components.homematicip_cloud.HomematicipHAP\"", ")", "as", "mock_hap", ":", "instance", "=", "mock_hap", ".", "return_value", "instance", ".", "async_setup", "=", "AsyncMock", "(", "return_value", "=", "True", ")", "instance", ".", "home", ".", "id", "=", "\"1\"", "instance", ".", "home", ".", "modelType", "=", "\"mock-type\"", "instance", ".", "home", ".", "name", "=", "\"mock-name\"", "instance", ".", "home", ".", "label", "=", "\"mock-label\"", "instance", ".", "home", ".", "currentAPVersion", "=", "\"mock-ap-version\"", "instance", ".", "async_reset", "=", "AsyncMock", "(", "return_value", "=", "True", ")", "assert", "await", "async_setup_component", "(", "hass", ",", "HMIPC_DOMAIN", ",", "{", "}", ")", "assert", "mock_hap", ".", "return_value", ".", "mock_calls", "[", "0", "]", "[", "0", "]", "==", "\"async_setup\"", "assert", "hass", ".", "data", "[", "HMIPC_DOMAIN", "]", "[", "\"ABC123\"", "]", "config_entries", "=", "hass", ".", "config_entries", ".", "async_entries", "(", "HMIPC_DOMAIN", ")", "assert", "len", "(", "config_entries", ")", "==", "1", "assert", "config_entries", "[", "0", "]", ".", "state", "==", "ENTRY_STATE_LOADED", "await", "hass", ".", "config_entries", ".", "async_unload", "(", "config_entries", "[", "0", "]", ".", "entry_id", ")", "assert", "config_entries", "[", "0", "]", ".", "state", "==", "ENTRY_STATE_NOT_LOADED", "assert", "mock_hap", ".", "return_value", ".", "mock_calls", "[", "2", "]", "[", "0", "]", "==", "\"async_reset\"", "# entry is unloaded", "assert", "hass", ".", "data", "[", "HMIPC_DOMAIN", "]", "==", "{", "}" ]
[ 136, 0 ]
[ 163, 40 ]
python
en
['en', 'en', 'en']
True
test_hmip_dump_hap_config_services
(hass, mock_hap_with_service)
Test dump configuration services.
Test dump configuration services.
async def test_hmip_dump_hap_config_services(hass, mock_hap_with_service): """Test dump configuration services.""" with patch("pathlib.Path.write_text", return_value=Mock()) as write_mock: await hass.services.async_call( "homematicip_cloud", "dump_hap_config", {"anonymize": True}, blocking=True ) home = mock_hap_with_service.home assert home.mock_calls[-1][0] == "download_configuration" assert home.mock_calls assert write_mock.mock_calls
[ "async", "def", "test_hmip_dump_hap_config_services", "(", "hass", ",", "mock_hap_with_service", ")", ":", "with", "patch", "(", "\"pathlib.Path.write_text\"", ",", "return_value", "=", "Mock", "(", ")", ")", "as", "write_mock", ":", "await", "hass", ".", "services", ".", "async_call", "(", "\"homematicip_cloud\"", ",", "\"dump_hap_config\"", ",", "{", "\"anonymize\"", ":", "True", "}", ",", "blocking", "=", "True", ")", "home", "=", "mock_hap_with_service", ".", "home", "assert", "home", ".", "mock_calls", "[", "-", "1", "]", "[", "0", "]", "==", "\"download_configuration\"", "assert", "home", ".", "mock_calls", "assert", "write_mock", ".", "mock_calls" ]
[ 166, 0 ]
[ 176, 36 ]
python
fr
['fr', 'fr', 'en']
True
test_setup_services_and_unload_services
(hass)
Test setup services and unload services.
Test setup services and unload services.
async def test_setup_services_and_unload_services(hass): """Test setup services and unload services.""" mock_config = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC123", HMIPC_NAME: "name"} MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config).add_to_hass(hass) with patch("homeassistant.components.homematicip_cloud.HomematicipHAP") as mock_hap: instance = mock_hap.return_value instance.async_setup = AsyncMock(return_value=True) instance.home.id = "1" instance.home.modelType = "mock-type" instance.home.name = "mock-name" instance.home.label = "mock-label" instance.home.currentAPVersion = "mock-ap-version" instance.async_reset = AsyncMock(return_value=True) assert await async_setup_component(hass, HMIPC_DOMAIN, {}) # Check services are created hmipc_services = hass.services.async_services()[HMIPC_DOMAIN] assert len(hmipc_services) == 8 config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN) assert len(config_entries) == 1 await hass.config_entries.async_unload(config_entries[0].entry_id) # Check services are removed assert not hass.services.async_services().get(HMIPC_DOMAIN)
[ "async", "def", "test_setup_services_and_unload_services", "(", "hass", ")", ":", "mock_config", "=", "{", "HMIPC_AUTHTOKEN", ":", "\"123\"", ",", "HMIPC_HAPID", ":", "\"ABC123\"", ",", "HMIPC_NAME", ":", "\"name\"", "}", "MockConfigEntry", "(", "domain", "=", "HMIPC_DOMAIN", ",", "data", "=", "mock_config", ")", ".", "add_to_hass", "(", "hass", ")", "with", "patch", "(", "\"homeassistant.components.homematicip_cloud.HomematicipHAP\"", ")", "as", "mock_hap", ":", "instance", "=", "mock_hap", ".", "return_value", "instance", ".", "async_setup", "=", "AsyncMock", "(", "return_value", "=", "True", ")", "instance", ".", "home", ".", "id", "=", "\"1\"", "instance", ".", "home", ".", "modelType", "=", "\"mock-type\"", "instance", ".", "home", ".", "name", "=", "\"mock-name\"", "instance", ".", "home", ".", "label", "=", "\"mock-label\"", "instance", ".", "home", ".", "currentAPVersion", "=", "\"mock-ap-version\"", "instance", ".", "async_reset", "=", "AsyncMock", "(", "return_value", "=", "True", ")", "assert", "await", "async_setup_component", "(", "hass", ",", "HMIPC_DOMAIN", ",", "{", "}", ")", "# Check services are created", "hmipc_services", "=", "hass", ".", "services", ".", "async_services", "(", ")", "[", "HMIPC_DOMAIN", "]", "assert", "len", "(", "hmipc_services", ")", "==", "8", "config_entries", "=", "hass", ".", "config_entries", ".", "async_entries", "(", "HMIPC_DOMAIN", ")", "assert", "len", "(", "config_entries", ")", "==", "1", "await", "hass", ".", "config_entries", ".", "async_unload", "(", "config_entries", "[", "0", "]", ".", "entry_id", ")", "# Check services are removed", "assert", "not", "hass", ".", "services", ".", "async_services", "(", ")", ".", "get", "(", "HMIPC_DOMAIN", ")" ]
[ 179, 0 ]
[ 205, 63 ]
python
en
['en', 'en', 'en']
True
test_setup_two_haps_unload_one_by_one
(hass)
Test setup two access points and unload one by one and check services.
Test setup two access points and unload one by one and check services.
async def test_setup_two_haps_unload_one_by_one(hass): """Test setup two access points and unload one by one and check services.""" # Setup AP1 mock_config = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC123", HMIPC_NAME: "name"} MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config).add_to_hass(hass) # Setup AP2 mock_config2 = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC1234", HMIPC_NAME: "name2"} MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config2).add_to_hass(hass) with patch("homeassistant.components.homematicip_cloud.HomematicipHAP") as mock_hap: instance = mock_hap.return_value instance.async_setup = AsyncMock(return_value=True) instance.home.id = "1" instance.home.modelType = "mock-type" instance.home.name = "mock-name" instance.home.label = "mock-label" instance.home.currentAPVersion = "mock-ap-version" instance.async_reset = AsyncMock(return_value=True) assert await async_setup_component(hass, HMIPC_DOMAIN, {}) hmipc_services = hass.services.async_services()[HMIPC_DOMAIN] assert len(hmipc_services) == 8 config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN) assert len(config_entries) == 2 # unload the first AP await hass.config_entries.async_unload(config_entries[0].entry_id) # services still exists hmipc_services = hass.services.async_services()[HMIPC_DOMAIN] assert len(hmipc_services) == 8 # unload the second AP await hass.config_entries.async_unload(config_entries[1].entry_id) # Check services are removed assert not hass.services.async_services().get(HMIPC_DOMAIN)
[ "async", "def", "test_setup_two_haps_unload_one_by_one", "(", "hass", ")", ":", "# Setup AP1", "mock_config", "=", "{", "HMIPC_AUTHTOKEN", ":", "\"123\"", ",", "HMIPC_HAPID", ":", "\"ABC123\"", ",", "HMIPC_NAME", ":", "\"name\"", "}", "MockConfigEntry", "(", "domain", "=", "HMIPC_DOMAIN", ",", "data", "=", "mock_config", ")", ".", "add_to_hass", "(", "hass", ")", "# Setup AP2", "mock_config2", "=", "{", "HMIPC_AUTHTOKEN", ":", "\"123\"", ",", "HMIPC_HAPID", ":", "\"ABC1234\"", ",", "HMIPC_NAME", ":", "\"name2\"", "}", "MockConfigEntry", "(", "domain", "=", "HMIPC_DOMAIN", ",", "data", "=", "mock_config2", ")", ".", "add_to_hass", "(", "hass", ")", "with", "patch", "(", "\"homeassistant.components.homematicip_cloud.HomematicipHAP\"", ")", "as", "mock_hap", ":", "instance", "=", "mock_hap", ".", "return_value", "instance", ".", "async_setup", "=", "AsyncMock", "(", "return_value", "=", "True", ")", "instance", ".", "home", ".", "id", "=", "\"1\"", "instance", ".", "home", ".", "modelType", "=", "\"mock-type\"", "instance", ".", "home", ".", "name", "=", "\"mock-name\"", "instance", ".", "home", ".", "label", "=", "\"mock-label\"", "instance", ".", "home", ".", "currentAPVersion", "=", "\"mock-ap-version\"", "instance", ".", "async_reset", "=", "AsyncMock", "(", "return_value", "=", "True", ")", "assert", "await", "async_setup_component", "(", "hass", ",", "HMIPC_DOMAIN", ",", "{", "}", ")", "hmipc_services", "=", "hass", ".", "services", ".", "async_services", "(", ")", "[", "HMIPC_DOMAIN", "]", "assert", "len", "(", "hmipc_services", ")", "==", "8", "config_entries", "=", "hass", ".", "config_entries", ".", "async_entries", "(", "HMIPC_DOMAIN", ")", "assert", "len", "(", "config_entries", ")", "==", "2", "# unload the first AP", "await", "hass", ".", "config_entries", ".", "async_unload", "(", "config_entries", "[", "0", "]", ".", "entry_id", ")", "# services still exists", "hmipc_services", "=", "hass", ".", "services", ".", "async_services", "(", ")", "[", "HMIPC_DOMAIN", "]", "assert", "len", "(", "hmipc_services", ")", "==", "8", "# unload the second AP", "await", "hass", ".", "config_entries", ".", "async_unload", "(", "config_entries", "[", "1", "]", ".", "entry_id", ")", "# Check services are removed", "assert", "not", "hass", ".", "services", ".", "async_services", "(", ")", ".", "get", "(", "HMIPC_DOMAIN", ")" ]
[ 208, 0 ]
[ 246, 63 ]
python
en
['en', 'en', 'en']
True
test_platform_manually_configured
(hass)
Test that we do not discover anything or try to set up a gateway.
Test that we do not discover anything or try to set up a gateway.
async def test_platform_manually_configured(hass): """Test that we do not discover anything or try to set up a gateway.""" assert ( await async_setup_component( hass, LIGHT_DOMAIN, {"light": {"platform": DECONZ_DOMAIN}} ) is True ) assert DECONZ_DOMAIN not in hass.data
[ "async", "def", "test_platform_manually_configured", "(", "hass", ")", ":", "assert", "(", "await", "async_setup_component", "(", "hass", ",", "LIGHT_DOMAIN", ",", "{", "\"light\"", ":", "{", "\"platform\"", ":", "DECONZ_DOMAIN", "}", "}", ")", "is", "True", ")", "assert", "DECONZ_DOMAIN", "not", "in", "hass", ".", "data" ]
[ 107, 0 ]
[ 115, 41 ]
python
en
['en', 'en', 'en']
True
test_no_lights_or_groups
(hass)
Test that no lights or groups entities are created.
Test that no lights or groups entities are created.
async def test_no_lights_or_groups(hass): """Test that no lights or groups entities are created.""" await setup_deconz_integration(hass) assert len(hass.states.async_all()) == 0
[ "async", "def", "test_no_lights_or_groups", "(", "hass", ")", ":", "await", "setup_deconz_integration", "(", "hass", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "0" ]
[ 118, 0 ]
[ 121, 44 ]
python
en
['en', 'en', 'en']
True
test_lights_and_groups
(hass)
Test that lights or groups entities are created.
Test that lights or groups entities are created.
async def test_lights_and_groups(hass): """Test that lights or groups entities are created.""" data = deepcopy(DECONZ_WEB_REQUEST) data["groups"] = deepcopy(GROUPS) data["lights"] = deepcopy(LIGHTS) config_entry = await setup_deconz_integration(hass, get_state_response=data) gateway = get_gateway_from_config_entry(hass, config_entry) assert len(hass.states.async_all()) == 6 rgb_light = hass.states.get("light.rgb_light") assert rgb_light.state == STATE_ON assert rgb_light.attributes[ATTR_BRIGHTNESS] == 255 assert rgb_light.attributes[ATTR_HS_COLOR] == (224.235, 100.0) assert rgb_light.attributes["is_deconz_group"] is False assert rgb_light.attributes[ATTR_SUPPORTED_FEATURES] == 61 tunable_white_light = hass.states.get("light.tunable_white_light") assert tunable_white_light.state == STATE_ON assert tunable_white_light.attributes[ATTR_COLOR_TEMP] == 2500 assert tunable_white_light.attributes[ATTR_MAX_MIREDS] == 454 assert tunable_white_light.attributes[ATTR_MIN_MIREDS] == 155 assert tunable_white_light.attributes[ATTR_SUPPORTED_FEATURES] == 2 tunable_white_light_bad_maxmin = hass.states.get( "light.tunable_white_light_with_bad_maxmin_values" ) assert tunable_white_light_bad_maxmin.state == STATE_ON assert tunable_white_light_bad_maxmin.attributes[ATTR_COLOR_TEMP] == 2500 assert tunable_white_light_bad_maxmin.attributes[ATTR_MAX_MIREDS] == 650 assert tunable_white_light_bad_maxmin.attributes[ATTR_MIN_MIREDS] == 140 assert tunable_white_light_bad_maxmin.attributes[ATTR_SUPPORTED_FEATURES] == 2 on_off_light = hass.states.get("light.on_off_light") assert on_off_light.state == STATE_ON assert on_off_light.attributes[ATTR_SUPPORTED_FEATURES] == 0 light_group = hass.states.get("light.light_group") assert light_group.state == STATE_ON assert light_group.attributes["all_on"] is False empty_group = hass.states.get("light.empty_group") assert empty_group is None state_changed_event = { "t": "event", "e": "changed", "r": "lights", "id": "1", "state": {"on": False}, } gateway.api.event_handler(state_changed_event) await hass.async_block_till_done() rgb_light = hass.states.get("light.rgb_light") assert rgb_light.state == STATE_OFF # Verify service calls rgb_light_device = gateway.api.lights["1"] # Service turn on light with short color loop with patch.object(rgb_light_device, "_request", return_value=True) as set_callback: await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_ON, { ATTR_ENTITY_ID: "light.rgb_light", ATTR_COLOR_TEMP: 2500, ATTR_BRIGHTNESS: 200, ATTR_TRANSITION: 5, ATTR_FLASH: FLASH_SHORT, ATTR_EFFECT: EFFECT_COLORLOOP, }, blocking=True, ) await hass.async_block_till_done() set_callback.assert_called_with( "put", "/lights/1/state", json={ "ct": 2500, "bri": 200, "transitiontime": 50, "alert": "select", "effect": "colorloop", }, ) # Service turn on light disabling color loop with long flashing with patch.object(rgb_light_device, "_request", return_value=True) as set_callback: await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_ON, { ATTR_ENTITY_ID: "light.rgb_light", ATTR_HS_COLOR: (20, 30), ATTR_FLASH: FLASH_LONG, ATTR_EFFECT: "None", }, blocking=True, ) await hass.async_block_till_done() set_callback.assert_called_with( "put", "/lights/1/state", json={"xy": (0.411, 0.351), "alert": "lselect", "effect": "none"}, ) # Service turn on light with short flashing with patch.object(rgb_light_device, "_request", return_value=True) as set_callback: await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_OFF, { ATTR_ENTITY_ID: "light.rgb_light", ATTR_TRANSITION: 5, ATTR_FLASH: FLASH_SHORT, }, blocking=True, ) await hass.async_block_till_done() assert not set_callback.called state_changed_event = { "t": "event", "e": "changed", "r": "lights", "id": "1", "state": {"on": True}, } gateway.api.event_handler(state_changed_event) await hass.async_block_till_done() # Service turn off light with short flashing with patch.object(rgb_light_device, "_request", return_value=True) as set_callback: await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_OFF, { ATTR_ENTITY_ID: "light.rgb_light", ATTR_TRANSITION: 5, ATTR_FLASH: FLASH_SHORT, }, blocking=True, ) await hass.async_block_till_done() set_callback.assert_called_with( "put", "/lights/1/state", json={"bri": 0, "transitiontime": 50, "alert": "select"}, ) # Service turn off light with long flashing with patch.object(rgb_light_device, "_request", return_value=True) as set_callback: await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "light.rgb_light", ATTR_FLASH: FLASH_LONG}, blocking=True, ) await hass.async_block_till_done() set_callback.assert_called_with( "put", "/lights/1/state", json={"alert": "lselect"} ) await hass.config_entries.async_unload(config_entry.entry_id) assert len(hass.states.async_all()) == 0
[ "async", "def", "test_lights_and_groups", "(", "hass", ")", ":", "data", "=", "deepcopy", "(", "DECONZ_WEB_REQUEST", ")", "data", "[", "\"groups\"", "]", "=", "deepcopy", "(", "GROUPS", ")", "data", "[", "\"lights\"", "]", "=", "deepcopy", "(", "LIGHTS", ")", "config_entry", "=", "await", "setup_deconz_integration", "(", "hass", ",", "get_state_response", "=", "data", ")", "gateway", "=", "get_gateway_from_config_entry", "(", "hass", ",", "config_entry", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "6", "rgb_light", "=", "hass", ".", "states", ".", "get", "(", "\"light.rgb_light\"", ")", "assert", "rgb_light", ".", "state", "==", "STATE_ON", "assert", "rgb_light", ".", "attributes", "[", "ATTR_BRIGHTNESS", "]", "==", "255", "assert", "rgb_light", ".", "attributes", "[", "ATTR_HS_COLOR", "]", "==", "(", "224.235", ",", "100.0", ")", "assert", "rgb_light", ".", "attributes", "[", "\"is_deconz_group\"", "]", "is", "False", "assert", "rgb_light", ".", "attributes", "[", "ATTR_SUPPORTED_FEATURES", "]", "==", "61", "tunable_white_light", "=", "hass", ".", "states", ".", "get", "(", "\"light.tunable_white_light\"", ")", "assert", "tunable_white_light", ".", "state", "==", "STATE_ON", "assert", "tunable_white_light", ".", "attributes", "[", "ATTR_COLOR_TEMP", "]", "==", "2500", "assert", "tunable_white_light", ".", "attributes", "[", "ATTR_MAX_MIREDS", "]", "==", "454", "assert", "tunable_white_light", ".", "attributes", "[", "ATTR_MIN_MIREDS", "]", "==", "155", "assert", "tunable_white_light", ".", "attributes", "[", "ATTR_SUPPORTED_FEATURES", "]", "==", "2", "tunable_white_light_bad_maxmin", "=", "hass", ".", "states", ".", "get", "(", "\"light.tunable_white_light_with_bad_maxmin_values\"", ")", "assert", "tunable_white_light_bad_maxmin", ".", "state", "==", "STATE_ON", "assert", "tunable_white_light_bad_maxmin", ".", "attributes", "[", "ATTR_COLOR_TEMP", "]", "==", "2500", "assert", "tunable_white_light_bad_maxmin", ".", "attributes", "[", "ATTR_MAX_MIREDS", "]", "==", "650", "assert", "tunable_white_light_bad_maxmin", ".", "attributes", "[", "ATTR_MIN_MIREDS", "]", "==", "140", "assert", "tunable_white_light_bad_maxmin", ".", "attributes", "[", "ATTR_SUPPORTED_FEATURES", "]", "==", "2", "on_off_light", "=", "hass", ".", "states", ".", "get", "(", "\"light.on_off_light\"", ")", "assert", "on_off_light", ".", "state", "==", "STATE_ON", "assert", "on_off_light", ".", "attributes", "[", "ATTR_SUPPORTED_FEATURES", "]", "==", "0", "light_group", "=", "hass", ".", "states", ".", "get", "(", "\"light.light_group\"", ")", "assert", "light_group", ".", "state", "==", "STATE_ON", "assert", "light_group", ".", "attributes", "[", "\"all_on\"", "]", "is", "False", "empty_group", "=", "hass", ".", "states", ".", "get", "(", "\"light.empty_group\"", ")", "assert", "empty_group", "is", "None", "state_changed_event", "=", "{", "\"t\"", ":", "\"event\"", ",", "\"e\"", ":", "\"changed\"", ",", "\"r\"", ":", "\"lights\"", ",", "\"id\"", ":", "\"1\"", ",", "\"state\"", ":", "{", "\"on\"", ":", "False", "}", ",", "}", "gateway", ".", "api", ".", "event_handler", "(", "state_changed_event", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "rgb_light", "=", "hass", ".", "states", ".", "get", "(", "\"light.rgb_light\"", ")", "assert", "rgb_light", ".", "state", "==", "STATE_OFF", "# Verify service calls", "rgb_light_device", "=", "gateway", ".", "api", ".", "lights", "[", "\"1\"", "]", "# Service turn on light with short color loop", "with", "patch", ".", "object", "(", "rgb_light_device", ",", "\"_request\"", ",", "return_value", "=", "True", ")", "as", "set_callback", ":", "await", "hass", ".", "services", ".", "async_call", "(", "LIGHT_DOMAIN", ",", "SERVICE_TURN_ON", ",", "{", "ATTR_ENTITY_ID", ":", "\"light.rgb_light\"", ",", "ATTR_COLOR_TEMP", ":", "2500", ",", "ATTR_BRIGHTNESS", ":", "200", ",", "ATTR_TRANSITION", ":", "5", ",", "ATTR_FLASH", ":", "FLASH_SHORT", ",", "ATTR_EFFECT", ":", "EFFECT_COLORLOOP", ",", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "set_callback", ".", "assert_called_with", "(", "\"put\"", ",", "\"/lights/1/state\"", ",", "json", "=", "{", "\"ct\"", ":", "2500", ",", "\"bri\"", ":", "200", ",", "\"transitiontime\"", ":", "50", ",", "\"alert\"", ":", "\"select\"", ",", "\"effect\"", ":", "\"colorloop\"", ",", "}", ",", ")", "# Service turn on light disabling color loop with long flashing", "with", "patch", ".", "object", "(", "rgb_light_device", ",", "\"_request\"", ",", "return_value", "=", "True", ")", "as", "set_callback", ":", "await", "hass", ".", "services", ".", "async_call", "(", "LIGHT_DOMAIN", ",", "SERVICE_TURN_ON", ",", "{", "ATTR_ENTITY_ID", ":", "\"light.rgb_light\"", ",", "ATTR_HS_COLOR", ":", "(", "20", ",", "30", ")", ",", "ATTR_FLASH", ":", "FLASH_LONG", ",", "ATTR_EFFECT", ":", "\"None\"", ",", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "set_callback", ".", "assert_called_with", "(", "\"put\"", ",", "\"/lights/1/state\"", ",", "json", "=", "{", "\"xy\"", ":", "(", "0.411", ",", "0.351", ")", ",", "\"alert\"", ":", "\"lselect\"", ",", "\"effect\"", ":", "\"none\"", "}", ",", ")", "# Service turn on light with short flashing", "with", "patch", ".", "object", "(", "rgb_light_device", ",", "\"_request\"", ",", "return_value", "=", "True", ")", "as", "set_callback", ":", "await", "hass", ".", "services", ".", "async_call", "(", "LIGHT_DOMAIN", ",", "SERVICE_TURN_OFF", ",", "{", "ATTR_ENTITY_ID", ":", "\"light.rgb_light\"", ",", "ATTR_TRANSITION", ":", "5", ",", "ATTR_FLASH", ":", "FLASH_SHORT", ",", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "not", "set_callback", ".", "called", "state_changed_event", "=", "{", "\"t\"", ":", "\"event\"", ",", "\"e\"", ":", "\"changed\"", ",", "\"r\"", ":", "\"lights\"", ",", "\"id\"", ":", "\"1\"", ",", "\"state\"", ":", "{", "\"on\"", ":", "True", "}", ",", "}", "gateway", ".", "api", ".", "event_handler", "(", "state_changed_event", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "# Service turn off light with short flashing", "with", "patch", ".", "object", "(", "rgb_light_device", ",", "\"_request\"", ",", "return_value", "=", "True", ")", "as", "set_callback", ":", "await", "hass", ".", "services", ".", "async_call", "(", "LIGHT_DOMAIN", ",", "SERVICE_TURN_OFF", ",", "{", "ATTR_ENTITY_ID", ":", "\"light.rgb_light\"", ",", "ATTR_TRANSITION", ":", "5", ",", "ATTR_FLASH", ":", "FLASH_SHORT", ",", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "set_callback", ".", "assert_called_with", "(", "\"put\"", ",", "\"/lights/1/state\"", ",", "json", "=", "{", "\"bri\"", ":", "0", ",", "\"transitiontime\"", ":", "50", ",", "\"alert\"", ":", "\"select\"", "}", ",", ")", "# Service turn off light with long flashing", "with", "patch", ".", "object", "(", "rgb_light_device", ",", "\"_request\"", ",", "return_value", "=", "True", ")", "as", "set_callback", ":", "await", "hass", ".", "services", ".", "async_call", "(", "LIGHT_DOMAIN", ",", "SERVICE_TURN_OFF", ",", "{", "ATTR_ENTITY_ID", ":", "\"light.rgb_light\"", ",", "ATTR_FLASH", ":", "FLASH_LONG", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "set_callback", ".", "assert_called_with", "(", "\"put\"", ",", "\"/lights/1/state\"", ",", "json", "=", "{", "\"alert\"", ":", "\"lselect\"", "}", ")", "await", "hass", ".", "config_entries", ".", "async_unload", "(", "config_entry", ".", "entry_id", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "0" ]
[ 124, 0 ]
[ 297, 44 ]
python
en
['en', 'en', 'en']
True
test_disable_light_groups
(hass)
Test disallowing light groups work.
Test disallowing light groups work.
async def test_disable_light_groups(hass): """Test disallowing light groups work.""" data = deepcopy(DECONZ_WEB_REQUEST) data["groups"] = deepcopy(GROUPS) data["lights"] = deepcopy(LIGHTS) config_entry = await setup_deconz_integration( hass, options={CONF_ALLOW_DECONZ_GROUPS: False}, get_state_response=data, ) assert len(hass.states.async_all()) == 5 assert hass.states.get("light.rgb_light") assert hass.states.get("light.tunable_white_light") assert hass.states.get("light.light_group") is None assert hass.states.get("light.empty_group") is None hass.config_entries.async_update_entry( config_entry, options={CONF_ALLOW_DECONZ_GROUPS: True} ) await hass.async_block_till_done() assert len(hass.states.async_all()) == 6 assert hass.states.get("light.light_group") hass.config_entries.async_update_entry( config_entry, options={CONF_ALLOW_DECONZ_GROUPS: False} ) await hass.async_block_till_done() assert len(hass.states.async_all()) == 5 assert hass.states.get("light.light_group") is None
[ "async", "def", "test_disable_light_groups", "(", "hass", ")", ":", "data", "=", "deepcopy", "(", "DECONZ_WEB_REQUEST", ")", "data", "[", "\"groups\"", "]", "=", "deepcopy", "(", "GROUPS", ")", "data", "[", "\"lights\"", "]", "=", "deepcopy", "(", "LIGHTS", ")", "config_entry", "=", "await", "setup_deconz_integration", "(", "hass", ",", "options", "=", "{", "CONF_ALLOW_DECONZ_GROUPS", ":", "False", "}", ",", "get_state_response", "=", "data", ",", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "5", "assert", "hass", ".", "states", ".", "get", "(", "\"light.rgb_light\"", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"light.tunable_white_light\"", ")", "assert", "hass", ".", "states", ".", "get", "(", "\"light.light_group\"", ")", "is", "None", "assert", "hass", ".", "states", ".", "get", "(", "\"light.empty_group\"", ")", "is", "None", "hass", ".", "config_entries", ".", "async_update_entry", "(", "config_entry", ",", "options", "=", "{", "CONF_ALLOW_DECONZ_GROUPS", ":", "True", "}", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "6", "assert", "hass", ".", "states", ".", "get", "(", "\"light.light_group\"", ")", "hass", ".", "config_entries", ".", "async_update_entry", "(", "config_entry", ",", "options", "=", "{", "CONF_ALLOW_DECONZ_GROUPS", ":", "False", "}", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_all", "(", ")", ")", "==", "5", "assert", "hass", ".", "states", ".", "get", "(", "\"light.light_group\"", ")", "is", "None" ]
[ 300, 0 ]
[ 331, 55 ]
python
en
['en', 'lb', 'en']
True
AsyncConfigEntryAuth.__init__
( self, websession: ClientSession, oauth_session: config_entry_oauth2_flow.OAuth2Session, api_url: str, )
Initialize Google Nest Device Access auth.
Initialize Google Nest Device Access auth.
def __init__( self, websession: ClientSession, oauth_session: config_entry_oauth2_flow.OAuth2Session, api_url: str, ): """Initialize Google Nest Device Access auth.""" super().__init__(websession, api_url) self._oauth_session = oauth_session
[ "def", "__init__", "(", "self", ",", "websession", ":", "ClientSession", ",", "oauth_session", ":", "config_entry_oauth2_flow", ".", "OAuth2Session", ",", "api_url", ":", "str", ",", ")", ":", "super", "(", ")", ".", "__init__", "(", "websession", ",", "api_url", ")", "self", ".", "_oauth_session", "=", "oauth_session" ]
[ 14, 4 ]
[ 22, 43 ]
python
en
['fr', 'en', 'it']
False
AsyncConfigEntryAuth.async_get_access_token
(self)
Return a valid access token.
Return a valid access token.
async def async_get_access_token(self): """Return a valid access token.""" if not self._oauth_session.valid_token: await self._oauth_session.async_ensure_token_valid() return self._oauth_session.token["access_token"]
[ "async", "def", "async_get_access_token", "(", "self", ")", ":", "if", "not", "self", ".", "_oauth_session", ".", "valid_token", ":", "await", "self", ".", "_oauth_session", ".", "async_ensure_token_valid", "(", ")", "return", "self", ".", "_oauth_session", ".", "token", "[", "\"access_token\"", "]" ]
[ 24, 4 ]
[ 29, 56 ]
python
en
['en', 'lb', 'en']
True
AsyncConfigEntryAuth.async_get_creds
(self)
Return a minimal OAuth credential.
Return a minimal OAuth credential.
async def async_get_creds(self): """Return a minimal OAuth credential.""" token = await self.async_get_access_token() return Credentials(token=token)
[ "async", "def", "async_get_creds", "(", "self", ")", ":", "token", "=", "await", "self", ".", "async_get_access_token", "(", ")", "return", "Credentials", "(", "token", "=", "token", ")" ]
[ 31, 4 ]
[ 34, 39 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Verisure switch platform.
Set up the Verisure switch platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Verisure switch platform.""" if not int(hub.config.get(CONF_SMARTPLUGS, 1)): return False hub.update_overview() switches = [] switches.extend( [ VerisureSmartplug(device_label) for device_label in hub.get("$.smartPlugs[*].deviceLabel") ] ) add_entities(switches)
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "not", "int", "(", "hub", ".", "config", ".", "get", "(", "CONF_SMARTPLUGS", ",", "1", ")", ")", ":", "return", "False", "hub", ".", "update_overview", "(", ")", "switches", "=", "[", "]", "switches", ".", "extend", "(", "[", "VerisureSmartplug", "(", "device_label", ")", "for", "device_label", "in", "hub", ".", "get", "(", "\"$.smartPlugs[*].deviceLabel\"", ")", "]", ")", "add_entities", "(", "switches", ")" ]
[ 8, 0 ]
[ 21, 26 ]
python
en
['en', 'cs', 'en']
True
VerisureSmartplug.__init__
(self, device_id)
Initialize the Verisure device.
Initialize the Verisure device.
def __init__(self, device_id): """Initialize the Verisure device.""" self._device_label = device_id self._change_timestamp = 0 self._state = False
[ "def", "__init__", "(", "self", ",", "device_id", ")", ":", "self", ".", "_device_label", "=", "device_id", "self", ".", "_change_timestamp", "=", "0", "self", ".", "_state", "=", "False" ]
[ 27, 4 ]
[ 31, 27 ]
python
en
['en', 'en', 'en']
True
VerisureSmartplug.name
(self)
Return the name or location of the smartplug.
Return the name or location of the smartplug.
def name(self): """Return the name or location of the smartplug.""" return hub.get_first( "$.smartPlugs[?(@.deviceLabel == '%s')].area", self._device_label )
[ "def", "name", "(", "self", ")", ":", "return", "hub", ".", "get_first", "(", "\"$.smartPlugs[?(@.deviceLabel == '%s')].area\"", ",", "self", ".", "_device_label", ")" ]
[ 34, 4 ]
[ 38, 9 ]
python
en
['en', 'en', 'en']
True
VerisureSmartplug.is_on
(self)
Return true if on.
Return true if on.
def is_on(self): """Return true if on.""" if monotonic() - self._change_timestamp < 10: return self._state self._state = ( hub.get_first( "$.smartPlugs[?(@.deviceLabel == '%s')].currentState", self._device_label, ) == "ON" ) return self._state
[ "def", "is_on", "(", "self", ")", ":", "if", "monotonic", "(", ")", "-", "self", ".", "_change_timestamp", "<", "10", ":", "return", "self", ".", "_state", "self", ".", "_state", "=", "(", "hub", ".", "get_first", "(", "\"$.smartPlugs[?(@.deviceLabel == '%s')].currentState\"", ",", "self", ".", "_device_label", ",", ")", "==", "\"ON\"", ")", "return", "self", ".", "_state" ]
[ 41, 4 ]
[ 52, 26 ]
python
en
['en', 'mt', 'en']
True
VerisureSmartplug.available
(self)
Return True if entity is available.
Return True if entity is available.
def available(self): """Return True if entity is available.""" return ( hub.get_first("$.smartPlugs[?(@.deviceLabel == '%s')]", self._device_label) is not None )
[ "def", "available", "(", "self", ")", ":", "return", "(", "hub", ".", "get_first", "(", "\"$.smartPlugs[?(@.deviceLabel == '%s')]\"", ",", "self", ".", "_device_label", ")", "is", "not", "None", ")" ]
[ 55, 4 ]
[ 60, 9 ]
python
en
['en', 'en', 'en']
True
VerisureSmartplug.turn_on
(self, **kwargs)
Set smartplug status on.
Set smartplug status on.
def turn_on(self, **kwargs): """Set smartplug status on.""" hub.session.set_smartplug_state(self._device_label, True) self._state = True self._change_timestamp = monotonic()
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "hub", ".", "session", ".", "set_smartplug_state", "(", "self", ".", "_device_label", ",", "True", ")", "self", ".", "_state", "=", "True", "self", ".", "_change_timestamp", "=", "monotonic", "(", ")" ]
[ 62, 4 ]
[ 66, 44 ]
python
en
['en', 'et', 'en']
True
VerisureSmartplug.turn_off
(self, **kwargs)
Set smartplug status off.
Set smartplug status off.
def turn_off(self, **kwargs): """Set smartplug status off.""" hub.session.set_smartplug_state(self._device_label, False) self._state = False self._change_timestamp = monotonic()
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "hub", ".", "session", ".", "set_smartplug_state", "(", "self", ".", "_device_label", ",", "False", ")", "self", ".", "_state", "=", "False", "self", ".", "_change_timestamp", "=", "monotonic", "(", ")" ]
[ 68, 4 ]
[ 72, 44 ]
python
en
['en', 'bs', 'en']
True
VerisureSmartplug.update
(self)
Get the latest date of the smartplug.
Get the latest date of the smartplug.
def update(self): """Get the latest date of the smartplug.""" hub.update_overview()
[ "def", "update", "(", "self", ")", ":", "hub", ".", "update_overview", "(", ")" ]
[ 75, 4 ]
[ 77, 29 ]
python
en
['en', 'en', 'en']
True
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up the Time and Date sensor.
Set up the Time and Date sensor.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Time and Date sensor.""" if hass.config.time_zone is None: _LOGGER.error("Timezone is not set in Home Assistant configuration") return False async_add_entities( [TimeDateSensor(hass, variable) for variable in config[CONF_DISPLAY_OPTIONS]] )
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "hass", ".", "config", ".", "time_zone", "is", "None", ":", "_LOGGER", ".", "error", "(", "\"Timezone is not set in Home Assistant configuration\"", ")", "return", "False", "async_add_entities", "(", "[", "TimeDateSensor", "(", "hass", ",", "variable", ")", "for", "variable", "in", "config", "[", "CONF_DISPLAY_OPTIONS", "]", "]", ")" ]
[ 38, 0 ]
[ 46, 5 ]
python
en
['en', 'en', 'en']
True
TimeDateSensor.__init__
(self, hass, option_type)
Initialize the sensor.
Initialize the sensor.
def __init__(self, hass, option_type): """Initialize the sensor.""" self._name = OPTION_TYPES[option_type] self.type = option_type self._state = None self.hass = hass self.unsub = None self._update_internal_state(dt_util.utcnow())
[ "def", "__init__", "(", "self", ",", "hass", ",", "option_type", ")", ":", "self", ".", "_name", "=", "OPTION_TYPES", "[", "option_type", "]", "self", ".", "type", "=", "option_type", "self", ".", "_state", "=", "None", "self", ".", "hass", "=", "hass", "self", ".", "unsub", "=", "None", "self", ".", "_update_internal_state", "(", "dt_util", ".", "utcnow", "(", ")", ")" ]
[ 52, 4 ]
[ 60, 53 ]
python
en
['en', 'en', 'en']
True
TimeDateSensor.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 63, 4 ]
[ 65, 25 ]
python
en
['en', 'mi', 'en']
True
TimeDateSensor.state
(self)
Return the state of the sensor.
Return the state of the sensor.
def state(self): """Return the state of the sensor.""" return self._state
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "_state" ]
[ 68, 4 ]
[ 70, 26 ]
python
en
['en', 'en', 'en']
True
TimeDateSensor.icon
(self)
Icon to use in the frontend, if any.
Icon to use in the frontend, if any.
def icon(self): """Icon to use in the frontend, if any.""" if "date" in self.type and "time" in self.type: return "mdi:calendar-clock" if "date" in self.type: return "mdi:calendar" return "mdi:clock"
[ "def", "icon", "(", "self", ")", ":", "if", "\"date\"", "in", "self", ".", "type", "and", "\"time\"", "in", "self", ".", "type", ":", "return", "\"mdi:calendar-clock\"", "if", "\"date\"", "in", "self", ".", "type", ":", "return", "\"mdi:calendar\"", "return", "\"mdi:clock\"" ]
[ 73, 4 ]
[ 79, 26 ]
python
en
['en', 'en', 'en']
True
TimeDateSensor.async_added_to_hass
(self)
Set up first update.
Set up first update.
async def async_added_to_hass(self) -> None: """Set up first update.""" self.unsub = async_track_point_in_utc_time( self.hass, self.point_in_time_listener, self.get_next_interval() )
[ "async", "def", "async_added_to_hass", "(", "self", ")", "->", "None", ":", "self", ".", "unsub", "=", "async_track_point_in_utc_time", "(", "self", ".", "hass", ",", "self", ".", "point_in_time_listener", ",", "self", ".", "get_next_interval", "(", ")", ")" ]
[ 81, 4 ]
[ 85, 9 ]
python
en
['en', 'lb', 'en']
True
TimeDateSensor.async_will_remove_from_hass
(self)
Cancel next update.
Cancel next update.
async def async_will_remove_from_hass(self) -> None: """Cancel next update.""" if self.unsub: self.unsub() self.unsub = None
[ "async", "def", "async_will_remove_from_hass", "(", "self", ")", "->", "None", ":", "if", "self", ".", "unsub", ":", "self", ".", "unsub", "(", ")", "self", ".", "unsub", "=", "None" ]
[ 87, 4 ]
[ 91, 29 ]
python
de
['es', 'de', 'en']
False
TimeDateSensor.get_next_interval
(self)
Compute next time an update should occur.
Compute next time an update should occur.
def get_next_interval(self): """Compute next time an update should occur.""" now = dt_util.utcnow() if self.type == "date": tomorrow = dt_util.as_local(now) + timedelta(days=1) return dt_util.start_of_local_day(tomorrow) if self.type == "beat": # Add 1 hour because @0 beats is at 23:00:00 UTC. timestamp = dt_util.as_timestamp(now + timedelta(hours=1)) interval = 86.4 else: timestamp = dt_util.as_timestamp(now) interval = 60 delta = interval - (timestamp % interval) next_interval = now + timedelta(seconds=delta) _LOGGER.debug("%s + %s -> %s (%s)", now, delta, next_interval, self.type) return next_interval
[ "def", "get_next_interval", "(", "self", ")", ":", "now", "=", "dt_util", ".", "utcnow", "(", ")", "if", "self", ".", "type", "==", "\"date\"", ":", "tomorrow", "=", "dt_util", ".", "as_local", "(", "now", ")", "+", "timedelta", "(", "days", "=", "1", ")", "return", "dt_util", ".", "start_of_local_day", "(", "tomorrow", ")", "if", "self", ".", "type", "==", "\"beat\"", ":", "# Add 1 hour because @0 beats is at 23:00:00 UTC.", "timestamp", "=", "dt_util", ".", "as_timestamp", "(", "now", "+", "timedelta", "(", "hours", "=", "1", ")", ")", "interval", "=", "86.4", "else", ":", "timestamp", "=", "dt_util", ".", "as_timestamp", "(", "now", ")", "interval", "=", "60", "delta", "=", "interval", "-", "(", "timestamp", "%", "interval", ")", "next_interval", "=", "now", "+", "timedelta", "(", "seconds", "=", "delta", ")", "_LOGGER", ".", "debug", "(", "\"%s + %s -> %s (%s)\"", ",", "now", ",", "delta", ",", "next_interval", ",", "self", ".", "type", ")", "return", "next_interval" ]
[ 93, 4 ]
[ 113, 28 ]
python
en
['en', 'en', 'en']
True
TimeDateSensor.point_in_time_listener
(self, time_date)
Get the latest data and update state.
Get the latest data and update state.
def point_in_time_listener(self, time_date): """Get the latest data and update state.""" self._update_internal_state(time_date) self.async_write_ha_state() self.unsub = async_track_point_in_utc_time( self.hass, self.point_in_time_listener, self.get_next_interval() )
[ "def", "point_in_time_listener", "(", "self", ",", "time_date", ")", ":", "self", ".", "_update_internal_state", "(", "time_date", ")", "self", ".", "async_write_ha_state", "(", ")", "self", ".", "unsub", "=", "async_track_point_in_utc_time", "(", "self", ".", "hass", ",", "self", ".", "point_in_time_listener", ",", "self", ".", "get_next_interval", "(", ")", ")" ]
[ 152, 4 ]
[ 158, 9 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up the Smappee Comfort Plugs.
Set up the Smappee Comfort Plugs.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Smappee Comfort Plugs.""" smappee_base = hass.data[DOMAIN][config_entry.entry_id] entities = [] for service_location in smappee_base.smappee.service_locations.values(): for actuator_id, actuator in service_location.actuators.items(): if actuator.type in ["SWITCH", "COMFORT_PLUG"]: entities.append( SmappeeActuator( smappee_base, service_location, actuator.name, actuator_id, actuator.type, actuator.serialnumber, ) ) elif actuator.type == "INFINITY_OUTPUT_MODULE": for option in actuator.state_options: entities.append( SmappeeActuator( smappee_base, service_location, actuator.name, actuator_id, actuator.type, actuator.serialnumber, actuator_state_option=option, ) ) async_add_entities(entities, True)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "smappee_base", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "config_entry", ".", "entry_id", "]", "entities", "=", "[", "]", "for", "service_location", "in", "smappee_base", ".", "smappee", ".", "service_locations", ".", "values", "(", ")", ":", "for", "actuator_id", ",", "actuator", "in", "service_location", ".", "actuators", ".", "items", "(", ")", ":", "if", "actuator", ".", "type", "in", "[", "\"SWITCH\"", ",", "\"COMFORT_PLUG\"", "]", ":", "entities", ".", "append", "(", "SmappeeActuator", "(", "smappee_base", ",", "service_location", ",", "actuator", ".", "name", ",", "actuator_id", ",", "actuator", ".", "type", ",", "actuator", ".", "serialnumber", ",", ")", ")", "elif", "actuator", ".", "type", "==", "\"INFINITY_OUTPUT_MODULE\"", ":", "for", "option", "in", "actuator", ".", "state_options", ":", "entities", ".", "append", "(", "SmappeeActuator", "(", "smappee_base", ",", "service_location", ",", "actuator", ".", "name", ",", "actuator_id", ",", "actuator", ".", "type", ",", "actuator", ".", "serialnumber", ",", "actuator_state_option", "=", "option", ",", ")", ")", "async_add_entities", "(", "entities", ",", "True", ")" ]
[ 9, 0 ]
[ 41, 38 ]
python
en
['en', 'en', 'en']
True
SmappeeActuator.__init__
( self, smappee_base, service_location, name, actuator_id, actuator_type, actuator_serialnumber, actuator_state_option=None, )
Initialize a new Smappee Comfort Plug.
Initialize a new Smappee Comfort Plug.
def __init__( self, smappee_base, service_location, name, actuator_id, actuator_type, actuator_serialnumber, actuator_state_option=None, ): """Initialize a new Smappee Comfort Plug.""" self._smappee_base = smappee_base self._service_location = service_location self._actuator_name = name self._actuator_id = actuator_id self._actuator_type = actuator_type self._actuator_serialnumber = actuator_serialnumber self._actuator_state_option = actuator_state_option self._state = self._service_location.actuators.get(actuator_id).state self._connection_state = self._service_location.actuators.get( actuator_id ).connection_state
[ "def", "__init__", "(", "self", ",", "smappee_base", ",", "service_location", ",", "name", ",", "actuator_id", ",", "actuator_type", ",", "actuator_serialnumber", ",", "actuator_state_option", "=", "None", ",", ")", ":", "self", ".", "_smappee_base", "=", "smappee_base", "self", ".", "_service_location", "=", "service_location", "self", ".", "_actuator_name", "=", "name", "self", ".", "_actuator_id", "=", "actuator_id", "self", ".", "_actuator_type", "=", "actuator_type", "self", ".", "_actuator_serialnumber", "=", "actuator_serialnumber", "self", ".", "_actuator_state_option", "=", "actuator_state_option", "self", ".", "_state", "=", "self", ".", "_service_location", ".", "actuators", ".", "get", "(", "actuator_id", ")", ".", "state", "self", ".", "_connection_state", "=", "self", ".", "_service_location", ".", "actuators", ".", "get", "(", "actuator_id", ")", ".", "connection_state" ]
[ 47, 4 ]
[ 68, 26 ]
python
en
['en', 'en', 'en']
True
SmappeeActuator.name
(self)
Return the name of the switch.
Return the name of the switch.
def name(self): """Return the name of the switch.""" if self._actuator_type == "INFINITY_OUTPUT_MODULE": return ( f"{self._service_location.service_location_name} - " f"Output module - {self._actuator_name} - {self._actuator_state_option}" ) # Switch or comfort plug return ( f"{self._service_location.service_location_name} - " f"{self._actuator_type.title()} - {self._actuator_name}" )
[ "def", "name", "(", "self", ")", ":", "if", "self", ".", "_actuator_type", "==", "\"INFINITY_OUTPUT_MODULE\"", ":", "return", "(", "f\"{self._service_location.service_location_name} - \"", "f\"Output module - {self._actuator_name} - {self._actuator_state_option}\"", ")", "# Switch or comfort plug", "return", "(", "f\"{self._service_location.service_location_name} - \"", "f\"{self._actuator_type.title()} - {self._actuator_name}\"", ")" ]
[ 71, 4 ]
[ 83, 9 ]
python
en
['en', 'en', 'en']
True
SmappeeActuator.is_on
(self)
Return true if switch is on.
Return true if switch is on.
def is_on(self): """Return true if switch is on.""" if self._actuator_type == "INFINITY_OUTPUT_MODULE": return ( self._service_location.actuators.get(self._actuator_id).state == self._actuator_state_option ) # Switch or comfort plug return self._state == "ON_ON"
[ "def", "is_on", "(", "self", ")", ":", "if", "self", ".", "_actuator_type", "==", "\"INFINITY_OUTPUT_MODULE\"", ":", "return", "(", "self", ".", "_service_location", ".", "actuators", ".", "get", "(", "self", ".", "_actuator_id", ")", ".", "state", "==", "self", ".", "_actuator_state_option", ")", "# Switch or comfort plug", "return", "self", ".", "_state", "==", "\"ON_ON\"" ]
[ 86, 4 ]
[ 95, 37 ]
python
en
['en', 'fy', 'en']
True
SmappeeActuator.icon
(self)
Icon to use in the frontend.
Icon to use in the frontend.
def icon(self): """Icon to use in the frontend.""" return ICON
[ "def", "icon", "(", "self", ")", ":", "return", "ICON" ]
[ 98, 4 ]
[ 100, 19 ]
python
en
['en', 'en', 'en']
True
SmappeeActuator.turn_on
(self, **kwargs)
Turn on Comport Plug.
Turn on Comport Plug.
def turn_on(self, **kwargs): """Turn on Comport Plug.""" if self._actuator_type in ["SWITCH", "COMFORT_PLUG"]: self._service_location.set_actuator_state(self._actuator_id, state="ON_ON") elif self._actuator_type == "INFINITY_OUTPUT_MODULE": self._service_location.set_actuator_state( self._actuator_id, state=self._actuator_state_option )
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_actuator_type", "in", "[", "\"SWITCH\"", ",", "\"COMFORT_PLUG\"", "]", ":", "self", ".", "_service_location", ".", "set_actuator_state", "(", "self", ".", "_actuator_id", ",", "state", "=", "\"ON_ON\"", ")", "elif", "self", ".", "_actuator_type", "==", "\"INFINITY_OUTPUT_MODULE\"", ":", "self", ".", "_service_location", ".", "set_actuator_state", "(", "self", ".", "_actuator_id", ",", "state", "=", "self", ".", "_actuator_state_option", ")" ]
[ 102, 4 ]
[ 109, 13 ]
python
en
['en', 'et', 'en']
True
SmappeeActuator.turn_off
(self, **kwargs)
Turn off Comport Plug.
Turn off Comport Plug.
def turn_off(self, **kwargs): """Turn off Comport Plug.""" if self._actuator_type in ["SWITCH", "COMFORT_PLUG"]: self._service_location.set_actuator_state( self._actuator_id, state="OFF_OFF" ) elif self._actuator_type == "INFINITY_OUTPUT_MODULE": self._service_location.set_actuator_state( self._actuator_id, state="PLACEHOLDER", api=False )
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_actuator_type", "in", "[", "\"SWITCH\"", ",", "\"COMFORT_PLUG\"", "]", ":", "self", ".", "_service_location", ".", "set_actuator_state", "(", "self", ".", "_actuator_id", ",", "state", "=", "\"OFF_OFF\"", ")", "elif", "self", ".", "_actuator_type", "==", "\"INFINITY_OUTPUT_MODULE\"", ":", "self", ".", "_service_location", ".", "set_actuator_state", "(", "self", ".", "_actuator_id", ",", "state", "=", "\"PLACEHOLDER\"", ",", "api", "=", "False", ")" ]
[ 111, 4 ]
[ 120, 13 ]
python
en
['en', 'et', 'en']
True
SmappeeActuator.available
(self)
Return True if entity is available. Unavailable for COMFORT_PLUGS.
Return True if entity is available. Unavailable for COMFORT_PLUGS.
def available(self): """Return True if entity is available. Unavailable for COMFORT_PLUGS.""" return ( self._connection_state == "CONNECTED" or self._actuator_type == "COMFORT_PLUG" )
[ "def", "available", "(", "self", ")", ":", "return", "(", "self", ".", "_connection_state", "==", "\"CONNECTED\"", "or", "self", ".", "_actuator_type", "==", "\"COMFORT_PLUG\"", ")" ]
[ 123, 4 ]
[ 128, 9 ]
python
en
['en', 'en', 'en']
True
SmappeeActuator.today_energy_kwh
(self)
Return the today total energy usage in kWh.
Return the today total energy usage in kWh.
def today_energy_kwh(self): """Return the today total energy usage in kWh.""" if self._actuator_type == "SWITCH": cons = self._service_location.actuators.get( self._actuator_id ).consumption_today if cons is not None: return round(cons / 1000.0, 2) return None
[ "def", "today_energy_kwh", "(", "self", ")", ":", "if", "self", ".", "_actuator_type", "==", "\"SWITCH\"", ":", "cons", "=", "self", ".", "_service_location", ".", "actuators", ".", "get", "(", "self", ".", "_actuator_id", ")", ".", "consumption_today", "if", "cons", "is", "not", "None", ":", "return", "round", "(", "cons", "/", "1000.0", ",", "2", ")", "return", "None" ]
[ 131, 4 ]
[ 139, 19 ]
python
en
['en', 'en', 'en']
True
SmappeeActuator.unique_id
( self, )
Return the unique ID for this switch.
Return the unique ID for this switch.
def unique_id( self, ): """Return the unique ID for this switch.""" if self._actuator_type == "INFINITY_OUTPUT_MODULE": return ( f"{self._service_location.device_serial_number}-" f"{self._service_location.service_location_id}-actuator-" f"{self._actuator_id}-{self._actuator_state_option}" ) # Switch or comfort plug return ( f"{self._service_location.device_serial_number}-" f"{self._service_location.service_location_id}-actuator-" f"{self._actuator_id}" )
[ "def", "unique_id", "(", "self", ",", ")", ":", "if", "self", ".", "_actuator_type", "==", "\"INFINITY_OUTPUT_MODULE\"", ":", "return", "(", "f\"{self._service_location.device_serial_number}-\"", "f\"{self._service_location.service_location_id}-actuator-\"", "f\"{self._actuator_id}-{self._actuator_state_option}\"", ")", "# Switch or comfort plug", "return", "(", "f\"{self._service_location.device_serial_number}-\"", "f\"{self._service_location.service_location_id}-actuator-\"", "f\"{self._actuator_id}\"", ")" ]
[ 142, 4 ]
[ 158, 9 ]
python
en
['en', 'en', 'en']
True
SmappeeActuator.device_info
(self)
Return the device info for this switch.
Return the device info for this switch.
def device_info(self): """Return the device info for this switch.""" return { "identifiers": {(DOMAIN, self._service_location.device_serial_number)}, "name": self._service_location.service_location_name, "manufacturer": "Smappee", "model": self._service_location.device_model, "sw_version": self._service_location.firmware_version, }
[ "def", "device_info", "(", "self", ")", ":", "return", "{", "\"identifiers\"", ":", "{", "(", "DOMAIN", ",", "self", ".", "_service_location", ".", "device_serial_number", ")", "}", ",", "\"name\"", ":", "self", ".", "_service_location", ".", "service_location_name", ",", "\"manufacturer\"", ":", "\"Smappee\"", ",", "\"model\"", ":", "self", ".", "_service_location", ".", "device_model", ",", "\"sw_version\"", ":", "self", ".", "_service_location", ".", "firmware_version", ",", "}" ]
[ 161, 4 ]
[ 169, 9 ]
python
en
['en', 'en', 'en']
True
SmappeeActuator.async_update
(self)
Get the latest data from Smappee and update the state.
Get the latest data from Smappee and update the state.
async def async_update(self): """Get the latest data from Smappee and update the state.""" await self._smappee_base.async_update() new_state = self._service_location.actuators.get(self._actuator_id).state if new_state != self._state: self._state = new_state self.async_write_ha_state() self._connection_state = self._service_location.actuators.get( self._actuator_id ).connection_state
[ "async", "def", "async_update", "(", "self", ")", ":", "await", "self", ".", "_smappee_base", ".", "async_update", "(", ")", "new_state", "=", "self", ".", "_service_location", ".", "actuators", ".", "get", "(", "self", ".", "_actuator_id", ")", ".", "state", "if", "new_state", "!=", "self", ".", "_state", ":", "self", ".", "_state", "=", "new_state", "self", ".", "async_write_ha_state", "(", ")", "self", ".", "_connection_state", "=", "self", ".", "_service_location", ".", "actuators", ".", "get", "(", "self", ".", "_actuator_id", ")", ".", "connection_state" ]
[ 171, 4 ]
[ 182, 26 ]
python
en
['en', 'en', 'en']
True
async_call_action_from_config
( hass: HomeAssistant, config: ConfigType, variables: TemplateVarsType, context: Context, )
Perform an action based on configuration.
Perform an action based on configuration.
async def async_call_action_from_config( hass: HomeAssistant, config: ConfigType, variables: TemplateVarsType, context: Context, ) -> None: """Perform an action based on configuration.""" await ZHA_ACTION_TYPES[DEVICE_ACTION_TYPES[config[CONF_TYPE]]]( hass, config, variables, context )
[ "async", "def", "async_call_action_from_config", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "ConfigType", ",", "variables", ":", "TemplateVarsType", ",", "context", ":", "Context", ",", ")", "->", "None", ":", "await", "ZHA_ACTION_TYPES", "[", "DEVICE_ACTION_TYPES", "[", "config", "[", "CONF_TYPE", "]", "]", "]", "(", "hass", ",", "config", ",", "variables", ",", "context", ")" ]
[ 44, 0 ]
[ 53, 5 ]
python
en
['en', 'en', 'en']
True
async_get_actions
(hass: HomeAssistant, device_id: str)
List device actions.
List device actions.
async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]: """List device actions.""" try: zha_device = await async_get_zha_device(hass, device_id) except (KeyError, AttributeError): return [] cluster_channels = [ ch.name for pool in zha_device.channels.pools for ch in pool.claimed_channels.values() ] actions = [ action for channel in DEVICE_ACTIONS for action in DEVICE_ACTIONS[channel] if channel in cluster_channels ] for action in actions: action[CONF_DEVICE_ID] = device_id return actions
[ "async", "def", "async_get_actions", "(", "hass", ":", "HomeAssistant", ",", "device_id", ":", "str", ")", "->", "List", "[", "dict", "]", ":", "try", ":", "zha_device", "=", "await", "async_get_zha_device", "(", "hass", ",", "device_id", ")", "except", "(", "KeyError", ",", "AttributeError", ")", ":", "return", "[", "]", "cluster_channels", "=", "[", "ch", ".", "name", "for", "pool", "in", "zha_device", ".", "channels", ".", "pools", "for", "ch", "in", "pool", ".", "claimed_channels", ".", "values", "(", ")", "]", "actions", "=", "[", "action", "for", "channel", "in", "DEVICE_ACTIONS", "for", "action", "in", "DEVICE_ACTIONS", "[", "channel", "]", "if", "channel", "in", "cluster_channels", "]", "for", "action", "in", "actions", ":", "action", "[", "CONF_DEVICE_ID", "]", "=", "device_id", "return", "actions" ]
[ 56, 0 ]
[ 75, 18 ]
python
en
['fr', 'en', 'en']
True
async_setup
(hass, config)
Track states and offer events for sensors.
Track states and offer events for sensors.
async def async_setup(hass, config): """Track states and offer events for sensors.""" component = hass.data[DOMAIN] = EntityComponent( _LOGGER, DOMAIN, hass, SCAN_INTERVAL ) await component.async_setup(config) return True
[ "async", "def", "async_setup", "(", "hass", ",", "config", ")", ":", "component", "=", "hass", ".", "data", "[", "DOMAIN", "]", "=", "EntityComponent", "(", "_LOGGER", ",", "DOMAIN", ",", "hass", ",", "SCAN_INTERVAL", ")", "await", "component", ".", "async_setup", "(", "config", ")", "return", "True" ]
[ 54, 0 ]
[ 61, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, entry)
Set up a config entry.
Set up a config entry.
async def async_setup_entry(hass, entry): """Set up a config entry.""" return await hass.data[DOMAIN].async_setup_entry(entry)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "entry", ")", ":", "return", "await", "hass", ".", "data", "[", "DOMAIN", "]", ".", "async_setup_entry", "(", "entry", ")" ]
[ 64, 0 ]
[ 66, 59 ]
python
en
['en', 'en', 'en']
True
async_unload_entry
(hass, entry)
Unload a config entry.
Unload a config entry.
async def async_unload_entry(hass, entry): """Unload a config entry.""" return await hass.data[DOMAIN].async_unload_entry(entry)
[ "async", "def", "async_unload_entry", "(", "hass", ",", "entry", ")", ":", "return", "await", "hass", ".", "data", "[", "DOMAIN", "]", ".", "async_unload_entry", "(", "entry", ")" ]
[ 69, 0 ]
[ 71, 60 ]
python
en
['en', 'es', 'en']
True
test_koogeek_ls1_setup
(hass)
Test that a Koogeek LS1 can be correctly setup in HA.
Test that a Koogeek LS1 can be correctly setup in HA.
async def test_koogeek_ls1_setup(hass): """Test that a Koogeek LS1 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "koogeek_ls1.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() # Assert that the entity is correctly added to the entity registry entry = entity_registry.async_get("light.koogeek_ls1_20833f") assert entry.unique_id == "homekit-AAAA011111111111-7" helper = Helper( hass, "light.koogeek_ls1_20833f", pairing, accessories[0], config_entry ) state = await helper.poll_and_get_state() # Assert that the friendly name is detected correctly assert state.attributes["friendly_name"] == "Koogeek-LS1-20833F" # Assert that all optional features the LS1 supports are detected assert state.attributes["supported_features"] == ( SUPPORT_BRIGHTNESS | SUPPORT_COLOR ) device_registry = await hass.helpers.device_registry.async_get_registry() device = device_registry.async_get(entry.device_id) assert device.manufacturer == "Koogeek" assert device.name == "Koogeek-LS1-20833F" assert device.model == "LS1" assert device.sw_version == "2.2.15" assert device.via_device_id is None
[ "async", "def", "test_koogeek_ls1_setup", "(", "hass", ")", ":", "accessories", "=", "await", "setup_accessories_from_file", "(", "hass", ",", "\"koogeek_ls1.json\"", ")", "config_entry", ",", "pairing", "=", "await", "setup_test_accessories", "(", "hass", ",", "accessories", ")", "entity_registry", "=", "await", "hass", ".", "helpers", ".", "entity_registry", ".", "async_get_registry", "(", ")", "# Assert that the entity is correctly added to the entity registry", "entry", "=", "entity_registry", ".", "async_get", "(", "\"light.koogeek_ls1_20833f\"", ")", "assert", "entry", ".", "unique_id", "==", "\"homekit-AAAA011111111111-7\"", "helper", "=", "Helper", "(", "hass", ",", "\"light.koogeek_ls1_20833f\"", ",", "pairing", ",", "accessories", "[", "0", "]", ",", "config_entry", ")", "state", "=", "await", "helper", ".", "poll_and_get_state", "(", ")", "# Assert that the friendly name is detected correctly", "assert", "state", ".", "attributes", "[", "\"friendly_name\"", "]", "==", "\"Koogeek-LS1-20833F\"", "# Assert that all optional features the LS1 supports are detected", "assert", "state", ".", "attributes", "[", "\"supported_features\"", "]", "==", "(", "SUPPORT_BRIGHTNESS", "|", "SUPPORT_COLOR", ")", "device_registry", "=", "await", "hass", ".", "helpers", ".", "device_registry", ".", "async_get_registry", "(", ")", "device", "=", "device_registry", ".", "async_get", "(", "entry", ".", "device_id", ")", "assert", "device", ".", "manufacturer", "==", "\"Koogeek\"", "assert", "device", ".", "name", "==", "\"Koogeek-LS1-20833F\"", "assert", "device", ".", "model", "==", "\"LS1\"", "assert", "device", ".", "sw_version", "==", "\"2.2.15\"", "assert", "device", ".", "via_device_id", "is", "None" ]
[ 22, 0 ]
[ 53, 39 ]
python
en
['en', 'ig', 'en']
True
test_recover_from_failure
(hass, utcnow, failure_cls)
Test that entity actually recovers from a network connection drop. See https://github.com/home-assistant/core/issues/18949
Test that entity actually recovers from a network connection drop.
async def test_recover_from_failure(hass, utcnow, failure_cls): """ Test that entity actually recovers from a network connection drop. See https://github.com/home-assistant/core/issues/18949 """ accessories = await setup_accessories_from_file(hass, "koogeek_ls1.json") config_entry, pairing = await setup_test_accessories(hass, accessories) helper = Helper( hass, "light.koogeek_ls1_20833f", pairing, accessories[0], config_entry ) # Set light state on fake device to off helper.characteristics[LIGHT_ON].set_value(False) # Test that entity starts off in a known state state = await helper.poll_and_get_state() assert state.state == "off" # Set light state on fake device to on helper.characteristics[LIGHT_ON].set_value(True) # Test that entity remains in the same state if there is a network error next_update = dt_util.utcnow() + timedelta(seconds=60) with mock.patch.object(FakePairing, "get_characteristics") as get_char: get_char.side_effect = failure_cls("Disconnected") state = await helper.poll_and_get_state() assert state.state == "off" chars = get_char.call_args[0][0] assert set(chars) == {(1, 8), (1, 9), (1, 10), (1, 11)} # Test that entity changes state when network error goes away next_update += timedelta(seconds=60) async_fire_time_changed(hass, next_update) await hass.async_block_till_done() state = await helper.poll_and_get_state() assert state.state == "on"
[ "async", "def", "test_recover_from_failure", "(", "hass", ",", "utcnow", ",", "failure_cls", ")", ":", "accessories", "=", "await", "setup_accessories_from_file", "(", "hass", ",", "\"koogeek_ls1.json\"", ")", "config_entry", ",", "pairing", "=", "await", "setup_test_accessories", "(", "hass", ",", "accessories", ")", "helper", "=", "Helper", "(", "hass", ",", "\"light.koogeek_ls1_20833f\"", ",", "pairing", ",", "accessories", "[", "0", "]", ",", "config_entry", ")", "# Set light state on fake device to off", "helper", ".", "characteristics", "[", "LIGHT_ON", "]", ".", "set_value", "(", "False", ")", "# Test that entity starts off in a known state", "state", "=", "await", "helper", ".", "poll_and_get_state", "(", ")", "assert", "state", ".", "state", "==", "\"off\"", "# Set light state on fake device to on", "helper", ".", "characteristics", "[", "LIGHT_ON", "]", ".", "set_value", "(", "True", ")", "# Test that entity remains in the same state if there is a network error", "next_update", "=", "dt_util", ".", "utcnow", "(", ")", "+", "timedelta", "(", "seconds", "=", "60", ")", "with", "mock", ".", "patch", ".", "object", "(", "FakePairing", ",", "\"get_characteristics\"", ")", "as", "get_char", ":", "get_char", ".", "side_effect", "=", "failure_cls", "(", "\"Disconnected\"", ")", "state", "=", "await", "helper", ".", "poll_and_get_state", "(", ")", "assert", "state", ".", "state", "==", "\"off\"", "chars", "=", "get_char", ".", "call_args", "[", "0", "]", "[", "0", "]", "assert", "set", "(", "chars", ")", "==", "{", "(", "1", ",", "8", ")", ",", "(", "1", ",", "9", ")", ",", "(", "1", ",", "10", ")", ",", "(", "1", ",", "11", ")", "}", "# Test that entity changes state when network error goes away", "next_update", "+=", "timedelta", "(", "seconds", "=", "60", ")", "async_fire_time_changed", "(", "hass", ",", "next_update", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "await", "helper", ".", "poll_and_get_state", "(", ")", "assert", "state", ".", "state", "==", "\"on\"" ]
[ 57, 0 ]
[ 97, 30 ]
python
en
['en', 'error', 'th']
False
problem3_4
(mon, day, year)
Takes date such as July 17, 2016 and write it as 7/17/2016
Takes date such as July 17, 2016 and write it as 7/17/2016
def problem3_4(mon, day, year): """ Takes date such as July 17, 2016 and write it as 7/17/2016 """ month_mapping = {'January':1, "Febuary":2, "March":3, "April":4, "May" : 5, "June" : 6, "July" : 7, "August" : 8, "September" : 9, "October":10, "November":11, "December":12 } print('{}/{}/{}'.format(month_mapping[mon], day, year))
[ "def", "problem3_4", "(", "mon", ",", "day", ",", "year", ")", ":", "month_mapping", "=", "{", "'January'", ":", "1", ",", "\"Febuary\"", ":", "2", ",", "\"March\"", ":", "3", ",", "\"April\"", ":", "4", ",", "\"May\"", ":", "5", ",", "\"June\"", ":", "6", ",", "\"July\"", ":", "7", ",", "\"August\"", ":", "8", ",", "\"September\"", ":", "9", ",", "\"October\"", ":", "10", ",", "\"November\"", ":", "11", ",", "\"December\"", ":", "12", "}", "print", "(", "'{}/{}/{}'", ".", "format", "(", "month_mapping", "[", "mon", "]", ",", "day", ",", "year", ")", ")" ]
[ 23, 0 ]
[ 38, 59 ]
python
en
['en', 'en', 'en']
True
test_mqtt_abort_if_existing_entry
(hass, mqtt_mock)
Check MQTT flow aborts when an entry already exist.
Check MQTT flow aborts when an entry already exist.
async def test_mqtt_abort_if_existing_entry(hass, mqtt_mock): """Check MQTT flow aborts when an entry already exist.""" MockConfigEntry(domain="tasmota").add_to_hass(hass) result = await hass.config_entries.flow.async_init( "tasmota", context={"source": "mqtt"} ) assert result["type"] == "abort" assert result["reason"] == "single_instance_allowed"
[ "async", "def", "test_mqtt_abort_if_existing_entry", "(", "hass", ",", "mqtt_mock", ")", ":", "MockConfigEntry", "(", "domain", "=", "\"tasmota\"", ")", ".", "add_to_hass", "(", "hass", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "\"tasmota\"", ",", "context", "=", "{", "\"source\"", ":", "\"mqtt\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"single_instance_allowed\"" ]
[ 6, 0 ]
[ 15, 56 ]
python
en
['en', 'en', 'en']
True
test_mqtt_abort_invalid_topic
(hass, mqtt_mock)
Check MQTT flow aborts if discovery topic is invalid.
Check MQTT flow aborts if discovery topic is invalid.
async def test_mqtt_abort_invalid_topic(hass, mqtt_mock): """Check MQTT flow aborts if discovery topic is invalid.""" discovery_info = Message("", "", 0, False, subscribed_topic="custom_prefix/##") result = await hass.config_entries.flow.async_init( "tasmota", context={"source": "mqtt"}, data=discovery_info ) assert result["type"] == "abort" assert result["reason"] == "invalid_discovery_info"
[ "async", "def", "test_mqtt_abort_invalid_topic", "(", "hass", ",", "mqtt_mock", ")", ":", "discovery_info", "=", "Message", "(", "\"\"", ",", "\"\"", ",", "0", ",", "False", ",", "subscribed_topic", "=", "\"custom_prefix/##\"", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "\"tasmota\"", ",", "context", "=", "{", "\"source\"", ":", "\"mqtt\"", "}", ",", "data", "=", "discovery_info", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"invalid_discovery_info\"" ]
[ 18, 0 ]
[ 25, 55 ]
python
en
['en', 'en', 'en']
True
test_mqtt_setup
(hass, mqtt_mock)
Test we can finish a config flow through MQTT with custom prefix.
Test we can finish a config flow through MQTT with custom prefix.
async def test_mqtt_setup(hass, mqtt_mock) -> None: """Test we can finish a config flow through MQTT with custom prefix.""" discovery_info = Message("", "", 0, False, subscribed_topic="custom_prefix/123/#") result = await hass.config_entries.flow.async_init( "tasmota", context={"source": "mqtt"}, data=discovery_info ) assert result["type"] == "form" result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) assert result["type"] == "create_entry" assert result["result"].data == { "discovery_prefix": "custom_prefix/123", }
[ "async", "def", "test_mqtt_setup", "(", "hass", ",", "mqtt_mock", ")", "->", "None", ":", "discovery_info", "=", "Message", "(", "\"\"", ",", "\"\"", ",", "0", ",", "False", ",", "subscribed_topic", "=", "\"custom_prefix/123/#\"", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "\"tasmota\"", ",", "context", "=", "{", "\"source\"", ":", "\"mqtt\"", "}", ",", "data", "=", "discovery_info", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result", "[", "\"result\"", "]", ".", "data", "==", "{", "\"discovery_prefix\"", ":", "\"custom_prefix/123\"", ",", "}" ]
[ 28, 0 ]
[ 41, 5 ]
python
en
['en', 'en', 'en']
True
test_user_setup
(hass, mqtt_mock)
Test we can finish a config flow.
Test we can finish a config flow.
async def test_user_setup(hass, mqtt_mock): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( "tasmota", context={"source": "user"} ) assert result["type"] == "form" result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) assert result["type"] == "create_entry" assert result["result"].data == { "discovery_prefix": "tasmota/discovery", }
[ "async", "def", "test_user_setup", "(", "hass", ",", "mqtt_mock", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "\"tasmota\"", ",", "context", "=", "{", "\"source\"", ":", "\"user\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result", "[", "\"result\"", "]", ".", "data", "==", "{", "\"discovery_prefix\"", ":", "\"tasmota/discovery\"", ",", "}" ]
[ 44, 0 ]
[ 56, 5 ]
python
en
['en', 'en', 'en']
True
test_user_setup_advanced
(hass, mqtt_mock)
Test we can finish a config flow.
Test we can finish a config flow.
async def test_user_setup_advanced(hass, mqtt_mock): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( "tasmota", context={"source": "user", "show_advanced_options": True} ) assert result["type"] == "form" result = await hass.config_entries.flow.async_configure( result["flow_id"], {"discovery_prefix": "test_tasmota/discovery"} ) assert result["type"] == "create_entry" assert result["result"].data == { "discovery_prefix": "test_tasmota/discovery", }
[ "async", "def", "test_user_setup_advanced", "(", "hass", ",", "mqtt_mock", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "\"tasmota\"", ",", "context", "=", "{", "\"source\"", ":", "\"user\"", ",", "\"show_advanced_options\"", ":", "True", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"discovery_prefix\"", ":", "\"test_tasmota/discovery\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result", "[", "\"result\"", "]", ".", "data", "==", "{", "\"discovery_prefix\"", ":", "\"test_tasmota/discovery\"", ",", "}" ]
[ 59, 0 ]
[ 73, 5 ]
python
en
['en', 'en', 'en']
True
test_user_setup_advanced_strip_wildcard
(hass, mqtt_mock)
Test we can finish a config flow.
Test we can finish a config flow.
async def test_user_setup_advanced_strip_wildcard(hass, mqtt_mock): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( "tasmota", context={"source": "user", "show_advanced_options": True} ) assert result["type"] == "form" result = await hass.config_entries.flow.async_configure( result["flow_id"], {"discovery_prefix": "test_tasmota/discovery/#"} ) assert result["type"] == "create_entry" assert result["result"].data == { "discovery_prefix": "test_tasmota/discovery", }
[ "async", "def", "test_user_setup_advanced_strip_wildcard", "(", "hass", ",", "mqtt_mock", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "\"tasmota\"", ",", "context", "=", "{", "\"source\"", ":", "\"user\"", ",", "\"show_advanced_options\"", ":", "True", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"discovery_prefix\"", ":", "\"test_tasmota/discovery/#\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result", "[", "\"result\"", "]", ".", "data", "==", "{", "\"discovery_prefix\"", ":", "\"test_tasmota/discovery\"", ",", "}" ]
[ 76, 0 ]
[ 90, 5 ]
python
en
['en', 'en', 'en']
True
test_user_setup_invalid_topic_prefix
(hass, mqtt_mock)
Test abort on invalid discovery topic.
Test abort on invalid discovery topic.
async def test_user_setup_invalid_topic_prefix(hass, mqtt_mock): """Test abort on invalid discovery topic.""" result = await hass.config_entries.flow.async_init( "tasmota", context={"source": "user", "show_advanced_options": True} ) assert result["type"] == "form" result = await hass.config_entries.flow.async_configure( result["flow_id"], {"discovery_prefix": "tasmota/config/##"} ) assert result["type"] == "form" assert result["errors"]["base"] == "invalid_discovery_topic"
[ "async", "def", "test_user_setup_invalid_topic_prefix", "(", "hass", ",", "mqtt_mock", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "\"tasmota\"", ",", "context", "=", "{", "\"source\"", ":", "\"user\"", ",", "\"show_advanced_options\"", ":", "True", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"discovery_prefix\"", ":", "\"tasmota/config/##\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"errors\"", "]", "[", "\"base\"", "]", "==", "\"invalid_discovery_topic\"" ]
[ 93, 0 ]
[ 105, 64 ]
python
en
['en', 'en', 'en']
True
test_user_single_instance
(hass, mqtt_mock)
Test we only allow a single config flow.
Test we only allow a single config flow.
async def test_user_single_instance(hass, mqtt_mock): """Test we only allow a single config flow.""" MockConfigEntry(domain="tasmota").add_to_hass(hass) result = await hass.config_entries.flow.async_init( "tasmota", context={"source": "user"} ) assert result["type"] == "abort" assert result["reason"] == "single_instance_allowed"
[ "async", "def", "test_user_single_instance", "(", "hass", ",", "mqtt_mock", ")", ":", "MockConfigEntry", "(", "domain", "=", "\"tasmota\"", ")", ".", "add_to_hass", "(", "hass", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "\"tasmota\"", ",", "context", "=", "{", "\"source\"", ":", "\"user\"", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"abort\"", "assert", "result", "[", "\"reason\"", "]", "==", "\"single_instance_allowed\"" ]
[ 108, 0 ]
[ 116, 56 ]
python
en
['en', 'en', 'en']
True
setup
(hass, config)
Set up the IDTECK proximity card component.
Set up the IDTECK proximity card component.
def setup(hass, config): """Set up the IDTECK proximity card component.""" conf = config[DOMAIN] for unit in conf: host = unit[CONF_HOST] port = unit[CONF_PORT] name = unit[CONF_NAME] try: reader = IdteckReader(hass, host, port, name) reader.connect() hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, reader.stop) except OSError as error: _LOGGER.error("Error creating %s. %s", name, error) return False return True
[ "def", "setup", "(", "hass", ",", "config", ")", ":", "conf", "=", "config", "[", "DOMAIN", "]", "for", "unit", "in", "conf", ":", "host", "=", "unit", "[", "CONF_HOST", "]", "port", "=", "unit", "[", "CONF_PORT", "]", "name", "=", "unit", "[", "CONF_NAME", "]", "try", ":", "reader", "=", "IdteckReader", "(", "hass", ",", "host", ",", "port", ",", "name", ")", "reader", ".", "connect", "(", ")", "hass", ".", "bus", ".", "listen_once", "(", "EVENT_HOMEASSISTANT_STOP", ",", "reader", ".", "stop", ")", "except", "OSError", "as", "error", ":", "_LOGGER", ".", "error", "(", "\"Error creating %s. %s\"", ",", "name", ",", "error", ")", "return", "False", "return", "True" ]
[ 39, 0 ]
[ 55, 15 ]
python
en
['en', 'en', 'en']
True
IdteckReader.__init__
(self, hass, host, port, name)
Initialize the reader.
Initialize the reader.
def __init__(self, hass, host, port, name): """Initialize the reader.""" self.hass = hass self._host = host self._port = port self._name = name self._connection = None
[ "def", "__init__", "(", "self", ",", "hass", ",", "host", ",", "port", ",", "name", ")", ":", "self", ".", "hass", "=", "hass", "self", ".", "_host", "=", "host", "self", ".", "_port", "=", "port", "self", ".", "_name", "=", "name", "self", ".", "_connection", "=", "None" ]
[ 61, 4 ]
[ 67, 31 ]
python
en
['en', 'en', 'en']
True
IdteckReader.connect
(self)
Connect to the reader.
Connect to the reader.
def connect(self): """Connect to the reader.""" self._connection = rfk101py(self._host, self._port, self._callback)
[ "def", "connect", "(", "self", ")", ":", "self", ".", "_connection", "=", "rfk101py", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_callback", ")" ]
[ 69, 4 ]
[ 72, 75 ]
python
en
['en', 'en', 'en']
True
IdteckReader._callback
(self, card)
Send a keycard event message into Home Assistant whenever a card is read.
Send a keycard event message into Home Assistant whenever a card is read.
def _callback(self, card): """Send a keycard event message into Home Assistant whenever a card is read.""" self.hass.bus.fire( EVENT_IDTECK_PROX_KEYCARD, {"card": card, "name": self._name} )
[ "def", "_callback", "(", "self", ",", "card", ")", ":", "self", ".", "hass", ".", "bus", ".", "fire", "(", "EVENT_IDTECK_PROX_KEYCARD", ",", "{", "\"card\"", ":", "card", ",", "\"name\"", ":", "self", ".", "_name", "}", ")" ]
[ 74, 4 ]
[ 78, 9 ]
python
en
['en', 'en', 'en']
True
IdteckReader.stop
(self)
Close resources.
Close resources.
def stop(self): """Close resources.""" if self._connection: self._connection.close() self._connection = None
[ "def", "stop", "(", "self", ")", ":", "if", "self", ".", "_connection", ":", "self", ".", "_connection", ".", "close", "(", ")", "self", ".", "_connection", "=", "None" ]
[ 80, 4 ]
[ 84, 35 ]
python
en
['en', 'la', 'en']
False
TestFrame.test_node_number
(self)
Test if node number same as defined
Test if node number same as defined
def test_node_number(self): """Test if node number same as defined""" for backend_name in backends_to_test: frame = build_frame(backend_name=backend_name) self.assertEqual(STATIC_NODE_NUM, len( frame.static_nodes), backend_name) self.assertEqual(DYNAMIC_NODE_NUM, len( frame.dynamic_nodes), backend_name)
[ "def", "test_node_number", "(", "self", ")", ":", "for", "backend_name", "in", "backends_to_test", ":", "frame", "=", "build_frame", "(", "backend_name", "=", "backend_name", ")", "self", ".", "assertEqual", "(", "STATIC_NODE_NUM", ",", "len", "(", "frame", ".", "static_nodes", ")", ",", "backend_name", ")", "self", ".", "assertEqual", "(", "DYNAMIC_NODE_NUM", ",", "len", "(", "frame", ".", "dynamic_nodes", ")", ",", "backend_name", ")" ]
[ 50, 4 ]
[ 58, 51 ]
python
da
['pt', 'da', 'en']
False
TestFrame.test_node_accessing
(self)
Test node accessing correct
Test node accessing correct
def test_node_accessing(self): """Test node accessing correct""" for backend_name in backends_to_test: frame = build_frame(backend_name=backend_name) # accessing for 1st node for both static and dynamic node static_node: StaticNode = frame.static_nodes[0] dynamic_node: DynamicNode = frame.dynamic_nodes[0] static_node.a2 = 10 dynamic_node.b1 = 12.34 self.assertEqual( 10, static_node.a2, msg="a2 attribute should be 10 for 1st static node") self.assertAlmostEqual( 12.34, dynamic_node.b1, 2, msg="b1 attribute should be 12.34 for 1st dynamic node") # check if values correct for multiple nodes for node in frame.static_nodes: node.a2 = node.index # check if the value correct for node in frame.static_nodes: self.assertEqual(node.index, node.a2, msg=f"static node.a2 should be {node.index}") # check slice accessing static_node.a1[1] = 12 static_node.a1[0] = 20 self.assertListEqual([20, 12], list( static_node.a1[:]), msg="static node's a1 should be [20, 12]") self.assertEqual( 20, static_node.a1[0], msg="1st slot of a1 should be 20") self.assertEqual( 12, static_node.a1[1], msg="2nd slot of a1 should be 12") # set again with another way static_node.a1[(1, 0)] = (22, 11) self.assertListEqual([11, 22], list( static_node.a1[:]), msg="static node a1 should be [11, 22]") # another way # NOTE: additional value will be ignored static_node.a1[:] = (1, 2, 3) self.assertListEqual([1, 2], list( static_node.a1[:]), msg="static node a1 should be [1, 2")
[ "def", "test_node_accessing", "(", "self", ")", ":", "for", "backend_name", "in", "backends_to_test", ":", "frame", "=", "build_frame", "(", "backend_name", "=", "backend_name", ")", "# accessing for 1st node for both static and dynamic node", "static_node", ":", "StaticNode", "=", "frame", ".", "static_nodes", "[", "0", "]", "dynamic_node", ":", "DynamicNode", "=", "frame", ".", "dynamic_nodes", "[", "0", "]", "static_node", ".", "a2", "=", "10", "dynamic_node", ".", "b1", "=", "12.34", "self", ".", "assertEqual", "(", "10", ",", "static_node", ".", "a2", ",", "msg", "=", "\"a2 attribute should be 10 for 1st static node\"", ")", "self", ".", "assertAlmostEqual", "(", "12.34", ",", "dynamic_node", ".", "b1", ",", "2", ",", "msg", "=", "\"b1 attribute should be 12.34 for 1st dynamic node\"", ")", "# check if values correct for multiple nodes", "for", "node", "in", "frame", ".", "static_nodes", ":", "node", ".", "a2", "=", "node", ".", "index", "# check if the value correct", "for", "node", "in", "frame", ".", "static_nodes", ":", "self", ".", "assertEqual", "(", "node", ".", "index", ",", "node", ".", "a2", ",", "msg", "=", "f\"static node.a2 should be {node.index}\"", ")", "# check slice accessing", "static_node", ".", "a1", "[", "1", "]", "=", "12", "static_node", ".", "a1", "[", "0", "]", "=", "20", "self", ".", "assertListEqual", "(", "[", "20", ",", "12", "]", ",", "list", "(", "static_node", ".", "a1", "[", ":", "]", ")", ",", "msg", "=", "\"static node's a1 should be [20, 12]\"", ")", "self", ".", "assertEqual", "(", "20", ",", "static_node", ".", "a1", "[", "0", "]", ",", "msg", "=", "\"1st slot of a1 should be 20\"", ")", "self", ".", "assertEqual", "(", "12", ",", "static_node", ".", "a1", "[", "1", "]", ",", "msg", "=", "\"2nd slot of a1 should be 12\"", ")", "# set again with another way", "static_node", ".", "a1", "[", "(", "1", ",", "0", ")", "]", "=", "(", "22", ",", "11", ")", "self", ".", "assertListEqual", "(", "[", "11", ",", "22", "]", ",", "list", "(", "static_node", ".", "a1", "[", ":", "]", ")", ",", "msg", "=", "\"static node a1 should be [11, 22]\"", ")", "# another way", "# NOTE: additional value will be ignored", "static_node", ".", "a1", "[", ":", "]", "=", "(", "1", ",", "2", ",", "3", ")", "self", ".", "assertListEqual", "(", "[", "1", ",", "2", "]", ",", "list", "(", "static_node", ".", "a1", "[", ":", "]", ")", ",", "msg", "=", "\"static node a1 should be [1, 2\"", ")" ]
[ 60, 4 ]
[ 109, 73 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass, config)
Set up the Bravia TV component.
Set up the Bravia TV component.
async def async_setup(hass, config): """Set up the Bravia TV component.""" return True
[ "async", "def", "async_setup", "(", "hass", ",", "config", ")", ":", "return", "True" ]
[ 12, 0 ]
[ 14, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry)
Set up a config entry.
Set up a config entry.
async def async_setup_entry(hass, config_entry): """Set up a config entry.""" host = config_entry.data[CONF_HOST] mac = config_entry.data[CONF_MAC] undo_listener = config_entry.add_update_listener(update_listener) hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][config_entry.entry_id] = { BRAVIARC: BraviaRC(host, mac), UNDO_UPDATE_LISTENER: undo_listener, } for component in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(config_entry, component) ) return True
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ")", ":", "host", "=", "config_entry", ".", "data", "[", "CONF_HOST", "]", "mac", "=", "config_entry", ".", "data", "[", "CONF_MAC", "]", "undo_listener", "=", "config_entry", ".", "add_update_listener", "(", "update_listener", ")", "hass", ".", "data", ".", "setdefault", "(", "DOMAIN", ",", "{", "}", ")", "hass", ".", "data", "[", "DOMAIN", "]", "[", "config_entry", ".", "entry_id", "]", "=", "{", "BRAVIARC", ":", "BraviaRC", "(", "host", ",", "mac", ")", ",", "UNDO_UPDATE_LISTENER", ":", "undo_listener", ",", "}", "for", "component", "in", "PLATFORMS", ":", "hass", ".", "async_create_task", "(", "hass", ".", "config_entries", ".", "async_forward_entry_setup", "(", "config_entry", ",", "component", ")", ")", "return", "True" ]
[ 17, 0 ]
[ 35, 15 ]
python
en
['en', 'en', 'en']
True
async_unload_entry
(hass, config_entry)
Unload a config entry.
Unload a config entry.
async def async_unload_entry(hass, config_entry): """Unload a config entry.""" unload_ok = all( await asyncio.gather( *[ hass.config_entries.async_forward_entry_unload(config_entry, component) for component in PLATFORMS ] ) ) hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]() if unload_ok: hass.data[DOMAIN].pop(config_entry.entry_id) return unload_ok
[ "async", "def", "async_unload_entry", "(", "hass", ",", "config_entry", ")", ":", "unload_ok", "=", "all", "(", "await", "asyncio", ".", "gather", "(", "*", "[", "hass", ".", "config_entries", ".", "async_forward_entry_unload", "(", "config_entry", ",", "component", ")", "for", "component", "in", "PLATFORMS", "]", ")", ")", "hass", ".", "data", "[", "DOMAIN", "]", "[", "config_entry", ".", "entry_id", "]", "[", "UNDO_UPDATE_LISTENER", "]", "(", ")", "if", "unload_ok", ":", "hass", ".", "data", "[", "DOMAIN", "]", ".", "pop", "(", "config_entry", ".", "entry_id", ")", "return", "unload_ok" ]
[ 38, 0 ]
[ 54, 20 ]
python
en
['en', 'es', 'en']
True
update_listener
(hass, config_entry)
Handle options update.
Handle options update.
async def update_listener(hass, config_entry): """Handle options update.""" await hass.config_entries.async_reload(config_entry.entry_id)
[ "async", "def", "update_listener", "(", "hass", ",", "config_entry", ")", ":", "await", "hass", ".", "config_entries", ".", "async_reload", "(", "config_entry", ".", "entry_id", ")" ]
[ 57, 0 ]
[ 59, 65 ]
python
en
['en', 'nl', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Dovado sensor platform.
Set up the Dovado sensor platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Dovado sensor platform.""" dovado = hass.data[DOVADO_DOMAIN] entities = [] for sensor in config[CONF_SENSORS]: entities.append(DovadoSensor(dovado, sensor)) add_entities(entities)
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "dovado", "=", "hass", ".", "data", "[", "DOVADO_DOMAIN", "]", "entities", "=", "[", "]", "for", "sensor", "in", "config", "[", "CONF_SENSORS", "]", ":", "entities", ".", "append", "(", "DovadoSensor", "(", "dovado", ",", "sensor", ")", ")", "add_entities", "(", "entities", ")" ]
[ 44, 0 ]
[ 52, 26 ]
python
en
['en', 'pt', 'en']
True
DovadoSensor.__init__
(self, data, sensor)
Initialize the sensor.
Initialize the sensor.
def __init__(self, data, sensor): """Initialize the sensor.""" self._data = data self._sensor = sensor self._state = self._compute_state()
[ "def", "__init__", "(", "self", ",", "data", ",", "sensor", ")", ":", "self", ".", "_data", "=", "data", "self", ".", "_sensor", "=", "sensor", "self", ".", "_state", "=", "self", ".", "_compute_state", "(", ")" ]
[ 58, 4 ]
[ 62, 43 ]
python
en
['en', 'en', 'en']
True
DovadoSensor._compute_state
(self)
Compute the state of the sensor.
Compute the state of the sensor.
def _compute_state(self): """Compute the state of the sensor.""" state = self._data.state.get(SENSORS[self._sensor][0]) if self._sensor == SENSOR_NETWORK: match = re.search(r"\((.+)\)", state) return match.group(1) if match else None if self._sensor == SENSOR_SIGNAL: try: return int(state.split()[0]) except ValueError: return None if self._sensor == SENSOR_SMS_UNREAD: return int(state) if self._sensor in [SENSOR_UPLOAD, SENSOR_DOWNLOAD]: return round(float(state) / 1e6, 1) return state
[ "def", "_compute_state", "(", "self", ")", ":", "state", "=", "self", ".", "_data", ".", "state", ".", "get", "(", "SENSORS", "[", "self", ".", "_sensor", "]", "[", "0", "]", ")", "if", "self", ".", "_sensor", "==", "SENSOR_NETWORK", ":", "match", "=", "re", ".", "search", "(", "r\"\\((.+)\\)\"", ",", "state", ")", "return", "match", ".", "group", "(", "1", ")", "if", "match", "else", "None", "if", "self", ".", "_sensor", "==", "SENSOR_SIGNAL", ":", "try", ":", "return", "int", "(", "state", ".", "split", "(", ")", "[", "0", "]", ")", "except", "ValueError", ":", "return", "None", "if", "self", ".", "_sensor", "==", "SENSOR_SMS_UNREAD", ":", "return", "int", "(", "state", ")", "if", "self", ".", "_sensor", "in", "[", "SENSOR_UPLOAD", ",", "SENSOR_DOWNLOAD", "]", ":", "return", "round", "(", "float", "(", "state", ")", "/", "1e6", ",", "1", ")", "return", "state" ]
[ 64, 4 ]
[ 79, 20 ]
python
en
['en', 'en', 'en']
True
DovadoSensor.update
(self)
Update sensor values.
Update sensor values.
def update(self): """Update sensor values.""" self._data.update() self._state = self._compute_state()
[ "def", "update", "(", "self", ")", ":", "self", ".", "_data", ".", "update", "(", ")", "self", ".", "_state", "=", "self", ".", "_compute_state", "(", ")" ]
[ 81, 4 ]
[ 84, 43 ]
python
en
['en', 'nl', 'en']
True
DovadoSensor.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return f"{self._data.name} {SENSORS[self._sensor][1]}"
[ "def", "name", "(", "self", ")", ":", "return", "f\"{self._data.name} {SENSORS[self._sensor][1]}\"" ]
[ 87, 4 ]
[ 89, 62 ]
python
en
['en', 'mi', 'en']
True
DovadoSensor.state
(self)
Return the sensor state.
Return the sensor state.
def state(self): """Return the sensor state.""" return self._state
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "_state" ]
[ 92, 4 ]
[ 94, 26 ]
python
en
['en', 'bs', 'en']
True
DovadoSensor.icon
(self)
Return the icon for the sensor.
Return the icon for the sensor.
def icon(self): """Return the icon for the sensor.""" return SENSORS[self._sensor][3]
[ "def", "icon", "(", "self", ")", ":", "return", "SENSORS", "[", "self", ".", "_sensor", "]", "[", "3", "]" ]
[ 97, 4 ]
[ 99, 39 ]
python
en
['en', 'en', 'en']
True
DovadoSensor.unit_of_measurement
(self)
Return the unit of measurement.
Return the unit of measurement.
def unit_of_measurement(self): """Return the unit of measurement.""" return SENSORS[self._sensor][2]
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "SENSORS", "[", "self", ".", "_sensor", "]", "[", "2", "]" ]
[ 102, 4 ]
[ 104, 39 ]
python
en
['en', 'la', 'en']
True
DovadoSensor.device_state_attributes
(self)
Return the state attributes.
Return the state attributes.
def device_state_attributes(self): """Return the state attributes.""" return {k: v for k, v in self._data.state.items() if k not in ["date", "time"]}
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "{", "k", ":", "v", "for", "k", ",", "v", "in", "self", ".", "_data", ".", "state", ".", "items", "(", ")", "if", "k", "not", "in", "[", "\"date\"", ",", "\"time\"", "]", "}" ]
[ 107, 4 ]
[ 109, 87 ]
python
en
['en', 'en', 'en']
True
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up cover(s) for Slide platform.
Set up cover(s) for Slide platform.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up cover(s) for Slide platform.""" if discovery_info is None: return entities = [] for slide in hass.data[DOMAIN][SLIDES].values(): _LOGGER.debug("Setting up Slide entity: %s", slide) entities.append(SlideCover(hass.data[DOMAIN][API], slide)) async_add_entities(entities)
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "discovery_info", "is", "None", ":", "return", "entities", "=", "[", "]", "for", "slide", "in", "hass", ".", "data", "[", "DOMAIN", "]", "[", "SLIDES", "]", ".", "values", "(", ")", ":", "_LOGGER", ".", "debug", "(", "\"Setting up Slide entity: %s\"", ",", "slide", ")", "entities", ".", "append", "(", "SlideCover", "(", "hass", ".", "data", "[", "DOMAIN", "]", "[", "API", "]", ",", "slide", ")", ")", "async_add_entities", "(", "entities", ")" ]
[ 19, 0 ]
[ 31, 32 ]
python
en
['en', 'da', 'en']
True
SlideCover.__init__
(self, api, slide)
Initialize the cover.
Initialize the cover.
def __init__(self, api, slide): """Initialize the cover.""" self._api = api self._slide = slide self._id = slide["id"] self._unique_id = slide["mac"] self._name = slide["name"] self._invert = slide["invert"]
[ "def", "__init__", "(", "self", ",", "api", ",", "slide", ")", ":", "self", ".", "_api", "=", "api", "self", ".", "_slide", "=", "slide", "self", ".", "_id", "=", "slide", "[", "\"id\"", "]", "self", ".", "_unique_id", "=", "slide", "[", "\"mac\"", "]", "self", ".", "_name", "=", "slide", "[", "\"name\"", "]", "self", ".", "_invert", "=", "slide", "[", "\"invert\"", "]" ]
[ 37, 4 ]
[ 44, 38 ]
python
en
['en', 'en', 'en']
True
SlideCover.unique_id
(self)
Return the device unique id.
Return the device unique id.
def unique_id(self): """Return the device unique id.""" return self._unique_id
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_unique_id" ]
[ 47, 4 ]
[ 49, 30 ]
python
en
['en', 'it', 'en']
True
SlideCover.name
(self)
Return the device name.
Return the device name.
def name(self): """Return the device name.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 52, 4 ]
[ 54, 25 ]
python
en
['en', 'en', 'en']
True