Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
test_entity_state
(hass, device_factory)
Tests the state attributes properly match the sensor types.
Tests the state attributes properly match the sensor types.
async def test_entity_state(hass, device_factory): """Tests the state attributes properly match the sensor types.""" device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100}) await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) state = hass.states.get("sensor.sensor_1_ba...
[ "async", "def", "test_entity_state", "(", "hass", ",", "device_factory", ")", ":", "device", "=", "device_factory", "(", "\"Sensor 1\"", ",", "[", "Capability", ".", "battery", "]", ",", "{", "Attribute", ".", "battery", ":", "100", "}", ")", "await", "set...
[ 34, 0 ]
[ 41, 76 ]
python
en
['en', 'en', 'en']
True
test_entity_three_axis_state
(hass, device_factory)
Tests the state attributes properly match the three axis types.
Tests the state attributes properly match the three axis types.
async def test_entity_three_axis_state(hass, device_factory): """Tests the state attributes properly match the three axis types.""" device = device_factory( "Three Axis", [Capability.three_axis], {Attribute.three_axis: [100, 75, 25]} ) await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) ...
[ "async", "def", "test_entity_three_axis_state", "(", "hass", ",", "device_factory", ")", ":", "device", "=", "device_factory", "(", "\"Three Axis\"", ",", "[", "Capability", ".", "three_axis", "]", ",", "{", "Attribute", ".", "three_axis", ":", "[", "100", ","...
[ 44, 0 ]
[ 58, 81 ]
python
en
['en', 'en', 'en']
True
test_entity_three_axis_invalid_state
(hass, device_factory)
Tests the state attributes properly match the three axis types.
Tests the state attributes properly match the three axis types.
async def test_entity_three_axis_invalid_state(hass, device_factory): """Tests the state attributes properly match the three axis types.""" device = device_factory( "Three Axis", [Capability.three_axis], {Attribute.three_axis: []} ) await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) ...
[ "async", "def", "test_entity_three_axis_invalid_state", "(", "hass", ",", "device_factory", ")", ":", "device", "=", "device_factory", "(", "\"Three Axis\"", ",", "[", "Capability", ".", "three_axis", "]", ",", "{", "Attribute", ".", "three_axis", ":", "[", "]",...
[ 61, 0 ]
[ 72, 39 ]
python
en
['en', 'en', 'en']
True
test_entity_and_device_attributes
(hass, device_factory)
Test the attributes of the entity are correct.
Test the attributes of the entity are correct.
async def test_entity_and_device_attributes(hass, device_factory): """Test the attributes of the entity are correct.""" # Arrange device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100}) entity_registry = await hass.helpers.entity_registry.async_get_registry() device_regis...
[ "async", "def", "test_entity_and_device_attributes", "(", "hass", ",", "device_factory", ")", ":", "# Arrange", "device", "=", "device_factory", "(", "\"Sensor 1\"", ",", "[", "Capability", ".", "battery", "]", ",", "{", "Attribute", ".", "battery", ":", "100", ...
[ 75, 0 ]
[ 91, 46 ]
python
en
['en', 'en', 'en']
True
test_update_from_signal
(hass, device_factory)
Test the binary_sensor updates when receiving a signal.
Test the binary_sensor updates when receiving a signal.
async def test_update_from_signal(hass, device_factory): """Test the binary_sensor updates when receiving a signal.""" # Arrange device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100}) await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) device.status.apply_attribu...
[ "async", "def", "test_update_from_signal", "(", "hass", ",", "device_factory", ")", ":", "# Arrange", "device", "=", "device_factory", "(", "\"Sensor 1\"", ",", "[", "Capability", ".", "battery", "]", ",", "{", "Attribute", ".", "battery", ":", "100", "}", "...
[ 94, 0 ]
[ 108, 30 ]
python
en
['en', 'lb', 'en']
True
test_unload_config_entry
(hass, device_factory)
Test the binary_sensor is removed when the config entry is unloaded.
Test the binary_sensor is removed when the config entry is unloaded.
async def test_unload_config_entry(hass, device_factory): """Test the binary_sensor is removed when the config entry is unloaded.""" # Arrange device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100}) config_entry = await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) ...
[ "async", "def", "test_unload_config_entry", "(", "hass", ",", "device_factory", ")", ":", "# Arrange", "device", "=", "device_factory", "(", "\"Sensor 1\"", ",", "[", "Capability", ".", "battery", "]", ",", "{", "Attribute", ".", "battery", ":", "100", "}", ...
[ 111, 0 ]
[ 119, 57 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass, config)
Start a discovery service.
Start a discovery service.
async def async_setup(hass, config): """Start a discovery service.""" logger = logging.getLogger(__name__) netdisco = NetworkDiscovery() already_discovered = set() if DOMAIN in config: # Platforms ignore by config ignored_platforms = config[DOMAIN][CONF_IGNORE] # Optional ...
[ "async", "def", "async_setup", "(", "hass", ",", "config", ")", ":", "logger", "=", "logging", ".", "getLogger", "(", "__name__", ")", "netdisco", "=", "NetworkDiscovery", "(", ")", "already_discovered", "=", "set", "(", ")", "if", "DOMAIN", "in", "config"...
[ 122, 0 ]
[ 215, 15 ]
python
en
['en', 'en', 'en']
True
_discover
(netdisco, zeroconf_instance)
Discover devices.
Discover devices.
def _discover(netdisco, zeroconf_instance): """Discover devices.""" results = [] try: netdisco.scan(zeroconf_instance=zeroconf_instance) for disc in netdisco.discover(): for service in netdisco.get_info(disc): results.append((disc, service)) finally: ...
[ "def", "_discover", "(", "netdisco", ",", "zeroconf_instance", ")", ":", "results", "=", "[", "]", "try", ":", "netdisco", ".", "scan", "(", "zeroconf_instance", "=", "zeroconf_instance", ")", "for", "disc", "in", "netdisco", ".", "discover", "(", ")", ":"...
[ 218, 0 ]
[ 231, 18 ]
python
en
['da', 'en', 'en']
False
naive_test
(args)
run naive integration test
run naive integration test
def naive_test(args): '''run naive integration test''' to_remove = ['tuner_search_space.json', 'tuner_result.txt', 'assessor_result.txt'] to_remove = list(map(lambda file: osp.join(NAIVE_TEST_CONFIG_DIR, file), to_remove)) remove_files(to_remove) proc = subprocess.run(['nnictl', 'create', '--config...
[ "def", "naive_test", "(", "args", ")", ":", "to_remove", "=", "[", "'tuner_search_space.json'", ",", "'tuner_result.txt'", ",", "'assessor_result.txt'", "]", "to_remove", "=", "list", "(", "map", "(", "lambda", "file", ":", "osp", ".", "join", "(", "NAIVE_TEST...
[ 18, 0 ]
[ 73, 37 ]
python
en
['en', 'fil', 'en']
True
stop_experiment_test
(args)
Test `nnictl stop` command, including `nnictl stop exp_id` and `nnictl stop all`. Simple `nnictl stop` is not tested here since it is used in all other test code
Test `nnictl stop` command, including `nnictl stop exp_id` and `nnictl stop all`. Simple `nnictl stop` is not tested here since it is used in all other test code
def stop_experiment_test(args): config_file = args.config '''Test `nnictl stop` command, including `nnictl stop exp_id` and `nnictl stop all`. Simple `nnictl stop` is not tested here since it is used in all other test code''' subprocess.run(['nnictl', 'create', '--config', config_file, '--port', '8080']...
[ "def", "stop_experiment_test", "(", "args", ")", ":", "config_file", "=", "args", ".", "config", "subprocess", ".", "run", "(", "[", "'nnictl'", ",", "'create'", ",", "'--config'", ",", "config_file", ",", "'--port'", ",", "'8080'", "]", ",", "check", "=",...
[ 75, 0 ]
[ 102, 108 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass: HomeAssistant, config: dict)
Set up the flume component.
Set up the flume component.
async def async_setup(hass: HomeAssistant, config: dict): """Set up the flume component.""" hass.data.setdefault(DOMAIN, {}) return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "dict", ")", ":", "hass", ".", "data", ".", "setdefault", "(", "DOMAIN", ",", "{", "}", ")", "return", "True" ]
[ 31, 0 ]
[ 34, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass: HomeAssistant, entry: ConfigEntry)
Set up flume from a config entry.
Set up flume from a config entry.
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up flume from a config entry.""" config = entry.data username = config[CONF_USERNAME] password = config[CONF_PASSWORD] client_id = config[CONF_CLIENT_ID] client_secret = config[CONF_CLIENT_SECRET] flume_token_full...
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "config", "=", "entry", ".", "data", "username", "=", "config", "[", "CONF_USERNAME", "]", "password", "=", "config", "[", "CONF_PASSWORD", "]...
[ 37, 0 ]
[ 86, 15 ]
python
en
['en', 'en', 'en']
True
async_unload_entry
(hass: HomeAssistant, entry: ConfigEntry)
Unload a config entry.
Unload a config entry.
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" unload_ok = all( await asyncio.gather( *[ hass.config_entries.async_forward_entry_unload(entry, component) for component in PLATFORMS ] ) ...
[ "async", "def", "async_unload_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "unload_ok", "=", "all", "(", "await", "asyncio", ".", "gather", "(", "*", "[", "hass", ".", "config_entries", ".", "async_forward_entry_unload...
[ 89, 0 ]
[ 105, 20 ]
python
en
['en', 'es', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the N26 sensor platform.
Set up the N26 sensor platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the N26 sensor platform.""" if discovery_info is None: return api_list = hass.data[DOMAIN][DATA] sensor_entities = [] for api_data in api_list: sensor_entities.append(N26Account(api_data)) for c...
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "discovery_info", "is", "None", ":", "return", "api_list", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "DATA", "]", "sens...
[ 25, 0 ]
[ 42, 33 ]
python
en
['en', 'da', 'en']
True
N26Account.__init__
(self, api_data)
Initialize a N26 balance account.
Initialize a N26 balance account.
def __init__(self, api_data) -> None: """Initialize a N26 balance account.""" self._data = api_data self._iban = self._data.balance["iban"]
[ "def", "__init__", "(", "self", ",", "api_data", ")", "->", "None", ":", "self", ".", "_data", "=", "api_data", "self", ".", "_iban", "=", "self", ".", "_data", ".", "balance", "[", "\"iban\"", "]" ]
[ 52, 4 ]
[ 55, 47 ]
python
en
['en', 'en', 'en']
True
N26Account.update
(self)
Get the current balance and currency for the account.
Get the current balance and currency for the account.
def update(self) -> None: """Get the current balance and currency for the account.""" self._data.update_account()
[ "def", "update", "(", "self", ")", "->", "None", ":", "self", ".", "_data", ".", "update_account", "(", ")" ]
[ 57, 4 ]
[ 59, 35 ]
python
en
['en', 'en', 'en']
True
N26Account.unique_id
(self)
Return the unique ID of the entity.
Return the unique ID of the entity.
def unique_id(self): """Return the unique ID of the entity.""" return self._iban[-4:]
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_iban", "[", "-", "4", ":", "]" ]
[ 62, 4 ]
[ 64, 30 ]
python
en
['en', 'en', 'en']
True
N26Account.name
(self)
Friendly name of the sensor.
Friendly name of the sensor.
def name(self) -> str: """Friendly name of the sensor.""" return f"n26_{self._iban[-4:]}"
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "f\"n26_{self._iban[-4:]}\"" ]
[ 67, 4 ]
[ 69, 39 ]
python
en
['en', 'en', 'en']
True
N26Account.state
(self)
Return the balance of the account as state.
Return the balance of the account as state.
def state(self) -> float: """Return the balance of the account as state.""" if self._data.balance is None: return None return self._data.balance.get("availableBalance")
[ "def", "state", "(", "self", ")", "->", "float", ":", "if", "self", ".", "_data", ".", "balance", "is", "None", ":", "return", "None", "return", "self", ".", "_data", ".", "balance", ".", "get", "(", "\"availableBalance\"", ")" ]
[ 72, 4 ]
[ 77, 57 ]
python
en
['en', 'en', 'en']
True
N26Account.unit_of_measurement
(self)
Use the currency as unit of measurement.
Use the currency as unit of measurement.
def unit_of_measurement(self) -> str: """Use the currency as unit of measurement.""" if self._data.balance is None: return None return self._data.balance.get("currency")
[ "def", "unit_of_measurement", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_data", ".", "balance", "is", "None", ":", "return", "None", "return", "self", ".", "_data", ".", "balance", ".", "get", "(", "\"currency\"", ")" ]
[ 80, 4 ]
[ 85, 49 ]
python
en
['en', 'en', 'en']
True
N26Account.device_state_attributes
(self)
Additional attributes of the sensor.
Additional attributes of the sensor.
def device_state_attributes(self) -> dict: """Additional attributes of the sensor.""" attributes = { ATTR_IBAN: self._data.balance.get("iban"), ATTR_BANK_BALANCE: self._data.balance.get("bankBalance"), ATTR_USABLE_BALANCE: self._data.balance.get("usableBalance"), ...
[ "def", "device_state_attributes", "(", "self", ")", "->", "dict", ":", "attributes", "=", "{", "ATTR_IBAN", ":", "self", ".", "_data", ".", "balance", ".", "get", "(", "\"iban\"", ")", ",", "ATTR_BANK_BALANCE", ":", "self", ".", "_data", ".", "balance", ...
[ 88, 4 ]
[ 111, 25 ]
python
en
['en', 'en', 'en']
True
N26Account.icon
(self)
Set the icon for the sensor.
Set the icon for the sensor.
def icon(self) -> str: """Set the icon for the sensor.""" return ICON_ACCOUNT
[ "def", "icon", "(", "self", ")", "->", "str", ":", "return", "ICON_ACCOUNT" ]
[ 114, 4 ]
[ 116, 27 ]
python
en
['en', 'en', 'en']
True
N26Card.__init__
(self, api_data, card)
Initialize a N26 card.
Initialize a N26 card.
def __init__(self, api_data, card) -> None: """Initialize a N26 card.""" self._data = api_data self._account_name = api_data.balance["iban"][-4:] self._card = card
[ "def", "__init__", "(", "self", ",", "api_data", ",", "card", ")", "->", "None", ":", "self", ".", "_data", "=", "api_data", "self", ".", "_account_name", "=", "api_data", ".", "balance", "[", "\"iban\"", "]", "[", "-", "4", ":", "]", "self", ".", ...
[ 122, 4 ]
[ 126, 25 ]
python
co
['en', 'co', 'it']
False
N26Card.update
(self)
Get the current balance and currency for the account.
Get the current balance and currency for the account.
def update(self) -> None: """Get the current balance and currency for the account.""" self._data.update_cards() self._card = self._data.card(self._card["id"], self._card)
[ "def", "update", "(", "self", ")", "->", "None", ":", "self", ".", "_data", ".", "update_cards", "(", ")", "self", ".", "_card", "=", "self", ".", "_data", ".", "card", "(", "self", ".", "_card", "[", "\"id\"", "]", ",", "self", ".", "_card", ")"...
[ 128, 4 ]
[ 131, 66 ]
python
en
['en', 'en', 'en']
True
N26Card.unique_id
(self)
Return the unique ID of the entity.
Return the unique ID of the entity.
def unique_id(self): """Return the unique ID of the entity.""" return self._card["id"]
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_card", "[", "\"id\"", "]" ]
[ 134, 4 ]
[ 136, 31 ]
python
en
['en', 'en', 'en']
True
N26Card.name
(self)
Friendly name of the sensor.
Friendly name of the sensor.
def name(self) -> str: """Friendly name of the sensor.""" return f"{self._account_name.lower()}_card_{self._card['id']}"
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "f\"{self._account_name.lower()}_card_{self._card['id']}\"" ]
[ 139, 4 ]
[ 141, 70 ]
python
en
['en', 'en', 'en']
True
N26Card.state
(self)
Return the balance of the account as state.
Return the balance of the account as state.
def state(self) -> float: """Return the balance of the account as state.""" return self._card["status"]
[ "def", "state", "(", "self", ")", "->", "float", ":", "return", "self", ".", "_card", "[", "\"status\"", "]" ]
[ 144, 4 ]
[ 146, 35 ]
python
en
['en', 'en', 'en']
True
N26Card.device_state_attributes
(self)
Additional attributes of the sensor.
Additional attributes of the sensor.
def device_state_attributes(self) -> dict: """Additional attributes of the sensor.""" attributes = { "apple_pay_eligible": self._card.get("applePayEligible"), "card_activated": timestamp_ms_to_date(self._card.get("cardActivated")), "card_product": self._card.get("card...
[ "def", "device_state_attributes", "(", "self", ")", "->", "dict", ":", "attributes", "=", "{", "\"apple_pay_eligible\"", ":", "self", ".", "_card", ".", "get", "(", "\"applePayEligible\"", ")", ",", "\"card_activated\"", ":", "timestamp_ms_to_date", "(", "self", ...
[ 149, 4 ]
[ 180, 25 ]
python
en
['en', 'en', 'en']
True
N26Card.icon
(self)
Set the icon for the sensor.
Set the icon for the sensor.
def icon(self) -> str: """Set the icon for the sensor.""" return ICON_CARD
[ "def", "icon", "(", "self", ")", "->", "str", ":", "return", "ICON_CARD" ]
[ 183, 4 ]
[ 185, 24 ]
python
en
['en', 'en', 'en']
True
N26Space.__init__
(self, api_data, space)
Initialize a N26 space.
Initialize a N26 space.
def __init__(self, api_data, space) -> None: """Initialize a N26 space.""" self._data = api_data self._space = space
[ "def", "__init__", "(", "self", ",", "api_data", ",", "space", ")", "->", "None", ":", "self", ".", "_data", "=", "api_data", "self", ".", "_space", "=", "space" ]
[ 191, 4 ]
[ 194, 27 ]
python
en
['en', 'en', 'en']
True
N26Space.update
(self)
Get the current balance and currency for the account.
Get the current balance and currency for the account.
def update(self) -> None: """Get the current balance and currency for the account.""" self._data.update_spaces() self._space = self._data.space(self._space["id"], self._space)
[ "def", "update", "(", "self", ")", "->", "None", ":", "self", ".", "_data", ".", "update_spaces", "(", ")", "self", ".", "_space", "=", "self", ".", "_data", ".", "space", "(", "self", ".", "_space", "[", "\"id\"", "]", ",", "self", ".", "_space", ...
[ 196, 4 ]
[ 199, 70 ]
python
en
['en', 'en', 'en']
True
N26Space.unique_id
(self)
Return the unique ID of the entity.
Return the unique ID of the entity.
def unique_id(self): """Return the unique ID of the entity.""" return f"space_{self._data.balance['iban'][-4:]}_{self._space['name'].lower()}"
[ "def", "unique_id", "(", "self", ")", ":", "return", "f\"space_{self._data.balance['iban'][-4:]}_{self._space['name'].lower()}\"" ]
[ 202, 4 ]
[ 204, 87 ]
python
en
['en', 'en', 'en']
True
N26Space.name
(self)
Friendly name of the sensor.
Friendly name of the sensor.
def name(self) -> str: """Friendly name of the sensor.""" return self._space["name"]
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_space", "[", "\"name\"", "]" ]
[ 207, 4 ]
[ 209, 34 ]
python
en
['en', 'en', 'en']
True
N26Space.state
(self)
Return the balance of the account as state.
Return the balance of the account as state.
def state(self) -> float: """Return the balance of the account as state.""" return self._space["balance"]["availableBalance"]
[ "def", "state", "(", "self", ")", "->", "float", ":", "return", "self", ".", "_space", "[", "\"balance\"", "]", "[", "\"availableBalance\"", "]" ]
[ 212, 4 ]
[ 214, 57 ]
python
en
['en', 'en', 'en']
True
N26Space.unit_of_measurement
(self)
Use the currency as unit of measurement.
Use the currency as unit of measurement.
def unit_of_measurement(self) -> str: """Use the currency as unit of measurement.""" return self._space["balance"]["currency"]
[ "def", "unit_of_measurement", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_space", "[", "\"balance\"", "]", "[", "\"currency\"", "]" ]
[ 217, 4 ]
[ 219, 49 ]
python
en
['en', 'en', 'en']
True
N26Space.device_state_attributes
(self)
Additional attributes of the sensor.
Additional attributes of the sensor.
def device_state_attributes(self) -> dict: """Additional attributes of the sensor.""" goal_value = "" if "goal" in self._space: goal_value = self._space.get("goal").get("amount") attributes = { "name": self._space.get("name"), "goal": goal_value, ...
[ "def", "device_state_attributes", "(", "self", ")", "->", "dict", ":", "goal_value", "=", "\"\"", "if", "\"goal\"", "in", "self", ".", "_space", ":", "goal_value", "=", "self", ".", "_space", ".", "get", "(", "\"goal\"", ")", ".", "get", "(", "\"amount\"...
[ 222, 4 ]
[ 238, 25 ]
python
en
['en', 'en', 'en']
True
N26Space.icon
(self)
Set the icon for the sensor.
Set the icon for the sensor.
def icon(self) -> str: """Set the icon for the sensor.""" return ICON_SPACE
[ "def", "icon", "(", "self", ")", "->", "str", ":", "return", "ICON_SPACE" ]
[ 241, 4 ]
[ 243, 25 ]
python
en
['en', 'en', 'en']
True
PoolSenseConfigFlow.__init__
(self)
Initialize PoolSense config flow.
Initialize PoolSense config flow.
def __init__(self): """Initialize PoolSense config flow."""
[ "def", "__init__", "(", "self", ")", ":" ]
[ 21, 4 ]
[ 22, 47 ]
python
en
['de', 'en', 'en']
True
PoolSenseConfigFlow.async_step_user
(self, user_input=None)
Handle the initial step.
Handle the initial step.
async def async_step_user(self, user_input=None): """Handle the initial step.""" errors = {} if user_input is not None: await self.async_set_unique_id(user_input[CONF_EMAIL]) self._abort_if_unique_id_configured() _LOGGER.debug( "Configuring u...
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "await", "self", ".", "async_set_unique_id", "(", "user_input", "[", "CONF_EMAIL", "]", ")", ...
[ 24, 4 ]
[ 61, 9 ]
python
en
['en', 'en', 'en']
True
setup
(hass, config)
Set up the Zabbix component.
Set up the Zabbix component.
def setup(hass, config): """Set up the Zabbix component.""" conf = config[DOMAIN] protocol = "https" if conf[CONF_SSL] else "http" url = urljoin(f"{protocol}://{conf[CONF_HOST]}", conf[CONF_PATH]) username = conf.get(CONF_USERNAME) password = conf.get(CONF_PASSWORD) publish_states_host = ...
[ "def", "setup", "(", "hass", ",", "config", ")", ":", "conf", "=", "config", "[", "DOMAIN", "]", "protocol", "=", "\"https\"", "if", "conf", "[", "CONF_SSL", "]", "else", "\"http\"", "url", "=", "urljoin", "(", "f\"{protocol}://{conf[CONF_HOST]}\"", ",", "...
[ 66, 0 ]
[ 158, 15 ]
python
en
['en', 'ny', 'en']
True
ZabbixThread.__init__
(self, hass, zabbix_sender, event_to_metrics)
Initialize the listener.
Initialize the listener.
def __init__(self, hass, zabbix_sender, event_to_metrics): """Initialize the listener.""" threading.Thread.__init__(self, name="Zabbix") self.queue = queue.Queue() self.zabbix_sender = zabbix_sender self.event_to_metrics = event_to_metrics self.write_errors = 0 se...
[ "def", "__init__", "(", "self", ",", "hass", ",", "zabbix_sender", ",", "event_to_metrics", ")", ":", "threading", ".", "Thread", ".", "__init__", "(", "self", ",", "name", "=", "\"Zabbix\"", ")", "self", ".", "queue", "=", "queue", ".", "Queue", "(", ...
[ 166, 4 ]
[ 175, 32 ]
python
en
['en', 'en', 'en']
True
ZabbixThread.setup
(self, hass)
Set up the thread and start it.
Set up the thread and start it.
def setup(self, hass): """Set up the thread and start it.""" hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, self._shutdown) self.start() _LOGGER.debug("Started publishing state changes to Zabbix")
[ "def", "setup", "(", "self", ",", "hass", ")", ":", "hass", ".", "bus", ".", "listen", "(", "EVENT_STATE_CHANGED", ",", "self", ".", "_event_listener", ")", "hass", ".", "bus", ".", "listen_once", "(", "EVENT_HOMEASSISTANT_STOP", ",", "self", ".", "_shutdo...
[ 177, 4 ]
[ 182, 67 ]
python
en
['en', 'en', 'en']
True
ZabbixThread._shutdown
(self, event)
Shut down the thread.
Shut down the thread.
def _shutdown(self, event): """Shut down the thread.""" self.queue.put(None) self.join()
[ "def", "_shutdown", "(", "self", ",", "event", ")", ":", "self", ".", "queue", ".", "put", "(", "None", ")", "self", ".", "join", "(", ")" ]
[ 184, 4 ]
[ 187, 19 ]
python
en
['en', 'gd', 'en']
True
ZabbixThread._event_listener
(self, event)
Listen for new messages on the bus and queue them for Zabbix.
Listen for new messages on the bus and queue them for Zabbix.
def _event_listener(self, event): """Listen for new messages on the bus and queue them for Zabbix.""" item = (time.monotonic(), event) self.queue.put(item)
[ "def", "_event_listener", "(", "self", ",", "event", ")", ":", "item", "=", "(", "time", ".", "monotonic", "(", ")", ",", "event", ")", "self", ".", "queue", ".", "put", "(", "item", ")" ]
[ 190, 4 ]
[ 193, 28 ]
python
en
['en', 'en', 'en']
True
ZabbixThread.get_metrics
(self)
Return a batch of events formatted for writing.
Return a batch of events formatted for writing.
def get_metrics(self): """Return a batch of events formatted for writing.""" queue_seconds = QUEUE_BACKLOG_SECONDS + self.MAX_TRIES * RETRY_DELAY count = 0 metrics = [] dropped = 0 try: while len(metrics) < BATCH_BUFFER_SIZE and not self.shutdown: ...
[ "def", "get_metrics", "(", "self", ")", ":", "queue_seconds", "=", "QUEUE_BACKLOG_SECONDS", "+", "self", ".", "MAX_TRIES", "*", "RETRY_DELAY", "count", "=", "0", "metrics", "=", "[", "]", "dropped", "=", "0", "try", ":", "while", "len", "(", "metrics", "...
[ 195, 4 ]
[ 231, 29 ]
python
en
['en', 'en', 'en']
True
ZabbixThread.write_to_zabbix
(self, metrics)
Write preprocessed events to zabbix, with retry.
Write preprocessed events to zabbix, with retry.
def write_to_zabbix(self, metrics): """Write preprocessed events to zabbix, with retry.""" for retry in range(self.MAX_TRIES + 1): try: self.zabbix_sender.send(metrics) if self.write_errors: _LOGGER.error("Resumed, lost %d events", self.w...
[ "def", "write_to_zabbix", "(", "self", ",", "metrics", ")", ":", "for", "retry", "in", "range", "(", "self", ".", "MAX_TRIES", "+", "1", ")", ":", "try", ":", "self", ".", "zabbix_sender", ".", "send", "(", "metrics", ")", "if", "self", ".", "write_e...
[ 233, 4 ]
[ 252, 53 ]
python
en
['en', 'en', 'en']
True
ZabbixThread.run
(self)
Process incoming events.
Process incoming events.
def run(self): """Process incoming events.""" while not self.shutdown: count, metrics = self.get_metrics() if metrics: self.write_to_zabbix(metrics) for _ in range(count): self.queue.task_done()
[ "def", "run", "(", "self", ")", ":", "while", "not", "self", ".", "shutdown", ":", "count", ",", "metrics", "=", "self", ".", "get_metrics", "(", ")", "if", "metrics", ":", "self", ".", "write_to_zabbix", "(", "metrics", ")", "for", "_", "in", "range...
[ 254, 4 ]
[ 261, 38 ]
python
en
['en', 'en', 'en']
True
async_update_entity
(hass: HomeAssistant, entity_id: str)
Trigger an update for an entity.
Trigger an update for an entity.
async def async_update_entity(hass: HomeAssistant, entity_id: str) -> None: """Trigger an update for an entity.""" domain = entity_id.split(".", 1)[0] entity_comp = hass.data.get(DATA_INSTANCES, {}).get(domain) if entity_comp is None: logging.getLogger(__name__).warning( "Forced upd...
[ "async", "def", "async_update_entity", "(", "hass", ":", "HomeAssistant", ",", "entity_id", ":", "str", ")", "->", "None", ":", "domain", "=", "entity_id", ".", "split", "(", "\".\"", ",", "1", ")", "[", "0", "]", "entity_comp", "=", "hass", ".", "data...
[ 33, 0 ]
[ 52, 48 ]
python
en
['br', 'en', 'en']
True
EntityComponent.__init__
( self, logger: logging.Logger, domain: str, hass: HomeAssistant, scan_interval: timedelta = DEFAULT_SCAN_INTERVAL, )
Initialize an entity component.
Initialize an entity component.
def __init__( self, logger: logging.Logger, domain: str, hass: HomeAssistant, scan_interval: timedelta = DEFAULT_SCAN_INTERVAL, ): """Initialize an entity component.""" self.logger = logger self.hass = hass self.domain = domain self.sca...
[ "def", "__init__", "(", "self", ",", "logger", ":", "logging", ".", "Logger", ",", "domain", ":", "str", ",", "hass", ":", "HomeAssistant", ",", "scan_interval", ":", "timedelta", "=", "DEFAULT_SCAN_INTERVAL", ",", ")", ":", "self", ".", "logger", "=", "...
[ 65, 4 ]
[ 86, 63 ]
python
en
['en', 'en', 'en']
True
EntityComponent.entities
(self)
Return an iterable that returns all entities.
Return an iterable that returns all entities.
def entities(self) -> Iterable[entity.Entity]: """Return an iterable that returns all entities.""" return chain.from_iterable( platform.entities.values() for platform in self._platforms.values() )
[ "def", "entities", "(", "self", ")", "->", "Iterable", "[", "entity", ".", "Entity", "]", ":", "return", "chain", ".", "from_iterable", "(", "platform", ".", "entities", ".", "values", "(", ")", "for", "platform", "in", "self", ".", "_platforms", ".", ...
[ 89, 4 ]
[ 93, 9 ]
python
en
['en', 'en', 'en']
True
EntityComponent.get_entity
(self, entity_id: str)
Get an entity.
Get an entity.
def get_entity(self, entity_id: str) -> Optional[entity.Entity]: """Get an entity.""" for platform in self._platforms.values(): entity_obj = platform.entities.get(entity_id) if entity_obj is not None: return entity_obj return None
[ "def", "get_entity", "(", "self", ",", "entity_id", ":", "str", ")", "->", "Optional", "[", "entity", ".", "Entity", "]", ":", "for", "platform", "in", "self", ".", "_platforms", ".", "values", "(", ")", ":", "entity_obj", "=", "platform", ".", "entiti...
[ 95, 4 ]
[ 101, 19 ]
python
br
['br', 'cy', 'en']
False
EntityComponent.setup
(self, config: ConfigType)
Set up a full entity component. This doesn't block the executor to protect from deadlocks.
Set up a full entity component.
def setup(self, config: ConfigType) -> None: """Set up a full entity component. This doesn't block the executor to protect from deadlocks. """ self.hass.add_job(self.async_setup(config))
[ "def", "setup", "(", "self", ",", "config", ":", "ConfigType", ")", "->", "None", ":", "self", ".", "hass", ".", "add_job", "(", "self", ".", "async_setup", "(", "config", ")", ")" ]
[ 103, 4 ]
[ 108, 51 ]
python
en
['en', 'en', 'en']
True
EntityComponent.async_setup
(self, config: ConfigType)
Set up a full entity component. Loads the platforms from the config and will listen for supported discovered platforms. This method must be run in the event loop.
Set up a full entity component.
async def async_setup(self, config: ConfigType) -> None: """Set up a full entity component. Loads the platforms from the config and will listen for supported discovered platforms. This method must be run in the event loop. """ self.config = config # Look in con...
[ "async", "def", "async_setup", "(", "self", ",", "config", ":", "ConfigType", ")", "->", "None", ":", "self", ".", "config", "=", "config", "# Look in config for Domain, Domain 2, Domain 3 etc and load them", "for", "p_type", ",", "p_config", "in", "config_per_platfor...
[ 110, 4 ]
[ 134, 9 ]
python
en
['en', 'en', 'en']
True
EntityComponent.async_setup_entry
(self, config_entry: ConfigEntry)
Set up a config entry.
Set up a config entry.
async def async_setup_entry(self, config_entry: ConfigEntry) -> bool: """Set up a config entry.""" platform_type = config_entry.domain platform = await async_prepare_setup_platform( self.hass, # In future PR we should make hass_config part of the constructor #...
[ "async", "def", "async_setup_entry", "(", "self", ",", "config_entry", ":", "ConfigEntry", ")", "->", "bool", ":", "platform_type", "=", "config_entry", ".", "domain", "platform", "=", "await", "async_prepare_setup_platform", "(", "self", ".", "hass", ",", "# In...
[ 136, 4 ]
[ 162, 73 ]
python
en
['en', 'en', 'en']
True
EntityComponent.async_unload_entry
(self, config_entry: ConfigEntry)
Unload a config entry.
Unload a config entry.
async def async_unload_entry(self, config_entry: ConfigEntry) -> bool: """Unload a config entry.""" key = config_entry.entry_id platform = self._platforms.pop(key, None) if platform is None: raise ValueError("Config entry was never loaded!") await platform.async_re...
[ "async", "def", "async_unload_entry", "(", "self", ",", "config_entry", ":", "ConfigEntry", ")", "->", "bool", ":", "key", "=", "config_entry", ".", "entry_id", "platform", "=", "self", ".", "_platforms", ".", "pop", "(", "key", ",", "None", ")", "if", "...
[ 164, 4 ]
[ 174, 19 ]
python
en
['en', 'es', 'en']
True
EntityComponent.async_extract_from_service
( self, service_call: ServiceCall, expand_group: bool = True )
Extract all known and available entities from a service call. Will return an empty list if entities specified but unknown. This method must be run in the event loop.
Extract all known and available entities from a service call.
async def async_extract_from_service( self, service_call: ServiceCall, expand_group: bool = True ) -> List[entity.Entity]: """Extract all known and available entities from a service call. Will return an empty list if entities specified but unknown. This method must be run in the ev...
[ "async", "def", "async_extract_from_service", "(", "self", ",", "service_call", ":", "ServiceCall", ",", "expand_group", ":", "bool", "=", "True", ")", "->", "List", "[", "entity", ".", "Entity", "]", ":", "return", "await", "service", ".", "async_extract_enti...
[ 176, 4 ]
[ 187, 9 ]
python
en
['en', 'en', 'en']
True
EntityComponent.async_register_entity_service
( self, name: str, schema: Union[Dict[str, Any], vol.Schema], func: str, required_features: Optional[List[int]] = None, )
Register an entity service.
Register an entity service.
def async_register_entity_service( self, name: str, schema: Union[Dict[str, Any], vol.Schema], func: str, required_features: Optional[List[int]] = None, ) -> None: """Register an entity service.""" if isinstance(schema, dict): schema = cv.make_enti...
[ "def", "async_register_entity_service", "(", "self", ",", "name", ":", "str", ",", "schema", ":", "Union", "[", "Dict", "[", "str", ",", "Any", "]", ",", "vol", ".", "Schema", "]", ",", "func", ":", "str", ",", "required_features", ":", "Optional", "["...
[ 190, 4 ]
[ 207, 84 ]
python
en
['en', 'en', 'en']
True
EntityComponent.async_setup_platform
( self, platform_type: str, platform_config: ConfigType, discovery_info: Optional[DiscoveryInfoType] = None, )
Set up a platform for this component.
Set up a platform for this component.
async def async_setup_platform( self, platform_type: str, platform_config: ConfigType, discovery_info: Optional[DiscoveryInfoType] = None, ) -> None: """Set up a platform for this component.""" if self.config is None: raise RuntimeError("async_setup needs ...
[ "async", "def", "async_setup_platform", "(", "self", ",", "platform_type", ":", "str", ",", "platform_config", ":", "ConfigType", ",", "discovery_info", ":", "Optional", "[", "DiscoveryInfoType", "]", "=", "None", ",", ")", "->", "None", ":", "if", "self", "...
[ 209, 4 ]
[ 241, 9 ]
python
en
['en', 'en', 'en']
True
EntityComponent._async_reset
(self)
Remove entities and reset the entity component to initial values. This method must be run in the event loop.
Remove entities and reset the entity component to initial values.
async def _async_reset(self) -> None: """Remove entities and reset the entity component to initial values. This method must be run in the event loop. """ tasks = [] for key, platform in self._platforms.items(): if key == self.domain: tasks.append(pla...
[ "async", "def", "_async_reset", "(", "self", ")", "->", "None", ":", "tasks", "=", "[", "]", "for", "key", ",", "platform", "in", "self", ".", "_platforms", ".", "items", "(", ")", ":", "if", "key", "==", "self", ".", "domain", ":", "tasks", ".", ...
[ 243, 4 ]
[ 260, 26 ]
python
en
['en', 'en', 'en']
True
EntityComponent.async_remove_entity
(self, entity_id: str)
Remove an entity managed by one of the platforms.
Remove an entity managed by one of the platforms.
async def async_remove_entity(self, entity_id: str) -> None: """Remove an entity managed by one of the platforms.""" found = None for platform in self._platforms.values(): if entity_id in platform.entities: found = platform break if found: ...
[ "async", "def", "async_remove_entity", "(", "self", ",", "entity_id", ":", "str", ")", "->", "None", ":", "found", "=", "None", "for", "platform", "in", "self", ".", "_platforms", ".", "values", "(", ")", ":", "if", "entity_id", "in", "platform", ".", ...
[ 262, 4 ]
[ 272, 54 ]
python
en
['en', 'en', 'en']
True
EntityComponent.async_prepare_reload
(self, *, skip_reset: bool = False)
Prepare reloading this entity component. This method must be run in the event loop.
Prepare reloading this entity component.
async def async_prepare_reload(self, *, skip_reset: bool = False) -> Optional[dict]: """Prepare reloading this entity component. This method must be run in the event loop. """ try: conf = await conf_util.async_hass_config_yaml(self.hass) except HomeAssistantError as ...
[ "async", "def", "async_prepare_reload", "(", "self", ",", "*", ",", "skip_reset", ":", "bool", "=", "False", ")", "->", "Optional", "[", "dict", "]", ":", "try", ":", "conf", "=", "await", "conf_util", ".", "async_hass_config_yaml", "(", "self", ".", "ha...
[ 274, 4 ]
[ 297, 29 ]
python
en
['en', 'en', 'en']
True
EntityComponent._async_init_entity_platform
( self, platform_type: str, platform: Optional[ModuleType], scan_interval: Optional[timedelta] = None, entity_namespace: Optional[str] = None, )
Initialize an entity platform.
Initialize an entity platform.
def _async_init_entity_platform( self, platform_type: str, platform: Optional[ModuleType], scan_interval: Optional[timedelta] = None, entity_namespace: Optional[str] = None, ) -> EntityPlatform: """Initialize an entity platform.""" if scan_interval is None: ...
[ "def", "_async_init_entity_platform", "(", "self", ",", "platform_type", ":", "str", ",", "platform", ":", "Optional", "[", "ModuleType", "]", ",", "scan_interval", ":", "Optional", "[", "timedelta", "]", "=", "None", ",", "entity_namespace", ":", "Optional", ...
[ 300, 4 ]
[ 319, 9 ]
python
en
['en', 'pl', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up Homekit switches.
Set up Homekit switches.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up Homekit switches.""" hkid = config_entry.data["AccessoryPairingID"] conn = hass.data[KNOWN_DEVICES][hkid] @callback def async_add_service(service): entity_class = ENTITY_TYPES.get(service.short_type) if n...
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "hkid", "=", "config_entry", ".", "data", "[", "\"AccessoryPairingID\"", "]", "conn", "=", "hass", ".", "data", "[", "KNOWN_DEVICES", "]", "[", "hkid", ...
[ 105, 0 ]
[ 119, 40 ]
python
en
['en', 'sn', 'en']
True
HomeKitSwitch.get_characteristic_types
(self)
Define the homekit characteristics the entity cares about.
Define the homekit characteristics the entity cares about.
def get_characteristic_types(self): """Define the homekit characteristics the entity cares about.""" return [CharacteristicsTypes.ON, CharacteristicsTypes.OUTLET_IN_USE]
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "ON", ",", "CharacteristicsTypes", ".", "OUTLET_IN_USE", "]" ]
[ 23, 4 ]
[ 25, 76 ]
python
en
['en', 'en', 'en']
True
HomeKitSwitch.is_on
(self)
Return true if device is on.
Return true if device is on.
def is_on(self): """Return true if device is on.""" return self.service.value(CharacteristicsTypes.ON)
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "ON", ")" ]
[ 28, 4 ]
[ 30, 58 ]
python
en
['en', 'fy', 'en']
True
HomeKitSwitch.async_turn_on
(self, **kwargs)
Turn the specified switch on.
Turn the specified switch on.
async def async_turn_on(self, **kwargs): """Turn the specified switch on.""" await self.async_put_characteristics({CharacteristicsTypes.ON: True})
[ "async", "def", "async_turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "async_put_characteristics", "(", "{", "CharacteristicsTypes", ".", "ON", ":", "True", "}", ")" ]
[ 32, 4 ]
[ 34, 77 ]
python
en
['en', 'en', 'en']
True
HomeKitSwitch.async_turn_off
(self, **kwargs)
Turn the specified switch off.
Turn the specified switch off.
async def async_turn_off(self, **kwargs): """Turn the specified switch off.""" await self.async_put_characteristics({CharacteristicsTypes.ON: False})
[ "async", "def", "async_turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "async_put_characteristics", "(", "{", "CharacteristicsTypes", ".", "ON", ":", "False", "}", ")" ]
[ 36, 4 ]
[ 38, 78 ]
python
en
['en', 'en', 'en']
True
HomeKitSwitch.device_state_attributes
(self)
Return the optional state attributes.
Return the optional state attributes.
def device_state_attributes(self): """Return the optional state attributes.""" outlet_in_use = self.service.value(CharacteristicsTypes.OUTLET_IN_USE) if outlet_in_use is not None: return {OUTLET_IN_USE: outlet_in_use}
[ "def", "device_state_attributes", "(", "self", ")", ":", "outlet_in_use", "=", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "OUTLET_IN_USE", ")", "if", "outlet_in_use", "is", "not", "None", ":", "return", "{", "OUTLET_IN_USE", ":", "...
[ 41, 4 ]
[ 45, 49 ]
python
en
['en', 'en', 'en']
True
HomeKitValve.get_characteristic_types
(self)
Define the homekit characteristics the entity cares about.
Define the homekit characteristics the entity cares about.
def get_characteristic_types(self): """Define the homekit characteristics the entity cares about.""" return [ CharacteristicsTypes.ACTIVE, CharacteristicsTypes.IN_USE, CharacteristicsTypes.IS_CONFIGURED, CharacteristicsTypes.REMAINING_DURATION, ]
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "ACTIVE", ",", "CharacteristicsTypes", ".", "IN_USE", ",", "CharacteristicsTypes", ".", "IS_CONFIGURED", ",", "CharacteristicsTypes", ".", "REMAINING_DURATION", ",", ...
[ 51, 4 ]
[ 58, 9 ]
python
en
['en', 'en', 'en']
True
HomeKitValve.async_turn_on
(self, **kwargs)
Turn the specified valve on.
Turn the specified valve on.
async def async_turn_on(self, **kwargs): """Turn the specified valve on.""" await self.async_put_characteristics({CharacteristicsTypes.ACTIVE: True})
[ "async", "def", "async_turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "async_put_characteristics", "(", "{", "CharacteristicsTypes", ".", "ACTIVE", ":", "True", "}", ")" ]
[ 60, 4 ]
[ 62, 81 ]
python
en
['en', 'en', 'en']
True
HomeKitValve.async_turn_off
(self, **kwargs)
Turn the specified valve off.
Turn the specified valve off.
async def async_turn_off(self, **kwargs): """Turn the specified valve off.""" await self.async_put_characteristics({CharacteristicsTypes.ACTIVE: False})
[ "async", "def", "async_turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "await", "self", ".", "async_put_characteristics", "(", "{", "CharacteristicsTypes", ".", "ACTIVE", ":", "False", "}", ")" ]
[ 64, 4 ]
[ 66, 82 ]
python
en
['en', 'en', 'en']
True
HomeKitValve.icon
(self)
Return the icon.
Return the icon.
def icon(self) -> str: """Return the icon.""" return "mdi:water"
[ "def", "icon", "(", "self", ")", "->", "str", ":", "return", "\"mdi:water\"" ]
[ 69, 4 ]
[ 71, 26 ]
python
en
['en', 'sr', 'en']
True
HomeKitValve.is_on
(self)
Return true if device is on.
Return true if device is on.
def is_on(self): """Return true if device is on.""" return self.service.value(CharacteristicsTypes.ACTIVE)
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "ACTIVE", ")" ]
[ 74, 4 ]
[ 76, 62 ]
python
en
['en', 'fy', 'en']
True
HomeKitValve.device_state_attributes
(self)
Return the optional state attributes.
Return the optional state attributes.
def device_state_attributes(self): """Return the optional state attributes.""" attrs = {} in_use = self.service.value(CharacteristicsTypes.IN_USE) if in_use is not None: attrs[ATTR_IN_USE] = in_use == InUseValues.IN_USE is_configured = self.service.value(Characteris...
[ "def", "device_state_attributes", "(", "self", ")", ":", "attrs", "=", "{", "}", "in_use", "=", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "IN_USE", ")", "if", "in_use", "is", "not", "None", ":", "attrs", "[", "ATTR_IN_USE", ...
[ 79, 4 ]
[ 95, 20 ]
python
en
['en', 'en', 'en']
True
BaseChannel.send
(self, command, data)
Send command to Training Service. command: CommandType object. data: string payload. the message is sent synchronized.
Send command to Training Service. command: CommandType object. data: string payload. the message is sent synchronized.
def send(self, command, data): """Send command to Training Service. command: CommandType object. data: string payload. the message is sent synchronized. """ data["node"] = self.node_id data = json.dumps(data) data = data.encode('utf8') message = b'...
[ "def", "send", "(", "self", ",", "command", ",", "data", ")", ":", "data", "[", "\"node\"", "]", "=", "self", ".", "node_id", "data", "=", "json", ".", "dumps", "(", "data", ")", "data", "=", "data", ".", "encode", "(", "'utf8'", ")", "message", ...
[ 65, 4 ]
[ 75, 36 ]
python
en
['en', 'en', 'en']
True
BaseChannel.receive
(self)
Receive a command from Training Service. Returns a tuple of command (CommandType) and payload (str)
Receive a command from Training Service. Returns a tuple of command (CommandType) and payload (str)
def receive(self): """Receive a command from Training Service. Returns a tuple of command (CommandType) and payload (str) """ command = None data = None try: command_content = self.receive_queue.get(False) if command_content is not None: ...
[ "def", "receive", "(", "self", ")", ":", "command", "=", "None", "data", "=", "None", "try", ":", "command_content", "=", "self", ".", "receive_queue", ".", "get", "(", "False", ")", "if", "command_content", "is", "not", "None", ":", "if", "(", "len", ...
[ 83, 4 ]
[ 115, 28 ]
python
en
['en', 'en', 'en']
True
test_duplicate_error
(hass)
Test that errors are shown when duplicates are added.
Test that errors are shown when duplicates are added.
async def test_duplicate_error(hass): """Test that errors are shown when duplicates are added.""" conf = { CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc", } MockConfigEntry(domain=DOMAIN, unique_id="user@host.com", data=conf).add_to_hass( hass ) result = await ...
[ "async", "def", "test_duplicate_error", "(", "hass", ")", ":", "conf", "=", "{", "CONF_USERNAME", ":", "\"user@host.com\"", ",", "CONF_PASSWORD", ":", "\"123abc\"", ",", "}", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "unique_id", "=", "\"user@host.co...
[ 12, 0 ]
[ 28, 51 ]
python
en
['en', 'en', 'en']
True
test_invalid_credentials
(hass)
Test that invalid credentials key throws an error.
Test that invalid credentials key throws an error.
async def test_invalid_credentials(hass): """Test that invalid credentials key throws an error.""" conf = { CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc", } with patch( "homeassistant.components.tile.config_flow.async_login", side_effect=TileError, ): ...
[ "async", "def", "test_invalid_credentials", "(", "hass", ")", ":", "conf", "=", "{", "CONF_USERNAME", ":", "\"user@host.com\"", ",", "CONF_PASSWORD", ":", "\"123abc\"", ",", "}", "with", "patch", "(", "\"homeassistant.components.tile.config_flow.async_login\"", ",", "...
[ 31, 0 ]
[ 46, 59 ]
python
en
['en', 'en', 'en']
True
test_step_import
(hass)
Test that the import step works.
Test that the import step works.
async def test_step_import(hass): """Test that the import step works.""" conf = { CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc", } with patch( "homeassistant.components.tile.async_setup_entry", return_value=True ), patch("homeassistant.components.tile.config_flow.a...
[ "async", "def", "test_step_import", "(", "hass", ")", ":", "conf", "=", "{", "CONF_USERNAME", ":", "\"user@host.com\"", ",", "CONF_PASSWORD", ":", "\"123abc\"", ",", "}", "with", "patch", "(", "\"homeassistant.components.tile.async_setup_entry\"", ",", "return_value",...
[ 49, 0 ]
[ 67, 9 ]
python
en
['en', 'en', 'en']
True
test_step_user
(hass)
Test that the user step works.
Test that the user step works.
async def test_step_user(hass): """Test that the user step works.""" conf = { CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc", } with patch( "homeassistant.components.tile.async_setup_entry", return_value=True ), patch("homeassistant.components.tile.config_flow.async...
[ "async", "def", "test_step_user", "(", "hass", ")", ":", "conf", "=", "{", "CONF_USERNAME", ":", "\"user@host.com\"", ",", "CONF_PASSWORD", ":", "\"123abc\"", ",", "}", "with", "patch", "(", "\"homeassistant.components.tile.async_setup_entry\"", ",", "return_value", ...
[ 70, 0 ]
[ 94, 9 ]
python
en
['en', 'en', 'en']
True
print_file
(filename)
Opens file and prints its contents line by line.
Opens file and prints its contents line by line.
def print_file(filename): """ Opens file and prints its contents line by line. """ infile = open(filename) for line in infile: print(line, end="") # the file has "\n" at the end of each line already infile.close()
[ "def", "print_file", "(", "filename", ")", ":", "infile", "=", "open", "(", "filename", ")", "for", "line", "in", "infile", ":", "print", "(", "line", ",", "end", "=", "\"\"", ")", "# the file has \"\\n\" at the end of each line already", "infile", ".", "close...
[ 249, 0 ]
[ 256, 18 ]
python
en
['en', 'en', 'en']
True
copy_file
(infilename, outfilename)
Opens two files and copies one into the other line by line.
Opens two files and copies one into the other line by line.
def copy_file(infilename, outfilename): """ Opens two files and copies one into the other line by line. """ infile = open(infilename) outfile = open(outfilename,'w') for line in infile: outfile.write(line) infile.close() outfile.close()
[ "def", "copy_file", "(", "infilename", ",", "outfilename", ")", ":", "infile", "=", "open", "(", "infilename", ")", "outfile", "=", "open", "(", "outfilename", ",", "'w'", ")", "for", "line", "in", "infile", ":", "outfile", ".", "write", "(", "line", "...
[ 258, 0 ]
[ 267, 19 ]
python
en
['en', 'en', 'en']
True
copy_file
(infilename, outfilename)
Opens two files and copies one into the other line by line.
Opens two files and copies one into the other line by line.
def copy_file(infilename, outfilename): """ Opens two files and copies one into the other line by line. """ infile = open(infilename) outfile = open(outfilename,'w') for line in infile: outfile.write(line) infile.close() outfile.close()
[ "def", "copy_file", "(", "infilename", ",", "outfilename", ")", ":", "infile", "=", "open", "(", "infilename", ")", "outfile", "=", "open", "(", "outfilename", ",", "'w'", ")", "for", "line", "in", "infile", ":", "outfile", ".", "write", "(", "line", "...
[ 373, 0 ]
[ 382, 19 ]
python
en
['en', 'en', 'en']
True
count_words
(filename)
Makes a list of the words in the file filename and the number of times each word appears. This program is modified from one by Mark Summerfield in his excellent book, "Programming in Python 3"
Makes a list of the words in the file filename and the number of times each word appears. This program is modified from one by Mark Summerfield in his excellent book, "Programming in Python 3"
def count_words(filename): """ Makes a list of the words in the file filename and the number of times each word appears. This program is modified from one by Mark Summerfield in his excellent book, "Programming in Python 3" """ text_file = open(filename) # open the file for reading ...
[ "def", "count_words", "(", "filename", ")", ":", "text_file", "=", "open", "(", "filename", ")", "# open the file for reading", "# Set up an empty dictionary to start a standard design pattern loop", "words_dic", "=", "{", "}", "# This loop adds each word to the dictionary and up...
[ 430, 0 ]
[ 455, 36 ]
python
en
['en', 'en', 'en']
True
read_csv_file
(filename)
Reads a CSV file and prints each row, which is a list.
Reads a CSV file and prints each row, which is a list.
def read_csv_file(filename): """Reads a CSV file and prints each row, which is a list. """ f = open(filename) for row in csv.reader(f): print(row) f.close()
[ "def", "read_csv_file", "(", "filename", ")", ":", "f", "=", "open", "(", "filename", ")", "for", "row", "in", "csv", ".", "reader", "(", "f", ")", ":", "print", "(", "row", ")", "f", ".", "close", "(", ")" ]
[ 551, 0 ]
[ 556, 13 ]
python
en
['en', 'en', 'en']
True
read_csv_file1
(filename)
Reads a CSV file and print it as a list of rows.
Reads a CSV file and print it as a list of rows.
def read_csv_file1(filename): """Reads a CSV file and print it as a list of rows.""" f = open(filename) data = [] for row in csv.reader(f): data.append(row) print(data) f.close()
[ "def", "read_csv_file1", "(", "filename", ")", ":", "f", "=", "open", "(", "filename", ")", "data", "=", "[", "]", "for", "row", "in", "csv", ".", "reader", "(", "f", ")", ":", "data", ".", "append", "(", "row", ")", "print", "(", "data", ")", ...
[ 564, 0 ]
[ 571, 13 ]
python
en
['en', 'en', 'en']
True
read_csv_file2
(filename)
Reads a CSV file and prints each row without list brackets.
Reads a CSV file and prints each row without list brackets.
def read_csv_file2(filename): """Reads a CSV file and prints each row without list brackets. """ f = open(filename) for row in csv.reader(f): pass # replace this line with your code f.close()
[ "def", "read_csv_file2", "(", "filename", ")", ":", "f", "=", "open", "(", "filename", ")", "for", "row", "in", "csv", ".", "reader", "(", "f", ")", ":", "pass", "# replace this line with your code", "f", ".", "close", "(", ")" ]
[ 611, 0 ]
[ 616, 13 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass: HomeAssistant, config: dict)
Set up the emulated_kasa component.
Set up the emulated_kasa component.
async def async_setup(hass: HomeAssistant, config: dict): """Set up the emulated_kasa component.""" conf = config.get(DOMAIN) if not conf: return True entity_configs = conf[CONF_ENTITIES] def devices(): """Devices to be emulated.""" yield from get_plug_devices(hass, entity_c...
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "dict", ")", ":", "conf", "=", "config", ".", "get", "(", "DOMAIN", ")", "if", "not", "conf", ":", "return", "True", "entity_configs", "=", "conf", "[", "CONF_ENTITIES"...
[ 50, 0 ]
[ 77, 15 ]
python
en
['en', 'en', 'en']
True
validate_configs
(hass, entity_configs)
Validate that entities exist and ensure templates are ready to use.
Validate that entities exist and ensure templates are ready to use.
async def validate_configs(hass, entity_configs): """Validate that entities exist and ensure templates are ready to use.""" entity_registry = await hass.helpers.entity_registry.async_get_registry() for entity_id, entity_config in entity_configs.items(): state = hass.states.get(entity_id) if ...
[ "async", "def", "validate_configs", "(", "hass", ",", "entity_configs", ")", ":", "entity_registry", "=", "await", "hass", ".", "helpers", ".", "entity_registry", ".", "async_get_registry", "(", ")", "for", "entity_id", ",", "entity_config", "in", "entity_configs"...
[ 80, 0 ]
[ 112, 70 ]
python
en
['en', 'en', 'en']
True
get_system_unique_id
(entity: RegistryEntry)
Determine the system wide unique_id for an entity.
Determine the system wide unique_id for an entity.
def get_system_unique_id(entity: RegistryEntry): """Determine the system wide unique_id for an entity.""" return f"{entity.platform}.{entity.domain}.{entity.unique_id}"
[ "def", "get_system_unique_id", "(", "entity", ":", "RegistryEntry", ")", ":", "return", "f\"{entity.platform}.{entity.domain}.{entity.unique_id}\"" ]
[ 115, 0 ]
[ 117, 66 ]
python
en
['en', 'en', 'en']
True
get_plug_devices
(hass, entity_configs)
Produce list of plug devices from config entities.
Produce list of plug devices from config entities.
def get_plug_devices(hass, entity_configs): """Produce list of plug devices from config entities.""" for entity_id, entity_config in entity_configs.items(): state = hass.states.get(entity_id) if state is None: continue name = entity_config.get(CONF_NAME, state.name) ...
[ "def", "get_plug_devices", "(", "hass", ",", "entity_configs", ")", ":", "for", "entity_id", ",", "entity_config", "in", "entity_configs", ".", "items", "(", ")", ":", "state", "=", "hass", ".", "states", ".", "get", "(", "entity_id", ")", "if", "state", ...
[ 120, 0 ]
[ 149, 9 ]
python
en
['en', 'en', 'en']
True
test_setup
(hass)
Test setting up the Melissa component.
Test setting up the Melissa component.
async def test_setup(hass): """Test setting up the Melissa component.""" with patch("melissa.AsyncMelissa") as mocked_melissa, patch.object( melissa, "async_load_platform" ): mocked_melissa.return_value.async_connect = AsyncMock() await melissa.async_setup(hass, VALID_CONFIG) ...
[ "async", "def", "test_setup", "(", "hass", ")", ":", "with", "patch", "(", "\"melissa.AsyncMelissa\"", ")", "as", "mocked_melissa", ",", "patch", ".", "object", "(", "melissa", ",", "\"async_load_platform\"", ")", ":", "mocked_melissa", ".", "return_value", ".",...
[ 8, 0 ]
[ 22, 9 ]
python
en
['en', 'en', 'en']
True
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up the switch from config.
Set up the switch from config.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the switch from config.""" if DATA_KEY not in hass.data: hass.data[DATA_KEY] = {} host = config[CONF_HOST] token = config[CONF_TOKEN] name = config[CONF_NAME] model = config.get(CONF_MODEL) ...
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "DATA_KEY", "not", "in", "hass", ".", "data", ":", "hass", ".", "data", "[", "DATA_KEY", "]", "=", "{", "}"...
[ 115, 0 ]
[ 217, 9 ]
python
en
['en', 'en', 'en']
True
XiaomiPlugGenericSwitch.__init__
(self, name, plug, model, unique_id)
Initialize the plug switch.
Initialize the plug switch.
def __init__(self, name, plug, model, unique_id): """Initialize the plug switch.""" self._name = name self._plug = plug self._model = model self._unique_id = unique_id self._icon = "mdi:power-socket" self._available = False self._state = None self...
[ "def", "__init__", "(", "self", ",", "name", ",", "plug", ",", "model", ",", "unique_id", ")", ":", "self", ".", "_name", "=", "name", "self", ".", "_plug", "=", "plug", "self", ".", "_model", "=", "model", "self", ".", "_unique_id", "=", "unique_id"...
[ 223, 4 ]
[ 235, 33 ]
python
en
['en', 'pl', 'en']
True
XiaomiPlugGenericSwitch.unique_id
(self)
Return an unique ID.
Return an unique ID.
def unique_id(self): """Return an unique ID.""" return self._unique_id
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_unique_id" ]
[ 238, 4 ]
[ 240, 30 ]
python
fr
['fr', 'fr', 'en']
True
XiaomiPlugGenericSwitch.name
(self)
Return the name of the device if any.
Return the name of the device if any.
def name(self): """Return the name of the device if any.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 243, 4 ]
[ 245, 25 ]
python
en
['en', 'en', 'en']
True
XiaomiPlugGenericSwitch.icon
(self)
Return the icon to use for device if any.
Return the icon to use for device if any.
def icon(self): """Return the icon to use for device if any.""" return self._icon
[ "def", "icon", "(", "self", ")", ":", "return", "self", ".", "_icon" ]
[ 248, 4 ]
[ 250, 25 ]
python
en
['en', 'en', 'en']
True
XiaomiPlugGenericSwitch.available
(self)
Return true when state is known.
Return true when state is known.
def available(self): """Return true when state is known.""" return self._available
[ "def", "available", "(", "self", ")", ":", "return", "self", ".", "_available" ]
[ 253, 4 ]
[ 255, 30 ]
python
en
['en', 'de', 'en']
True
XiaomiPlugGenericSwitch.device_state_attributes
(self)
Return the state attributes of the device.
Return the state attributes of the device.
def device_state_attributes(self): """Return the state attributes of the device.""" return self._state_attrs
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "self", ".", "_state_attrs" ]
[ 258, 4 ]
[ 260, 32 ]
python
en
['en', 'en', 'en']
True
XiaomiPlugGenericSwitch.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.""" return self._state
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "_state" ]
[ 263, 4 ]
[ 265, 26 ]
python
en
['en', 'fy', 'en']
True