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
AmcrestChecker.available
(self)
Return if camera's API is responding.
Return if camera's API is responding.
def available(self): """Return if camera's API is responding.""" return self._wrap_errors <= MAX_ERRORS and not self._wrap_login_err
[ "def", "available", "(", "self", ")", ":", "return", "self", ".", "_wrap_errors", "<=", "MAX_ERRORS", "and", "not", "self", ".", "_wrap_login_err" ]
[ 138, 4 ]
[ 140, 75 ]
python
en
['en', 'no', 'en']
True
AmcrestChecker.available_flag
(self)
Return threading event flag that indicates if camera's API is responding.
Return threading event flag that indicates if camera's API is responding.
def available_flag(self): """Return threading event flag that indicates if camera's API is responding.""" return self._wrap_event_flag
[ "def", "available_flag", "(", "self", ")", ":", "return", "self", ".", "_wrap_event_flag" ]
[ 143, 4 ]
[ 145, 36 ]
python
en
['en', 'en', 'en']
True
AmcrestChecker.command
(self, *args, **kwargs)
amcrest.Http.command wrapper to catch errors.
amcrest.Http.command wrapper to catch errors.
def command(self, *args, **kwargs): """amcrest.Http.command wrapper to catch errors.""" try: ret = super().command(*args, **kwargs) except LoginError as ex: with self._wrap_lock: was_online = self.available was_login_err = self._wrap_login_err self._wrap_login_err = True if not was_login_err: _LOGGER.error("%s camera offline: Login error: %s", self._wrap_name, ex) if was_online: self._start_recovery() raise except AmcrestError: with self._wrap_lock: was_online = self.available errs = self._wrap_errors = self._wrap_errors + 1 offline = not self.available _LOGGER.debug("%s camera errs: %i", self._wrap_name, errs) if was_online and offline: _LOGGER.error("%s camera offline: Too many errors", self._wrap_name) self._start_recovery() raise with self._wrap_lock: was_offline = not self.available self._wrap_errors = 0 self._wrap_login_err = False if was_offline: self._unsub_recheck() self._unsub_recheck = None _LOGGER.error("%s camera back online", self._wrap_name) self._wrap_event_flag.set() dispatcher_send(self._hass, service_signal(SERVICE_UPDATE, self._wrap_name)) return ret
[ "def", "command", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "try", ":", "ret", "=", "super", "(", ")", ".", "command", "(", "*", "args", ",", "*", "*", "kwargs", ")", "except", "LoginError", "as", "ex", ":", "with", "self", ".", "_wrap_lock", ":", "was_online", "=", "self", ".", "available", "was_login_err", "=", "self", ".", "_wrap_login_err", "self", ".", "_wrap_login_err", "=", "True", "if", "not", "was_login_err", ":", "_LOGGER", ".", "error", "(", "\"%s camera offline: Login error: %s\"", ",", "self", ".", "_wrap_name", ",", "ex", ")", "if", "was_online", ":", "self", ".", "_start_recovery", "(", ")", "raise", "except", "AmcrestError", ":", "with", "self", ".", "_wrap_lock", ":", "was_online", "=", "self", ".", "available", "errs", "=", "self", ".", "_wrap_errors", "=", "self", ".", "_wrap_errors", "+", "1", "offline", "=", "not", "self", ".", "available", "_LOGGER", ".", "debug", "(", "\"%s camera errs: %i\"", ",", "self", ".", "_wrap_name", ",", "errs", ")", "if", "was_online", "and", "offline", ":", "_LOGGER", ".", "error", "(", "\"%s camera offline: Too many errors\"", ",", "self", ".", "_wrap_name", ")", "self", ".", "_start_recovery", "(", ")", "raise", "with", "self", ".", "_wrap_lock", ":", "was_offline", "=", "not", "self", ".", "available", "self", ".", "_wrap_errors", "=", "0", "self", ".", "_wrap_login_err", "=", "False", "if", "was_offline", ":", "self", ".", "_unsub_recheck", "(", ")", "self", ".", "_unsub_recheck", "=", "None", "_LOGGER", ".", "error", "(", "\"%s camera back online\"", ",", "self", ".", "_wrap_name", ")", "self", ".", "_wrap_event_flag", ".", "set", "(", ")", "dispatcher_send", "(", "self", ".", "_hass", ",", "service_signal", "(", "SERVICE_UPDATE", ",", "self", ".", "_wrap_name", ")", ")", "return", "ret" ]
[ 154, 4 ]
[ 188, 18 ]
python
en
['en', 'en', 'en']
True
AmcrestChecker._wrap_test_online
(self, now)
Test if camera is back online.
Test if camera is back online.
def _wrap_test_online(self, now): """Test if camera is back online.""" _LOGGER.debug("Testing if %s back online", self._wrap_name) try: self.current_time except AmcrestError: pass
[ "def", "_wrap_test_online", "(", "self", ",", "now", ")", ":", "_LOGGER", ".", "debug", "(", "\"Testing if %s back online\"", ",", "self", ".", "_wrap_name", ")", "try", ":", "self", ".", "current_time", "except", "AmcrestError", ":", "pass" ]
[ 190, 4 ]
[ 196, 16 ]
python
en
['en', 'en', 'en']
True
AmcrestDevice.__init__
( self, api, authentication, ffmpeg_arguments, stream_source, resolution, control_light, )
Initialize the entity.
Initialize the entity.
def __init__( self, api, authentication, ffmpeg_arguments, stream_source, resolution, control_light, ): """Initialize the entity.""" self.api = api self.authentication = authentication self.ffmpeg_arguments = ffmpeg_arguments self.stream_source = stream_source self.resolution = resolution self.control_light = control_light
[ "def", "__init__", "(", "self", ",", "api", ",", "authentication", ",", "ffmpeg_arguments", ",", "stream_source", ",", "resolution", ",", "control_light", ",", ")", ":", "self", ".", "api", "=", "api", "self", ".", "authentication", "=", "authentication", "self", ".", "ffmpeg_arguments", "=", "ffmpeg_arguments", "self", ".", "stream_source", "=", "stream_source", "self", ".", "resolution", "=", "resolution", "self", ".", "control_light", "=", "control_light" ]
[ 336, 4 ]
[ 351, 42 ]
python
en
['en', 'en', 'en']
True
test_hassio_discovery_startup
(hass, aioclient_mock, hassio_client)
Test startup and discovery after event.
Test startup and discovery after event.
async def test_hassio_discovery_startup(hass, aioclient_mock, hassio_client): """Test startup and discovery after event.""" aioclient_mock.get( "http://127.0.0.1/discovery", json={ "result": "ok", "data": { "discovery": [ { "service": "mqtt", "uuid": "test", "addon": "mosquitto", "config": { "broker": "mock-broker", "port": 1883, "username": "mock-user", "password": "mock-pass", "protocol": "3.1.1", }, } ] }, }, ) aioclient_mock.get( "http://127.0.0.1/addons/mosquitto/info", json={"result": "ok", "data": {"name": "Mosquitto Test"}}, ) assert aioclient_mock.call_count == 0 with patch( "homeassistant.components.mqtt.config_flow.FlowHandler.async_step_hassio", return_value={"type": "abort"}, ) as mock_mqtt: hass.bus.async_fire(EVENT_HOMEASSISTANT_START) await hass.async_block_till_done() assert aioclient_mock.call_count == 2 assert mock_mqtt.called mock_mqtt.assert_called_with( { "broker": "mock-broker", "port": 1883, "username": "mock-user", "password": "mock-pass", "protocol": "3.1.1", "addon": "Mosquitto Test", } )
[ "async", "def", "test_hassio_discovery_startup", "(", "hass", ",", "aioclient_mock", ",", "hassio_client", ")", ":", "aioclient_mock", ".", "get", "(", "\"http://127.0.0.1/discovery\"", ",", "json", "=", "{", "\"result\"", ":", "\"ok\"", ",", "\"data\"", ":", "{", "\"discovery\"", ":", "[", "{", "\"service\"", ":", "\"mqtt\"", ",", "\"uuid\"", ":", "\"test\"", ",", "\"addon\"", ":", "\"mosquitto\"", ",", "\"config\"", ":", "{", "\"broker\"", ":", "\"mock-broker\"", ",", "\"port\"", ":", "1883", ",", "\"username\"", ":", "\"mock-user\"", ",", "\"password\"", ":", "\"mock-pass\"", ",", "\"protocol\"", ":", "\"3.1.1\"", ",", "}", ",", "}", "]", "}", ",", "}", ",", ")", "aioclient_mock", ".", "get", "(", "\"http://127.0.0.1/addons/mosquitto/info\"", ",", "json", "=", "{", "\"result\"", ":", "\"ok\"", ",", "\"data\"", ":", "{", "\"name\"", ":", "\"Mosquitto Test\"", "}", "}", ",", ")", "assert", "aioclient_mock", ".", "call_count", "==", "0", "with", "patch", "(", "\"homeassistant.components.mqtt.config_flow.FlowHandler.async_step_hassio\"", ",", "return_value", "=", "{", "\"type\"", ":", "\"abort\"", "}", ",", ")", "as", "mock_mqtt", ":", "hass", ".", "bus", ".", "async_fire", "(", "EVENT_HOMEASSISTANT_START", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "aioclient_mock", ".", "call_count", "==", "2", "assert", "mock_mqtt", ".", "called", "mock_mqtt", ".", "assert_called_with", "(", "{", "\"broker\"", ":", "\"mock-broker\"", ",", "\"port\"", ":", "1883", ",", "\"username\"", ":", "\"mock-user\"", ",", "\"password\"", ":", "\"mock-pass\"", ",", "\"protocol\"", ":", "\"3.1.1\"", ",", "\"addon\"", ":", "\"Mosquitto Test\"", ",", "}", ")" ]
[ 8, 0 ]
[ 57, 9 ]
python
en
['en', 'en', 'en']
True
test_hassio_discovery_startup_done
(hass, aioclient_mock, hassio_client)
Test startup and discovery with hass discovery.
Test startup and discovery with hass discovery.
async def test_hassio_discovery_startup_done(hass, aioclient_mock, hassio_client): """Test startup and discovery with hass discovery.""" aioclient_mock.post( "http://127.0.0.1/supervisor/options", json={"result": "ok", "data": {}}, ) aioclient_mock.get( "http://127.0.0.1/discovery", json={ "result": "ok", "data": { "discovery": [ { "service": "mqtt", "uuid": "test", "addon": "mosquitto", "config": { "broker": "mock-broker", "port": 1883, "username": "mock-user", "password": "mock-pass", "protocol": "3.1.1", }, } ] }, }, ) aioclient_mock.get( "http://127.0.0.1/addons/mosquitto/info", json={"result": "ok", "data": {"name": "Mosquitto Test"}}, ) with patch( "homeassistant.components.hassio.HassIO.update_hass_api", return_value={"result": "ok"}, ), patch( "homeassistant.components.hassio.HassIO.get_info", Mock(side_effect=HassioAPIError()), ), patch( "homeassistant.components.mqtt.config_flow.FlowHandler.async_step_hassio", return_value={"type": "abort"}, ) as mock_mqtt: await hass.async_start() await async_setup_component(hass, "hassio", {}) await hass.async_block_till_done() assert aioclient_mock.call_count == 2 assert mock_mqtt.called mock_mqtt.assert_called_with( { "broker": "mock-broker", "port": 1883, "username": "mock-user", "password": "mock-pass", "protocol": "3.1.1", "addon": "Mosquitto Test", } )
[ "async", "def", "test_hassio_discovery_startup_done", "(", "hass", ",", "aioclient_mock", ",", "hassio_client", ")", ":", "aioclient_mock", ".", "post", "(", "\"http://127.0.0.1/supervisor/options\"", ",", "json", "=", "{", "\"result\"", ":", "\"ok\"", ",", "\"data\"", ":", "{", "}", "}", ",", ")", "aioclient_mock", ".", "get", "(", "\"http://127.0.0.1/discovery\"", ",", "json", "=", "{", "\"result\"", ":", "\"ok\"", ",", "\"data\"", ":", "{", "\"discovery\"", ":", "[", "{", "\"service\"", ":", "\"mqtt\"", ",", "\"uuid\"", ":", "\"test\"", ",", "\"addon\"", ":", "\"mosquitto\"", ",", "\"config\"", ":", "{", "\"broker\"", ":", "\"mock-broker\"", ",", "\"port\"", ":", "1883", ",", "\"username\"", ":", "\"mock-user\"", ",", "\"password\"", ":", "\"mock-pass\"", ",", "\"protocol\"", ":", "\"3.1.1\"", ",", "}", ",", "}", "]", "}", ",", "}", ",", ")", "aioclient_mock", ".", "get", "(", "\"http://127.0.0.1/addons/mosquitto/info\"", ",", "json", "=", "{", "\"result\"", ":", "\"ok\"", ",", "\"data\"", ":", "{", "\"name\"", ":", "\"Mosquitto Test\"", "}", "}", ",", ")", "with", "patch", "(", "\"homeassistant.components.hassio.HassIO.update_hass_api\"", ",", "return_value", "=", "{", "\"result\"", ":", "\"ok\"", "}", ",", ")", ",", "patch", "(", "\"homeassistant.components.hassio.HassIO.get_info\"", ",", "Mock", "(", "side_effect", "=", "HassioAPIError", "(", ")", ")", ",", ")", ",", "patch", "(", "\"homeassistant.components.mqtt.config_flow.FlowHandler.async_step_hassio\"", ",", "return_value", "=", "{", "\"type\"", ":", "\"abort\"", "}", ",", ")", "as", "mock_mqtt", ":", "await", "hass", ".", "async_start", "(", ")", "await", "async_setup_component", "(", "hass", ",", "\"hassio\"", ",", "{", "}", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "aioclient_mock", ".", "call_count", "==", "2", "assert", "mock_mqtt", ".", "called", "mock_mqtt", ".", "assert_called_with", "(", "{", "\"broker\"", ":", "\"mock-broker\"", ",", "\"port\"", ":", "1883", ",", "\"username\"", ":", "\"mock-user\"", ",", "\"password\"", ":", "\"mock-pass\"", ",", "\"protocol\"", ":", "\"3.1.1\"", ",", "\"addon\"", ":", "\"Mosquitto Test\"", ",", "}", ")" ]
[ 60, 0 ]
[ 118, 9 ]
python
en
['en', 'en', 'en']
True
test_hassio_discovery_webhook
(hass, aioclient_mock, hassio_client)
Test discovery webhook.
Test discovery webhook.
async def test_hassio_discovery_webhook(hass, aioclient_mock, hassio_client): """Test discovery webhook.""" aioclient_mock.get( "http://127.0.0.1/discovery/testuuid", json={ "result": "ok", "data": { "service": "mqtt", "uuid": "test", "addon": "mosquitto", "config": { "broker": "mock-broker", "port": 1883, "username": "mock-user", "password": "mock-pass", "protocol": "3.1.1", }, }, }, ) aioclient_mock.get( "http://127.0.0.1/addons/mosquitto/info", json={"result": "ok", "data": {"name": "Mosquitto Test"}}, ) with patch( "homeassistant.components.mqtt.config_flow.FlowHandler.async_step_hassio", return_value={"type": "abort"}, ) as mock_mqtt: resp = await hassio_client.post( "/api/hassio_push/discovery/testuuid", json={"addon": "mosquitto", "service": "mqtt", "uuid": "testuuid"}, ) await hass.async_block_till_done() assert resp.status == 200 assert aioclient_mock.call_count == 2 assert mock_mqtt.called mock_mqtt.assert_called_with( { "broker": "mock-broker", "port": 1883, "username": "mock-user", "password": "mock-pass", "protocol": "3.1.1", "addon": "Mosquitto Test", } )
[ "async", "def", "test_hassio_discovery_webhook", "(", "hass", ",", "aioclient_mock", ",", "hassio_client", ")", ":", "aioclient_mock", ".", "get", "(", "\"http://127.0.0.1/discovery/testuuid\"", ",", "json", "=", "{", "\"result\"", ":", "\"ok\"", ",", "\"data\"", ":", "{", "\"service\"", ":", "\"mqtt\"", ",", "\"uuid\"", ":", "\"test\"", ",", "\"addon\"", ":", "\"mosquitto\"", ",", "\"config\"", ":", "{", "\"broker\"", ":", "\"mock-broker\"", ",", "\"port\"", ":", "1883", ",", "\"username\"", ":", "\"mock-user\"", ",", "\"password\"", ":", "\"mock-pass\"", ",", "\"protocol\"", ":", "\"3.1.1\"", ",", "}", ",", "}", ",", "}", ",", ")", "aioclient_mock", ".", "get", "(", "\"http://127.0.0.1/addons/mosquitto/info\"", ",", "json", "=", "{", "\"result\"", ":", "\"ok\"", ",", "\"data\"", ":", "{", "\"name\"", ":", "\"Mosquitto Test\"", "}", "}", ",", ")", "with", "patch", "(", "\"homeassistant.components.mqtt.config_flow.FlowHandler.async_step_hassio\"", ",", "return_value", "=", "{", "\"type\"", ":", "\"abort\"", "}", ",", ")", "as", "mock_mqtt", ":", "resp", "=", "await", "hassio_client", ".", "post", "(", "\"/api/hassio_push/discovery/testuuid\"", ",", "json", "=", "{", "\"addon\"", ":", "\"mosquitto\"", ",", "\"service\"", ":", "\"mqtt\"", ",", "\"uuid\"", ":", "\"testuuid\"", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "resp", ".", "status", "==", "200", "assert", "aioclient_mock", ".", "call_count", "==", "2", "assert", "mock_mqtt", ".", "called", "mock_mqtt", ".", "assert_called_with", "(", "{", "\"broker\"", ":", "\"mock-broker\"", ",", "\"port\"", ":", "1883", ",", "\"username\"", ":", "\"mock-user\"", ",", "\"password\"", ":", "\"mock-pass\"", ",", "\"protocol\"", ":", "\"3.1.1\"", ",", "\"addon\"", ":", "\"Mosquitto Test\"", ",", "}", ")" ]
[ 121, 0 ]
[ 168, 9 ]
python
en
['en', 'en', 'en']
True
mock_storage
(hass_storage, data)
Mock the onboarding storage.
Mock the onboarding storage.
def mock_storage(hass_storage, data): """Mock the onboarding storage.""" hass_storage[onboarding.STORAGE_KEY] = { "version": onboarding.STORAGE_VERSION, "data": data, }
[ "def", "mock_storage", "(", "hass_storage", ",", "data", ")", ":", "hass_storage", "[", "onboarding", ".", "STORAGE_KEY", "]", "=", "{", "\"version\"", ":", "onboarding", ".", "STORAGE_VERSION", ",", "\"data\"", ":", "data", ",", "}" ]
[ 5, 0 ]
[ 10, 5 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the sensor platform.
Set up the sensor platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the sensor platform.""" username = config[CONF_USERNAME] password = config[CONF_PASSWORD] counter_id = config[CONF_COUNTER_ID] try: client = SuezClient(username, password, counter_id) if not client.check_credentials(): _LOGGER.warning("Wrong username and/or password") return except PySuezError: _LOGGER.warning("Unable to create Suez Client") return add_entities([SuezSensor(client)], True)
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "username", "=", "config", "[", "CONF_USERNAME", "]", "password", "=", "config", "[", "CONF_PASSWORD", "]", "counter_id", "=", "config", "[", "CONF_COUNTER_ID", "]", "try", ":", "client", "=", "SuezClient", "(", "username", ",", "password", ",", "counter_id", ")", "if", "not", "client", ".", "check_credentials", "(", ")", ":", "_LOGGER", ".", "warning", "(", "\"Wrong username and/or password\"", ")", "return", "except", "PySuezError", ":", "_LOGGER", ".", "warning", "(", "\"Unable to create Suez Client\"", ")", "return", "add_entities", "(", "[", "SuezSensor", "(", "client", ")", "]", ",", "True", ")" ]
[ 30, 0 ]
[ 46, 44 ]
python
en
['en', 'da', 'en']
True
SuezSensor.__init__
(self, client)
Initialize the data object.
Initialize the data object.
def __init__(self, client): """Initialize the data object.""" self._attributes = {} self._state = None self._available = None self.client = client
[ "def", "__init__", "(", "self", ",", "client", ")", ":", "self", ".", "_attributes", "=", "{", "}", "self", ".", "_state", "=", "None", "self", ".", "_available", "=", "None", "self", ".", "client", "=", "client" ]
[ 52, 4 ]
[ 57, 28 ]
python
en
['en', 'en', 'en']
True
SuezSensor.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return COMPONENT_NAME
[ "def", "name", "(", "self", ")", ":", "return", "COMPONENT_NAME" ]
[ 60, 4 ]
[ 62, 29 ]
python
en
['en', 'mi', 'en']
True
SuezSensor.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" ]
[ 65, 4 ]
[ 67, 26 ]
python
en
['en', 'en', 'en']
True
SuezSensor.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 VOLUME_LITERS
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "VOLUME_LITERS" ]
[ 70, 4 ]
[ 72, 28 ]
python
en
['en', 'la', 'en']
True
SuezSensor.device_state_attributes
(self)
Return the state attributes.
Return the state attributes.
def device_state_attributes(self): """Return the state attributes.""" return self._attributes
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "self", ".", "_attributes" ]
[ 75, 4 ]
[ 77, 31 ]
python
en
['en', 'en', 'en']
True
SuezSensor.icon
(self)
Return the icon of the sensor.
Return the icon of the sensor.
def icon(self): """Return the icon of the sensor.""" return COMPONENT_ICON
[ "def", "icon", "(", "self", ")", ":", "return", "COMPONENT_ICON" ]
[ 80, 4 ]
[ 82, 29 ]
python
en
['en', 'en', 'en']
True
SuezSensor._fetch_data
(self)
Fetch latest data from Suez.
Fetch latest data from Suez.
def _fetch_data(self): """Fetch latest data from Suez.""" try: self.client.update() # _state holds the volume of consumed water during previous day self._state = self.client.state self._available = True self._attributes["attribution"] = self.client.attributes["attribution"] self._attributes["this_month_consumption"] = {} for item in self.client.attributes["thisMonthConsumption"]: self._attributes["this_month_consumption"][ item ] = self.client.attributes["thisMonthConsumption"][item] self._attributes["previous_month_consumption"] = {} for item in self.client.attributes["previousMonthConsumption"]: self._attributes["previous_month_consumption"][ item ] = self.client.attributes["previousMonthConsumption"][item] self._attributes["highest_monthly_consumption"] = self.client.attributes[ "highestMonthlyConsumption" ] self._attributes["last_year_overall"] = self.client.attributes[ "lastYearOverAll" ] self._attributes["this_year_overall"] = self.client.attributes[ "thisYearOverAll" ] self._attributes["history"] = {} for item in self.client.attributes["history"]: self._attributes["history"][item] = self.client.attributes["history"][ item ] except PySuezError: self._available = False _LOGGER.warning("Unable to fetch data")
[ "def", "_fetch_data", "(", "self", ")", ":", "try", ":", "self", ".", "client", ".", "update", "(", ")", "# _state holds the volume of consumed water during previous day", "self", ".", "_state", "=", "self", ".", "client", ".", "state", "self", ".", "_available", "=", "True", "self", ".", "_attributes", "[", "\"attribution\"", "]", "=", "self", ".", "client", ".", "attributes", "[", "\"attribution\"", "]", "self", ".", "_attributes", "[", "\"this_month_consumption\"", "]", "=", "{", "}", "for", "item", "in", "self", ".", "client", ".", "attributes", "[", "\"thisMonthConsumption\"", "]", ":", "self", ".", "_attributes", "[", "\"this_month_consumption\"", "]", "[", "item", "]", "=", "self", ".", "client", ".", "attributes", "[", "\"thisMonthConsumption\"", "]", "[", "item", "]", "self", ".", "_attributes", "[", "\"previous_month_consumption\"", "]", "=", "{", "}", "for", "item", "in", "self", ".", "client", ".", "attributes", "[", "\"previousMonthConsumption\"", "]", ":", "self", ".", "_attributes", "[", "\"previous_month_consumption\"", "]", "[", "item", "]", "=", "self", ".", "client", ".", "attributes", "[", "\"previousMonthConsumption\"", "]", "[", "item", "]", "self", ".", "_attributes", "[", "\"highest_monthly_consumption\"", "]", "=", "self", ".", "client", ".", "attributes", "[", "\"highestMonthlyConsumption\"", "]", "self", ".", "_attributes", "[", "\"last_year_overall\"", "]", "=", "self", ".", "client", ".", "attributes", "[", "\"lastYearOverAll\"", "]", "self", ".", "_attributes", "[", "\"this_year_overall\"", "]", "=", "self", ".", "client", ".", "attributes", "[", "\"thisYearOverAll\"", "]", "self", ".", "_attributes", "[", "\"history\"", "]", "=", "{", "}", "for", "item", "in", "self", ".", "client", ".", "attributes", "[", "\"history\"", "]", ":", "self", ".", "_attributes", "[", "\"history\"", "]", "[", "item", "]", "=", "self", ".", "client", ".", "attributes", "[", "\"history\"", "]", "[", "item", "]", "except", "PySuezError", ":", "self", ".", "_available", "=", "False", "_LOGGER", ".", "warning", "(", "\"Unable to fetch data\"", ")" ]
[ 84, 4 ]
[ 119, 51 ]
python
en
['en', 'pl', 'en']
True
SuezSensor.update
(self)
Return the latest collected data from Linky.
Return the latest collected data from Linky.
def update(self): """Return the latest collected data from Linky.""" self._fetch_data() _LOGGER.debug("Suez data state is: %s", self._state)
[ "def", "update", "(", "self", ")", ":", "self", ".", "_fetch_data", "(", ")", "_LOGGER", ".", "debug", "(", "\"Suez data state is: %s\"", ",", "self", ".", "_state", ")" ]
[ 121, 4 ]
[ 124, 60 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up the deCONZ lights and groups from a config entry.
Set up the deCONZ lights and groups from a config entry.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the deCONZ lights and groups from a config entry.""" gateway = get_gateway_from_config_entry(hass, config_entry) gateway.entities[DOMAIN] = set() @callback def async_add_light(lights): """Add light from deCONZ.""" entities = [] for light in lights: if ( light.type not in COVER_TYPES + LOCK_TYPES + SWITCH_TYPES and light.uniqueid not in gateway.entities[DOMAIN] ): entities.append(DeconzLight(light, gateway)) if entities: async_add_entities(entities) gateway.listeners.append( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_LIGHT), async_add_light ) ) @callback def async_add_group(groups): """Add group from deCONZ.""" if not gateway.option_allow_deconz_groups: return entities = [] for group in groups: if not group.lights: continue known_groups = set(gateway.entities[DOMAIN]) new_group = DeconzGroup(group, gateway) if new_group.unique_id not in known_groups: entities.append(new_group) if entities: async_add_entities(entities) gateway.listeners.append( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_GROUP), async_add_group ) ) async_add_light(gateway.api.lights.values()) async_add_group(gateway.api.groups.values())
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "gateway", "=", "get_gateway_from_config_entry", "(", "hass", ",", "config_entry", ")", "gateway", ".", "entities", "[", "DOMAIN", "]", "=", "set", "(", ")", "@", "callback", "def", "async_add_light", "(", "lights", ")", ":", "\"\"\"Add light from deCONZ.\"\"\"", "entities", "=", "[", "]", "for", "light", "in", "lights", ":", "if", "(", "light", ".", "type", "not", "in", "COVER_TYPES", "+", "LOCK_TYPES", "+", "SWITCH_TYPES", "and", "light", ".", "uniqueid", "not", "in", "gateway", ".", "entities", "[", "DOMAIN", "]", ")", ":", "entities", ".", "append", "(", "DeconzLight", "(", "light", ",", "gateway", ")", ")", "if", "entities", ":", "async_add_entities", "(", "entities", ")", "gateway", ".", "listeners", ".", "append", "(", "async_dispatcher_connect", "(", "hass", ",", "gateway", ".", "async_signal_new_device", "(", "NEW_LIGHT", ")", ",", "async_add_light", ")", ")", "@", "callback", "def", "async_add_group", "(", "groups", ")", ":", "\"\"\"Add group from deCONZ.\"\"\"", "if", "not", "gateway", ".", "option_allow_deconz_groups", ":", "return", "entities", "=", "[", "]", "for", "group", "in", "groups", ":", "if", "not", "group", ".", "lights", ":", "continue", "known_groups", "=", "set", "(", "gateway", ".", "entities", "[", "DOMAIN", "]", ")", "new_group", "=", "DeconzGroup", "(", "group", ",", "gateway", ")", "if", "new_group", ".", "unique_id", "not", "in", "known_groups", ":", "entities", ".", "append", "(", "new_group", ")", "if", "entities", ":", "async_add_entities", "(", "entities", ")", "gateway", ".", "listeners", ".", "append", "(", "async_dispatcher_connect", "(", "hass", ",", "gateway", ".", "async_signal_new_device", "(", "NEW_GROUP", ")", ",", "async_add_group", ")", ")", "async_add_light", "(", "gateway", ".", "api", ".", "lights", ".", "values", "(", ")", ")", "async_add_group", "(", "gateway", ".", "api", ".", "groups", ".", "values", "(", ")", ")" ]
[ 37, 0 ]
[ 90, 48 ]
python
en
['en', 'en', 'en']
True
DeconzBaseLight.__init__
(self, device, gateway)
Set up light.
Set up light.
def __init__(self, device, gateway): """Set up light.""" super().__init__(device, gateway) self._features = 0 if self._device.brightness is not None: self._features |= SUPPORT_BRIGHTNESS self._features |= SUPPORT_FLASH self._features |= SUPPORT_TRANSITION if self._device.ct is not None: self._features |= SUPPORT_COLOR_TEMP if self._device.xy is not None: self._features |= SUPPORT_COLOR if self._device.effect is not None: self._features |= SUPPORT_EFFECT
[ "def", "__init__", "(", "self", ",", "device", ",", "gateway", ")", ":", "super", "(", ")", ".", "__init__", "(", "device", ",", "gateway", ")", "self", ".", "_features", "=", "0", "if", "self", ".", "_device", ".", "brightness", "is", "not", "None", ":", "self", ".", "_features", "|=", "SUPPORT_BRIGHTNESS", "self", ".", "_features", "|=", "SUPPORT_FLASH", "self", ".", "_features", "|=", "SUPPORT_TRANSITION", "if", "self", ".", "_device", ".", "ct", "is", "not", "None", ":", "self", ".", "_features", "|=", "SUPPORT_COLOR_TEMP", "if", "self", ".", "_device", ".", "xy", "is", "not", "None", ":", "self", ".", "_features", "|=", "SUPPORT_COLOR", "if", "self", ".", "_device", ".", "effect", "is", "not", "None", ":", "self", ".", "_features", "|=", "SUPPORT_EFFECT" ]
[ 98, 4 ]
[ 116, 44 ]
python
en
['en', 'ky', 'en']
True
DeconzBaseLight.brightness
(self)
Return the brightness of this light between 0..255.
Return the brightness of this light between 0..255.
def brightness(self): """Return the brightness of this light between 0..255.""" return self._device.brightness
[ "def", "brightness", "(", "self", ")", ":", "return", "self", ".", "_device", ".", "brightness" ]
[ 119, 4 ]
[ 121, 38 ]
python
en
['en', 'en', 'en']
True
DeconzBaseLight.effect_list
(self)
Return the list of supported effects.
Return the list of supported effects.
def effect_list(self): """Return the list of supported effects.""" return [EFFECT_COLORLOOP]
[ "def", "effect_list", "(", "self", ")", ":", "return", "[", "EFFECT_COLORLOOP", "]" ]
[ 124, 4 ]
[ 126, 33 ]
python
en
['en', 'en', 'en']
True
DeconzBaseLight.color_temp
(self)
Return the CT color value.
Return the CT color value.
def color_temp(self): """Return the CT color value.""" if self._device.colormode != "ct": return None return self._device.ct
[ "def", "color_temp", "(", "self", ")", ":", "if", "self", ".", "_device", ".", "colormode", "!=", "\"ct\"", ":", "return", "None", "return", "self", ".", "_device", ".", "ct" ]
[ 129, 4 ]
[ 134, 30 ]
python
en
['en', 'en', 'en']
True
DeconzBaseLight.hs_color
(self)
Return the hs color value.
Return the hs color value.
def hs_color(self): """Return the hs color value.""" if self._device.colormode in ("xy", "hs") and self._device.xy: return color_util.color_xy_to_hs(*self._device.xy) return None
[ "def", "hs_color", "(", "self", ")", ":", "if", "self", ".", "_device", ".", "colormode", "in", "(", "\"xy\"", ",", "\"hs\"", ")", "and", "self", ".", "_device", ".", "xy", ":", "return", "color_util", ".", "color_xy_to_hs", "(", "*", "self", ".", "_device", ".", "xy", ")", "return", "None" ]
[ 137, 4 ]
[ 141, 19 ]
python
en
['en', 'en', 'en']
True
DeconzBaseLight.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._device.state
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "_device", ".", "state" ]
[ 144, 4 ]
[ 146, 33 ]
python
en
['en', 'et', 'en']
True
DeconzBaseLight.supported_features
(self)
Flag supported features.
Flag supported features.
def supported_features(self): """Flag supported features.""" return self._features
[ "def", "supported_features", "(", "self", ")", ":", "return", "self", ".", "_features" ]
[ 149, 4 ]
[ 151, 29 ]
python
en
['da', 'en', 'en']
True
DeconzBaseLight.async_turn_on
(self, **kwargs)
Turn on light.
Turn on light.
async def async_turn_on(self, **kwargs): """Turn on light.""" data = {"on": True} if ATTR_COLOR_TEMP in kwargs: data["ct"] = kwargs[ATTR_COLOR_TEMP] if ATTR_HS_COLOR in kwargs: data["xy"] = color_util.color_hs_to_xy(*kwargs[ATTR_HS_COLOR]) if ATTR_BRIGHTNESS in kwargs: data["bri"] = kwargs[ATTR_BRIGHTNESS] if ATTR_TRANSITION in kwargs: data["transitiontime"] = int(kwargs[ATTR_TRANSITION] * 10) elif "IKEA" in self._device.manufacturer: data["transitiontime"] = 0 if ATTR_FLASH in kwargs: if kwargs[ATTR_FLASH] == FLASH_SHORT: data["alert"] = "select" del data["on"] elif kwargs[ATTR_FLASH] == FLASH_LONG: data["alert"] = "lselect" del data["on"] if ATTR_EFFECT in kwargs: if kwargs[ATTR_EFFECT] == EFFECT_COLORLOOP: data["effect"] = "colorloop" else: data["effect"] = "none" await self._device.async_set_state(data)
[ "async", "def", "async_turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "data", "=", "{", "\"on\"", ":", "True", "}", "if", "ATTR_COLOR_TEMP", "in", "kwargs", ":", "data", "[", "\"ct\"", "]", "=", "kwargs", "[", "ATTR_COLOR_TEMP", "]", "if", "ATTR_HS_COLOR", "in", "kwargs", ":", "data", "[", "\"xy\"", "]", "=", "color_util", ".", "color_hs_to_xy", "(", "*", "kwargs", "[", "ATTR_HS_COLOR", "]", ")", "if", "ATTR_BRIGHTNESS", "in", "kwargs", ":", "data", "[", "\"bri\"", "]", "=", "kwargs", "[", "ATTR_BRIGHTNESS", "]", "if", "ATTR_TRANSITION", "in", "kwargs", ":", "data", "[", "\"transitiontime\"", "]", "=", "int", "(", "kwargs", "[", "ATTR_TRANSITION", "]", "*", "10", ")", "elif", "\"IKEA\"", "in", "self", ".", "_device", ".", "manufacturer", ":", "data", "[", "\"transitiontime\"", "]", "=", "0", "if", "ATTR_FLASH", "in", "kwargs", ":", "if", "kwargs", "[", "ATTR_FLASH", "]", "==", "FLASH_SHORT", ":", "data", "[", "\"alert\"", "]", "=", "\"select\"", "del", "data", "[", "\"on\"", "]", "elif", "kwargs", "[", "ATTR_FLASH", "]", "==", "FLASH_LONG", ":", "data", "[", "\"alert\"", "]", "=", "\"lselect\"", "del", "data", "[", "\"on\"", "]", "if", "ATTR_EFFECT", "in", "kwargs", ":", "if", "kwargs", "[", "ATTR_EFFECT", "]", "==", "EFFECT_COLORLOOP", ":", "data", "[", "\"effect\"", "]", "=", "\"colorloop\"", "else", ":", "data", "[", "\"effect\"", "]", "=", "\"none\"", "await", "self", ".", "_device", ".", "async_set_state", "(", "data", ")" ]
[ 153, 4 ]
[ 185, 48 ]
python
en
['en', 'et', 'en']
True
DeconzBaseLight.async_turn_off
(self, **kwargs)
Turn off light.
Turn off light.
async def async_turn_off(self, **kwargs): """Turn off light.""" if not self._device.state: return data = {"on": False} if ATTR_TRANSITION in kwargs: data["bri"] = 0 data["transitiontime"] = int(kwargs[ATTR_TRANSITION] * 10) if ATTR_FLASH in kwargs: if kwargs[ATTR_FLASH] == FLASH_SHORT: data["alert"] = "select" del data["on"] elif kwargs[ATTR_FLASH] == FLASH_LONG: data["alert"] = "lselect" del data["on"] await self._device.async_set_state(data)
[ "async", "def", "async_turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "_device", ".", "state", ":", "return", "data", "=", "{", "\"on\"", ":", "False", "}", "if", "ATTR_TRANSITION", "in", "kwargs", ":", "data", "[", "\"bri\"", "]", "=", "0", "data", "[", "\"transitiontime\"", "]", "=", "int", "(", "kwargs", "[", "ATTR_TRANSITION", "]", "*", "10", ")", "if", "ATTR_FLASH", "in", "kwargs", ":", "if", "kwargs", "[", "ATTR_FLASH", "]", "==", "FLASH_SHORT", ":", "data", "[", "\"alert\"", "]", "=", "\"select\"", "del", "data", "[", "\"on\"", "]", "elif", "kwargs", "[", "ATTR_FLASH", "]", "==", "FLASH_LONG", ":", "data", "[", "\"alert\"", "]", "=", "\"lselect\"", "del", "data", "[", "\"on\"", "]", "await", "self", ".", "_device", ".", "async_set_state", "(", "data", ")" ]
[ 187, 4 ]
[ 206, 48 ]
python
en
['en', 'zh', 'en']
True
DeconzBaseLight.device_state_attributes
(self)
Return the device state attributes.
Return the device state attributes.
def device_state_attributes(self): """Return the device state attributes.""" return {"is_deconz_group": self._device.type == "LightGroup"}
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "{", "\"is_deconz_group\"", ":", "self", ".", "_device", ".", "type", "==", "\"LightGroup\"", "}" ]
[ 209, 4 ]
[ 211, 69 ]
python
en
['en', 'en', 'en']
True
DeconzLight.max_mireds
(self)
Return the warmest color_temp that this light supports.
Return the warmest color_temp that this light supports.
def max_mireds(self): """Return the warmest color_temp that this light supports.""" return self._device.ctmax or super().max_mireds
[ "def", "max_mireds", "(", "self", ")", ":", "return", "self", ".", "_device", ".", "ctmax", "or", "super", "(", ")", ".", "max_mireds" ]
[ 218, 4 ]
[ 220, 55 ]
python
en
['en', 'en', 'en']
True
DeconzLight.min_mireds
(self)
Return the coldest color_temp that this light supports.
Return the coldest color_temp that this light supports.
def min_mireds(self): """Return the coldest color_temp that this light supports.""" return self._device.ctmin or super().min_mireds
[ "def", "min_mireds", "(", "self", ")", ":", "return", "self", ".", "_device", ".", "ctmin", "or", "super", "(", ")", ".", "min_mireds" ]
[ 223, 4 ]
[ 225, 55 ]
python
en
['en', 'en', 'en']
True
DeconzGroup.__init__
(self, device, gateway)
Set up group and create an unique id.
Set up group and create an unique id.
def __init__(self, device, gateway): """Set up group and create an unique id.""" group_id_base = gateway.config_entry.unique_id if CONF_GROUP_ID_BASE in gateway.config_entry.data: group_id_base = gateway.config_entry.data[CONF_GROUP_ID_BASE] self._unique_id = f"{group_id_base}-{device.deconz_id}" super().__init__(device, gateway)
[ "def", "__init__", "(", "self", ",", "device", ",", "gateway", ")", ":", "group_id_base", "=", "gateway", ".", "config_entry", ".", "unique_id", "if", "CONF_GROUP_ID_BASE", "in", "gateway", ".", "config_entry", ".", "data", ":", "group_id_base", "=", "gateway", ".", "config_entry", ".", "data", "[", "CONF_GROUP_ID_BASE", "]", "self", ".", "_unique_id", "=", "f\"{group_id_base}-{device.deconz_id}\"", "super", "(", ")", ".", "__init__", "(", "device", ",", "gateway", ")" ]
[ 231, 4 ]
[ 238, 41 ]
python
en
['en', 'en', 'en']
True
DeconzGroup.unique_id
(self)
Return a unique identifier for this device.
Return a unique identifier for this device.
def unique_id(self): """Return a unique identifier for this device.""" return self._unique_id
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_unique_id" ]
[ 241, 4 ]
[ 243, 30 ]
python
en
['en', 'en', 'en']
True
DeconzGroup.device_info
(self)
Return a device description for device registry.
Return a device description for device registry.
def device_info(self): """Return a device description for device registry.""" bridgeid = self.gateway.api.config.bridgeid return { "identifiers": {(DECONZ_DOMAIN, self.unique_id)}, "manufacturer": "Dresden Elektronik", "model": "deCONZ group", "name": self._device.name, "via_device": (DECONZ_DOMAIN, bridgeid), }
[ "def", "device_info", "(", "self", ")", ":", "bridgeid", "=", "self", ".", "gateway", ".", "api", ".", "config", ".", "bridgeid", "return", "{", "\"identifiers\"", ":", "{", "(", "DECONZ_DOMAIN", ",", "self", ".", "unique_id", ")", "}", ",", "\"manufacturer\"", ":", "\"Dresden Elektronik\"", ",", "\"model\"", ":", "\"deCONZ group\"", ",", "\"name\"", ":", "self", ".", "_device", ".", "name", ",", "\"via_device\"", ":", "(", "DECONZ_DOMAIN", ",", "bridgeid", ")", ",", "}" ]
[ 246, 4 ]
[ 256, 9 ]
python
en
['ro', 'fr', 'en']
False
DeconzGroup.device_state_attributes
(self)
Return the device state attributes.
Return the device state attributes.
def device_state_attributes(self): """Return the device state attributes.""" attributes = dict(super().device_state_attributes) attributes["all_on"] = self._device.all_on return attributes
[ "def", "device_state_attributes", "(", "self", ")", ":", "attributes", "=", "dict", "(", "super", "(", ")", ".", "device_state_attributes", ")", "attributes", "[", "\"all_on\"", "]", "=", "self", ".", "_device", ".", "all_on", "return", "attributes" ]
[ 259, 4 ]
[ 264, 25 ]
python
en
['en', 'en', 'en']
True
InsteonEntity.__init__
(self, device, group)
Initialize the INSTEON binary sensor.
Initialize the INSTEON binary sensor.
def __init__(self, device, group): """Initialize the INSTEON binary sensor.""" self._insteon_device_group = device.groups[group] self._insteon_device = device
[ "def", "__init__", "(", "self", ",", "device", ",", "group", ")", ":", "self", ".", "_insteon_device_group", "=", "device", ".", "groups", "[", "group", "]", "self", ".", "_insteon_device", "=", "device" ]
[ 29, 4 ]
[ 32, 37 ]
python
en
['en', 'pl', 'en']
True
InsteonEntity.__hash__
(self)
Return the hash of the Insteon Entity.
Return the hash of the Insteon Entity.
def __hash__(self): """Return the hash of the Insteon Entity.""" return hash(self._insteon_device)
[ "def", "__hash__", "(", "self", ")", ":", "return", "hash", "(", "self", ".", "_insteon_device", ")" ]
[ 34, 4 ]
[ 36, 41 ]
python
en
['en', 'en', 'en']
True
InsteonEntity.should_poll
(self)
No polling needed.
No polling needed.
def should_poll(self): """No polling needed.""" return False
[ "def", "should_poll", "(", "self", ")", ":", "return", "False" ]
[ 39, 4 ]
[ 41, 20 ]
python
en
['en', 'en', 'en']
True
InsteonEntity.address
(self)
Return the address of the node.
Return the address of the node.
def address(self): """Return the address of the node.""" return str(self._insteon_device.address)
[ "def", "address", "(", "self", ")", ":", "return", "str", "(", "self", ".", "_insteon_device", ".", "address", ")" ]
[ 44, 4 ]
[ 46, 48 ]
python
en
['en', 'en', 'en']
True
InsteonEntity.group
(self)
Return the INSTEON group that the entity responds to.
Return the INSTEON group that the entity responds to.
def group(self): """Return the INSTEON group that the entity responds to.""" return self._insteon_device_group.group
[ "def", "group", "(", "self", ")", ":", "return", "self", ".", "_insteon_device_group", ".", "group" ]
[ 49, 4 ]
[ 51, 47 ]
python
en
['en', 'en', 'en']
True
InsteonEntity.unique_id
(self)
Return a unique ID.
Return a unique ID.
def unique_id(self) -> str: """Return a unique ID.""" if self._insteon_device_group.group == 0x01: uid = self._insteon_device.id else: uid = f"{self._insteon_device.id}_{self._insteon_device_group.group}" return uid
[ "def", "unique_id", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_insteon_device_group", ".", "group", "==", "0x01", ":", "uid", "=", "self", ".", "_insteon_device", ".", "id", "else", ":", "uid", "=", "f\"{self._insteon_device.id}_{self._insteon_device_group.group}\"", "return", "uid" ]
[ 54, 4 ]
[ 60, 18 ]
python
ca
['fr', 'ca', 'en']
False
InsteonEntity.name
(self)
Return the name of the node (used for Entity_ID).
Return the name of the node (used for Entity_ID).
def name(self): """Return the name of the node (used for Entity_ID).""" # Set a base description description = self._insteon_device.description if description is None: description = "Unknown Device" # Get an extension label if there is one extension = self._get_label() if extension: extension = f" {extension}" return f"{description} {self._insteon_device.address}{extension}"
[ "def", "name", "(", "self", ")", ":", "# Set a base description", "description", "=", "self", ".", "_insteon_device", ".", "description", "if", "description", "is", "None", ":", "description", "=", "\"Unknown Device\"", "# Get an extension label if there is one", "extension", "=", "self", ".", "_get_label", "(", ")", "if", "extension", ":", "extension", "=", "f\" {extension}\"", "return", "f\"{description} {self._insteon_device.address}{extension}\"" ]
[ 63, 4 ]
[ 73, 73 ]
python
en
['en', 'en', 'en']
True
InsteonEntity.device_state_attributes
(self)
Provide attributes for display on device card.
Provide attributes for display on device card.
def device_state_attributes(self): """Provide attributes for display on device card.""" return {"insteon_address": self.address, "insteon_group": self.group}
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "{", "\"insteon_address\"", ":", "self", ".", "address", ",", "\"insteon_group\"", ":", "self", ".", "group", "}" ]
[ 76, 4 ]
[ 78, 77 ]
python
en
['en', 'en', 'en']
True
InsteonEntity.device_info
(self)
Return device information.
Return device information.
def device_info(self): """Return device information.""" return { "identifiers": {(DOMAIN, str(self._insteon_device.address))}, "name": f"{self._insteon_device.description} {self._insteon_device.address}", "model": f"{self._insteon_device.model} (0x{self._insteon_device.cat:02x}, 0x{self._insteon_device.subcat:02x})", "sw_version": f"{self._insteon_device.firmware:02x} Engine Version: {self._insteon_device.engine_version}", "manufacturer": "Smart Home", "via_device": (DOMAIN, str(devices.modem.address)), }
[ "def", "device_info", "(", "self", ")", ":", "return", "{", "\"identifiers\"", ":", "{", "(", "DOMAIN", ",", "str", "(", "self", ".", "_insteon_device", ".", "address", ")", ")", "}", ",", "\"name\"", ":", "f\"{self._insteon_device.description} {self._insteon_device.address}\"", ",", "\"model\"", ":", "f\"{self._insteon_device.model} (0x{self._insteon_device.cat:02x}, 0x{self._insteon_device.subcat:02x})\"", ",", "\"sw_version\"", ":", "f\"{self._insteon_device.firmware:02x} Engine Version: {self._insteon_device.engine_version}\"", ",", "\"manufacturer\"", ":", "\"Smart Home\"", ",", "\"via_device\"", ":", "(", "DOMAIN", ",", "str", "(", "devices", ".", "modem", ".", "address", ")", ")", ",", "}" ]
[ 81, 4 ]
[ 90, 9 ]
python
da
['es', 'da', 'en']
False
InsteonEntity.async_entity_update
(self, name, address, value, group)
Receive notification from transport that new data exists.
Receive notification from transport that new data exists.
def async_entity_update(self, name, address, value, group): """Receive notification from transport that new data exists.""" _LOGGER.debug( "Received update for device %s group %d value %s", address, group, value, ) self.async_write_ha_state()
[ "def", "async_entity_update", "(", "self", ",", "name", ",", "address", ",", "value", ",", "group", ")", ":", "_LOGGER", ".", "debug", "(", "\"Received update for device %s group %d value %s\"", ",", "address", ",", "group", ",", "value", ",", ")", "self", ".", "async_write_ha_state", "(", ")" ]
[ 93, 4 ]
[ 101, 35 ]
python
en
['en', 'en', 'en']
True
InsteonEntity.async_added_to_hass
(self)
Register INSTEON update events.
Register INSTEON update events.
async def async_added_to_hass(self): """Register INSTEON update events.""" _LOGGER.debug( "Tracking updates for device %s group %d name %s", self.address, self.group, self._insteon_device_group.name, ) self._insteon_device_group.subscribe(self.async_entity_update) load_signal = f"{self.entity_id}_{SIGNAL_LOAD_ALDB}" self.async_on_remove( async_dispatcher_connect(self.hass, load_signal, self._async_read_aldb) ) print_signal = f"{self.entity_id}_{SIGNAL_PRINT_ALDB}" async_dispatcher_connect(self.hass, print_signal, self._print_aldb) default_links_signal = f"{self.entity_id}_{SIGNAL_ADD_DEFAULT_LINKS}" async_dispatcher_connect( self.hass, default_links_signal, self._async_add_default_links ) remove_signal = f"{self._insteon_device.address.id}_{SIGNAL_REMOVE_ENTITY}" self.async_on_remove( async_dispatcher_connect(self.hass, remove_signal, self.async_remove) )
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "_LOGGER", ".", "debug", "(", "\"Tracking updates for device %s group %d name %s\"", ",", "self", ".", "address", ",", "self", ".", "group", ",", "self", ".", "_insteon_device_group", ".", "name", ",", ")", "self", ".", "_insteon_device_group", ".", "subscribe", "(", "self", ".", "async_entity_update", ")", "load_signal", "=", "f\"{self.entity_id}_{SIGNAL_LOAD_ALDB}\"", "self", ".", "async_on_remove", "(", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "load_signal", ",", "self", ".", "_async_read_aldb", ")", ")", "print_signal", "=", "f\"{self.entity_id}_{SIGNAL_PRINT_ALDB}\"", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "print_signal", ",", "self", ".", "_print_aldb", ")", "default_links_signal", "=", "f\"{self.entity_id}_{SIGNAL_ADD_DEFAULT_LINKS}\"", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "default_links_signal", ",", "self", ".", "_async_add_default_links", ")", "remove_signal", "=", "f\"{self._insteon_device.address.id}_{SIGNAL_REMOVE_ENTITY}\"", "self", ".", "async_on_remove", "(", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "remove_signal", ",", "self", ".", "async_remove", ")", ")" ]
[ 103, 4 ]
[ 125, 9 ]
python
en
['es', 'nl', 'en']
False
InsteonEntity.async_will_remove_from_hass
(self)
Unsubscribe to INSTEON update events.
Unsubscribe to INSTEON update events.
async def async_will_remove_from_hass(self): """Unsubscribe to INSTEON update events.""" _LOGGER.debug( "Remove tracking updates for device %s group %d name %s", self.address, self.group, self._insteon_device_group.name, ) self._insteon_device_group.unsubscribe(self.async_entity_update)
[ "async", "def", "async_will_remove_from_hass", "(", "self", ")", ":", "_LOGGER", ".", "debug", "(", "\"Remove tracking updates for device %s group %d name %s\"", ",", "self", ".", "address", ",", "self", ".", "group", ",", "self", ".", "_insteon_device_group", ".", "name", ",", ")", "self", ".", "_insteon_device_group", ".", "unsubscribe", "(", "self", ".", "async_entity_update", ")" ]
[ 127, 4 ]
[ 135, 72 ]
python
en
['en', 'en', 'en']
True
InsteonEntity._async_read_aldb
(self, reload)
Call device load process and print to log.
Call device load process and print to log.
async def _async_read_aldb(self, reload): """Call device load process and print to log.""" await self._insteon_device.aldb.async_load(refresh=reload) self._print_aldb() async_dispatcher_send(self.hass, SIGNAL_SAVE_DEVICES)
[ "async", "def", "_async_read_aldb", "(", "self", ",", "reload", ")", ":", "await", "self", ".", "_insteon_device", ".", "aldb", ".", "async_load", "(", "refresh", "=", "reload", ")", "self", ".", "_print_aldb", "(", ")", "async_dispatcher_send", "(", "self", ".", "hass", ",", "SIGNAL_SAVE_DEVICES", ")" ]
[ 137, 4 ]
[ 141, 61 ]
python
en
['en', 'en', 'en']
True
InsteonEntity._print_aldb
(self)
Print the device ALDB to the log file.
Print the device ALDB to the log file.
def _print_aldb(self): """Print the device ALDB to the log file.""" print_aldb_to_log(self._insteon_device.aldb)
[ "def", "_print_aldb", "(", "self", ")", ":", "print_aldb_to_log", "(", "self", ".", "_insteon_device", ".", "aldb", ")" ]
[ 143, 4 ]
[ 145, 52 ]
python
en
['en', 'en', 'en']
True
InsteonEntity._get_label
(self)
Get the device label for grouped devices.
Get the device label for grouped devices.
def _get_label(self): """Get the device label for grouped devices.""" label = "" if len(self._insteon_device.groups) > 1: if self._insteon_device_group.name in STATE_NAME_LABEL_MAP: label = STATE_NAME_LABEL_MAP[self._insteon_device_group.name] else: label = f"Group {self.group:d}" return label
[ "def", "_get_label", "(", "self", ")", ":", "label", "=", "\"\"", "if", "len", "(", "self", ".", "_insteon_device", ".", "groups", ")", ">", "1", ":", "if", "self", ".", "_insteon_device_group", ".", "name", "in", "STATE_NAME_LABEL_MAP", ":", "label", "=", "STATE_NAME_LABEL_MAP", "[", "self", ".", "_insteon_device_group", ".", "name", "]", "else", ":", "label", "=", "f\"Group {self.group:d}\"", "return", "label" ]
[ 147, 4 ]
[ 155, 20 ]
python
en
['en', 'en', 'en']
True
InsteonEntity._async_add_default_links
(self)
Add default links between the device and the modem.
Add default links between the device and the modem.
async def _async_add_default_links(self): """Add default links between the device and the modem.""" await self._insteon_device.async_add_default_links()
[ "async", "def", "_async_add_default_links", "(", "self", ")", ":", "await", "self", ".", "_insteon_device", ".", "async_add_default_links", "(", ")" ]
[ 157, 4 ]
[ 159, 60 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Add a AccuWeather weather entity from a config_entry.
Add a AccuWeather weather entity from a config_entry.
async def async_setup_entry(hass, config_entry, async_add_entities): """Add a AccuWeather weather entity from a config_entry.""" name = config_entry.data[CONF_NAME] coordinator = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR] async_add_entities([AccuWeatherEntity(name, coordinator)], False)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "name", "=", "config_entry", ".", "data", "[", "CONF_NAME", "]", "coordinator", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "config_entry", ".", "entry_id", "]", "[", "COORDINATOR", "]", "async_add_entities", "(", "[", "AccuWeatherEntity", "(", "name", ",", "coordinator", ")", "]", ",", "False", ")" ]
[ 31, 0 ]
[ 37, 69 ]
python
en
['en', 'en', 'en']
True
AccuWeatherEntity.__init__
(self, name, coordinator)
Initialize.
Initialize.
def __init__(self, name, coordinator): """Initialize.""" super().__init__(coordinator) self._name = name self._attrs = {} self._unit_system = "Metric" if self.coordinator.is_metric else "Imperial"
[ "def", "__init__", "(", "self", ",", "name", ",", "coordinator", ")", ":", "super", "(", ")", ".", "__init__", "(", "coordinator", ")", "self", ".", "_name", "=", "name", "self", ".", "_attrs", "=", "{", "}", "self", ".", "_unit_system", "=", "\"Metric\"", "if", "self", ".", "coordinator", ".", "is_metric", "else", "\"Imperial\"" ]
[ 43, 4 ]
[ 48, 82 ]
python
en
['en', 'en', 'it']
False
AccuWeatherEntity.name
(self)
Return the name.
Return the name.
def name(self): """Return the name.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 51, 4 ]
[ 53, 25 ]
python
en
['en', 'ig', 'en']
True
AccuWeatherEntity.attribution
(self)
Return the attribution.
Return the attribution.
def attribution(self): """Return the attribution.""" return ATTRIBUTION
[ "def", "attribution", "(", "self", ")", ":", "return", "ATTRIBUTION" ]
[ 56, 4 ]
[ 58, 26 ]
python
en
['en', 'ja', 'en']
True
AccuWeatherEntity.unique_id
(self)
Return a unique_id for this entity.
Return a unique_id for this entity.
def unique_id(self): """Return a unique_id for this entity.""" return self.coordinator.location_key
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "coordinator", ".", "location_key" ]
[ 61, 4 ]
[ 63, 44 ]
python
en
['en', 'en', 'en']
True
AccuWeatherEntity.device_info
(self)
Return the device info.
Return the device info.
def device_info(self): """Return the device info.""" return { "identifiers": {(DOMAIN, self.coordinator.location_key)}, "name": NAME, "manufacturer": MANUFACTURER, "entry_type": "service", }
[ "def", "device_info", "(", "self", ")", ":", "return", "{", "\"identifiers\"", ":", "{", "(", "DOMAIN", ",", "self", ".", "coordinator", ".", "location_key", ")", "}", ",", "\"name\"", ":", "NAME", ",", "\"manufacturer\"", ":", "MANUFACTURER", ",", "\"entry_type\"", ":", "\"service\"", ",", "}" ]
[ 66, 4 ]
[ 73, 9 ]
python
en
['en', 'en', 'en']
True
AccuWeatherEntity.condition
(self)
Return the current condition.
Return the current condition.
def condition(self): """Return the current condition.""" try: return [ k for k, v in CONDITION_CLASSES.items() if self.coordinator.data["WeatherIcon"] in v ][0] except IndexError: return None
[ "def", "condition", "(", "self", ")", ":", "try", ":", "return", "[", "k", "for", "k", ",", "v", "in", "CONDITION_CLASSES", ".", "items", "(", ")", "if", "self", ".", "coordinator", ".", "data", "[", "\"WeatherIcon\"", "]", "in", "v", "]", "[", "0", "]", "except", "IndexError", ":", "return", "None" ]
[ 76, 4 ]
[ 85, 23 ]
python
en
['en', 'en', 'en']
True
AccuWeatherEntity.temperature
(self)
Return the temperature.
Return the temperature.
def temperature(self): """Return the temperature.""" return self.coordinator.data["Temperature"][self._unit_system]["Value"]
[ "def", "temperature", "(", "self", ")", ":", "return", "self", ".", "coordinator", ".", "data", "[", "\"Temperature\"", "]", "[", "self", ".", "_unit_system", "]", "[", "\"Value\"", "]" ]
[ 88, 4 ]
[ 90, 79 ]
python
en
['en', 'la', 'en']
True
AccuWeatherEntity.temperature_unit
(self)
Return the unit of measurement.
Return the unit of measurement.
def temperature_unit(self): """Return the unit of measurement.""" return TEMP_CELSIUS if self.coordinator.is_metric else TEMP_FAHRENHEIT
[ "def", "temperature_unit", "(", "self", ")", ":", "return", "TEMP_CELSIUS", "if", "self", ".", "coordinator", ".", "is_metric", "else", "TEMP_FAHRENHEIT" ]
[ 93, 4 ]
[ 95, 78 ]
python
en
['en', 'la', 'en']
True
AccuWeatherEntity.pressure
(self)
Return the pressure.
Return the pressure.
def pressure(self): """Return the pressure.""" return self.coordinator.data["Pressure"][self._unit_system]["Value"]
[ "def", "pressure", "(", "self", ")", ":", "return", "self", ".", "coordinator", ".", "data", "[", "\"Pressure\"", "]", "[", "self", ".", "_unit_system", "]", "[", "\"Value\"", "]" ]
[ 98, 4 ]
[ 100, 76 ]
python
en
['en', 'ig', 'en']
True
AccuWeatherEntity.humidity
(self)
Return the humidity.
Return the humidity.
def humidity(self): """Return the humidity.""" return self.coordinator.data["RelativeHumidity"]
[ "def", "humidity", "(", "self", ")", ":", "return", "self", ".", "coordinator", ".", "data", "[", "\"RelativeHumidity\"", "]" ]
[ 103, 4 ]
[ 105, 56 ]
python
en
['en', 'sw', 'en']
True
AccuWeatherEntity.wind_speed
(self)
Return the wind speed.
Return the wind speed.
def wind_speed(self): """Return the wind speed.""" return self.coordinator.data["Wind"]["Speed"][self._unit_system]["Value"]
[ "def", "wind_speed", "(", "self", ")", ":", "return", "self", ".", "coordinator", ".", "data", "[", "\"Wind\"", "]", "[", "\"Speed\"", "]", "[", "self", ".", "_unit_system", "]", "[", "\"Value\"", "]" ]
[ 108, 4 ]
[ 110, 81 ]
python
en
['en', 'zh', 'en']
True
AccuWeatherEntity.wind_bearing
(self)
Return the wind bearing.
Return the wind bearing.
def wind_bearing(self): """Return the wind bearing.""" return self.coordinator.data["Wind"]["Direction"]["Degrees"]
[ "def", "wind_bearing", "(", "self", ")", ":", "return", "self", ".", "coordinator", ".", "data", "[", "\"Wind\"", "]", "[", "\"Direction\"", "]", "[", "\"Degrees\"", "]" ]
[ 113, 4 ]
[ 115, 68 ]
python
en
['en', 'ig', 'en']
True
AccuWeatherEntity.visibility
(self)
Return the visibility.
Return the visibility.
def visibility(self): """Return the visibility.""" return self.coordinator.data["Visibility"][self._unit_system]["Value"]
[ "def", "visibility", "(", "self", ")", ":", "return", "self", ".", "coordinator", ".", "data", "[", "\"Visibility\"", "]", "[", "self", ".", "_unit_system", "]", "[", "\"Value\"", "]" ]
[ 118, 4 ]
[ 120, 78 ]
python
en
['en', 'en', 'en']
True
AccuWeatherEntity.ozone
(self)
Return the ozone level.
Return the ozone level.
def ozone(self): """Return the ozone level.""" # We only have ozone data for certain locations and only in the forecast data. if self.coordinator.forecast and self.coordinator.data[ATTR_FORECAST][0].get( "Ozone" ): return self.coordinator.data[ATTR_FORECAST][0]["Ozone"]["Value"] return None
[ "def", "ozone", "(", "self", ")", ":", "# We only have ozone data for certain locations and only in the forecast data.", "if", "self", ".", "coordinator", ".", "forecast", "and", "self", ".", "coordinator", ".", "data", "[", "ATTR_FORECAST", "]", "[", "0", "]", ".", "get", "(", "\"Ozone\"", ")", ":", "return", "self", ".", "coordinator", ".", "data", "[", "ATTR_FORECAST", "]", "[", "0", "]", "[", "\"Ozone\"", "]", "[", "\"Value\"", "]", "return", "None" ]
[ 123, 4 ]
[ 130, 19 ]
python
en
['en', 'zu', 'en']
True
AccuWeatherEntity.forecast
(self)
Return the forecast array.
Return the forecast array.
def forecast(self): """Return the forecast array.""" if not self.coordinator.forecast: return None # remap keys from library to keys understood by the weather component forecast = [ { ATTR_FORECAST_TIME: utc_from_timestamp(item["EpochDate"]).isoformat(), ATTR_FORECAST_TEMP: item["TemperatureMax"]["Value"], ATTR_FORECAST_TEMP_LOW: item["TemperatureMin"]["Value"], ATTR_FORECAST_PRECIPITATION: self._calc_precipitation(item), ATTR_FORECAST_PRECIPITATION_PROBABILITY: round( mean( [ item["PrecipitationProbabilityDay"], item["PrecipitationProbabilityNight"], ] ) ), ATTR_FORECAST_WIND_SPEED: item["WindDay"]["Speed"]["Value"], ATTR_FORECAST_WIND_BEARING: item["WindDay"]["Direction"]["Degrees"], ATTR_FORECAST_CONDITION: [ k for k, v in CONDITION_CLASSES.items() if item["IconDay"] in v ][0], } for item in self.coordinator.data[ATTR_FORECAST] ] return forecast
[ "def", "forecast", "(", "self", ")", ":", "if", "not", "self", ".", "coordinator", ".", "forecast", ":", "return", "None", "# remap keys from library to keys understood by the weather component", "forecast", "=", "[", "{", "ATTR_FORECAST_TIME", ":", "utc_from_timestamp", "(", "item", "[", "\"EpochDate\"", "]", ")", ".", "isoformat", "(", ")", ",", "ATTR_FORECAST_TEMP", ":", "item", "[", "\"TemperatureMax\"", "]", "[", "\"Value\"", "]", ",", "ATTR_FORECAST_TEMP_LOW", ":", "item", "[", "\"TemperatureMin\"", "]", "[", "\"Value\"", "]", ",", "ATTR_FORECAST_PRECIPITATION", ":", "self", ".", "_calc_precipitation", "(", "item", ")", ",", "ATTR_FORECAST_PRECIPITATION_PROBABILITY", ":", "round", "(", "mean", "(", "[", "item", "[", "\"PrecipitationProbabilityDay\"", "]", ",", "item", "[", "\"PrecipitationProbabilityNight\"", "]", ",", "]", ")", ")", ",", "ATTR_FORECAST_WIND_SPEED", ":", "item", "[", "\"WindDay\"", "]", "[", "\"Speed\"", "]", "[", "\"Value\"", "]", ",", "ATTR_FORECAST_WIND_BEARING", ":", "item", "[", "\"WindDay\"", "]", "[", "\"Direction\"", "]", "[", "\"Degrees\"", "]", ",", "ATTR_FORECAST_CONDITION", ":", "[", "k", "for", "k", ",", "v", "in", "CONDITION_CLASSES", ".", "items", "(", ")", "if", "item", "[", "\"IconDay\"", "]", "in", "v", "]", "[", "0", "]", ",", "}", "for", "item", "in", "self", ".", "coordinator", ".", "data", "[", "ATTR_FORECAST", "]", "]", "return", "forecast" ]
[ 133, 4 ]
[ 160, 23 ]
python
en
['en', 'ga', 'en']
True
AccuWeatherEntity._calc_precipitation
(day: dict)
Return sum of the precipitation.
Return sum of the precipitation.
def _calc_precipitation(day: dict) -> float: """Return sum of the precipitation.""" precip_sum = 0 precip_types = ["Rain", "Snow", "Ice"] for precip in precip_types: precip_sum = sum( [ precip_sum, day[f"{precip}Day"]["Value"], day[f"{precip}Night"]["Value"], ] ) return round(precip_sum, 1)
[ "def", "_calc_precipitation", "(", "day", ":", "dict", ")", "->", "float", ":", "precip_sum", "=", "0", "precip_types", "=", "[", "\"Rain\"", ",", "\"Snow\"", ",", "\"Ice\"", "]", "for", "precip", "in", "precip_types", ":", "precip_sum", "=", "sum", "(", "[", "precip_sum", ",", "day", "[", "f\"{precip}Day\"", "]", "[", "\"Value\"", "]", ",", "day", "[", "f\"{precip}Night\"", "]", "[", "\"Value\"", "]", ",", "]", ")", "return", "round", "(", "precip_sum", ",", "1", ")" ]
[ 163, 4 ]
[ 175, 35 ]
python
en
['en', 'pt', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Netio platform.
Set up the Netio platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Netio platform.""" host = config.get(CONF_HOST) username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) port = config.get(CONF_PORT) if not DEVICES: hass.http.register_view(NetioApiView) dev = Netio(host, port, username, password) DEVICES[host] = Device(dev, []) # Throttle the update for all Netio switches of one Netio dev.update = util.Throttle(MIN_TIME_BETWEEN_SCANS)(dev.update) for key in config[CONF_OUTLETS]: switch = NetioSwitch(DEVICES[host].netio, key, config[CONF_OUTLETS][key]) DEVICES[host].entities.append(switch) add_entities(DEVICES[host].entities) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, dispose) return True
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "host", "=", "config", ".", "get", "(", "CONF_HOST", ")", "username", "=", "config", ".", "get", "(", "CONF_USERNAME", ")", "password", "=", "config", ".", "get", "(", "CONF_PASSWORD", ")", "port", "=", "config", ".", "get", "(", "CONF_PORT", ")", "if", "not", "DEVICES", ":", "hass", ".", "http", ".", "register_view", "(", "NetioApiView", ")", "dev", "=", "Netio", "(", "host", ",", "port", ",", "username", ",", "password", ")", "DEVICES", "[", "host", "]", "=", "Device", "(", "dev", ",", "[", "]", ")", "# Throttle the update for all Netio switches of one Netio", "dev", ".", "update", "=", "util", ".", "Throttle", "(", "MIN_TIME_BETWEEN_SCANS", ")", "(", "dev", ".", "update", ")", "for", "key", "in", "config", "[", "CONF_OUTLETS", "]", ":", "switch", "=", "NetioSwitch", "(", "DEVICES", "[", "host", "]", ".", "netio", ",", "key", ",", "config", "[", "CONF_OUTLETS", "]", "[", "key", "]", ")", "DEVICES", "[", "host", "]", ".", "entities", ".", "append", "(", "switch", ")", "add_entities", "(", "DEVICES", "[", "host", "]", ".", "entities", ")", "hass", ".", "bus", ".", "listen_once", "(", "EVENT_HOMEASSISTANT_STOP", ",", "dispose", ")", "return", "True" ]
[ 51, 0 ]
[ 76, 15 ]
python
en
['en', 'ky', 'en']
True
dispose
(event)
Close connections to Netio Devices.
Close connections to Netio Devices.
def dispose(event): """Close connections to Netio Devices.""" for value in DEVICES.values(): value.netio.stop()
[ "def", "dispose", "(", "event", ")", ":", "for", "value", "in", "DEVICES", ".", "values", "(", ")", ":", "value", ".", "netio", ".", "stop", "(", ")" ]
[ 79, 0 ]
[ 82, 26 ]
python
en
['en', 'en', 'en']
True
NetioApiView.get
(self, request, host)
Request handler.
Request handler.
def get(self, request, host): """Request handler.""" data = request.query states, consumptions, cumulated_consumptions, start_dates = [], [], [], [] for i in range(1, 5): out = "output%d" % i states.append(data.get("%s_state" % out) == STATE_ON) consumptions.append(float(data.get("%s_consumption" % out, 0))) cumulated_consumptions.append( float(data.get("%s_cumulatedConsumption" % out, 0)) / 1000 ) start_dates.append(data.get("%s_consumptionStart" % out, "")) _LOGGER.debug( "%s: %s, %s, %s since %s", host, states, consumptions, cumulated_consumptions, start_dates, ) ndev = DEVICES[host].netio ndev.consumptions = consumptions ndev.cumulated_consumptions = cumulated_consumptions ndev.states = states ndev.start_dates = start_dates for dev in DEVICES[host].entities: dev.async_write_ha_state() return self.json(True)
[ "def", "get", "(", "self", ",", "request", ",", "host", ")", ":", "data", "=", "request", ".", "query", "states", ",", "consumptions", ",", "cumulated_consumptions", ",", "start_dates", "=", "[", "]", ",", "[", "]", ",", "[", "]", ",", "[", "]", "for", "i", "in", "range", "(", "1", ",", "5", ")", ":", "out", "=", "\"output%d\"", "%", "i", "states", ".", "append", "(", "data", ".", "get", "(", "\"%s_state\"", "%", "out", ")", "==", "STATE_ON", ")", "consumptions", ".", "append", "(", "float", "(", "data", ".", "get", "(", "\"%s_consumption\"", "%", "out", ",", "0", ")", ")", ")", "cumulated_consumptions", ".", "append", "(", "float", "(", "data", ".", "get", "(", "\"%s_cumulatedConsumption\"", "%", "out", ",", "0", ")", ")", "/", "1000", ")", "start_dates", ".", "append", "(", "data", ".", "get", "(", "\"%s_consumptionStart\"", "%", "out", ",", "\"\"", ")", ")", "_LOGGER", ".", "debug", "(", "\"%s: %s, %s, %s since %s\"", ",", "host", ",", "states", ",", "consumptions", ",", "cumulated_consumptions", ",", "start_dates", ",", ")", "ndev", "=", "DEVICES", "[", "host", "]", ".", "netio", "ndev", ".", "consumptions", "=", "consumptions", "ndev", ".", "cumulated_consumptions", "=", "cumulated_consumptions", "ndev", ".", "states", "=", "states", "ndev", ".", "start_dates", "=", "start_dates", "for", "dev", "in", "DEVICES", "[", "host", "]", ".", "entities", ":", "dev", ".", "async_write_ha_state", "(", ")", "return", "self", ".", "json", "(", "True", ")" ]
[ 92, 4 ]
[ 124, 30 ]
python
en
['en', 'nl', 'en']
False
NetioSwitch.__init__
(self, netio, outlet, name)
Initialize the Netio switch.
Initialize the Netio switch.
def __init__(self, netio, outlet, name): """Initialize the Netio switch.""" self._name = name self.outlet = outlet self.netio = netio
[ "def", "__init__", "(", "self", ",", "netio", ",", "outlet", ",", "name", ")", ":", "self", ".", "_name", "=", "name", "self", ".", "outlet", "=", "outlet", "self", ".", "netio", "=", "netio" ]
[ 130, 4 ]
[ 134, 26 ]
python
en
['en', 'pl', 'en']
True
NetioSwitch.name
(self)
Return the device's name.
Return the device's name.
def name(self): """Return the device's name.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 137, 4 ]
[ 139, 25 ]
python
en
['en', 'en', 'en']
True
NetioSwitch.available
(self)
Return true if entity is available.
Return true if entity is available.
def available(self): """Return true if entity is available.""" return not hasattr(self, "telnet")
[ "def", "available", "(", "self", ")", ":", "return", "not", "hasattr", "(", "self", ",", "\"telnet\"", ")" ]
[ 142, 4 ]
[ 144, 42 ]
python
en
['en', 'en', 'en']
True
NetioSwitch.turn_on
(self, **kwargs)
Turn switch on.
Turn switch on.
def turn_on(self, **kwargs): """Turn switch on.""" self._set(True)
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_set", "(", "True", ")" ]
[ 146, 4 ]
[ 148, 23 ]
python
en
['en', 'en', 'en']
True
NetioSwitch.turn_off
(self, **kwargs)
Turn switch off.
Turn switch off.
def turn_off(self, **kwargs): """Turn switch off.""" self._set(False)
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_set", "(", "False", ")" ]
[ 150, 4 ]
[ 152, 24 ]
python
en
['en', 'en', 'en']
True
NetioSwitch.is_on
(self)
Return the switch's status.
Return the switch's status.
def is_on(self): """Return the switch's status.""" return self.netio.states[int(self.outlet) - 1]
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "netio", ".", "states", "[", "int", "(", "self", ".", "outlet", ")", "-", "1", "]" ]
[ 162, 4 ]
[ 164, 54 ]
python
en
['en', 'sn', 'en']
True
NetioSwitch.update
(self)
Update the state.
Update the state.
def update(self): """Update the state.""" self.netio.update()
[ "def", "update", "(", "self", ")", ":", "self", ".", "netio", ".", "update", "(", ")" ]
[ 166, 4 ]
[ 168, 27 ]
python
en
['en', 'en', 'en']
True
NetioSwitch.state_attributes
(self)
Return optional state attributes.
Return optional state attributes.
def state_attributes(self): """Return optional state attributes.""" return { ATTR_TOTAL_CONSUMPTION_KWH: self.cumulated_consumption_kwh, ATTR_START_DATE: self.start_date.split("|")[0], }
[ "def", "state_attributes", "(", "self", ")", ":", "return", "{", "ATTR_TOTAL_CONSUMPTION_KWH", ":", "self", ".", "cumulated_consumption_kwh", ",", "ATTR_START_DATE", ":", "self", ".", "start_date", ".", "split", "(", "\"|\"", ")", "[", "0", "]", ",", "}" ]
[ 171, 4 ]
[ 176, 9 ]
python
en
['en', 'en', 'en']
True
NetioSwitch.current_power_w
(self)
Return actual power.
Return actual power.
def current_power_w(self): """Return actual power.""" return self.netio.consumptions[int(self.outlet) - 1]
[ "def", "current_power_w", "(", "self", ")", ":", "return", "self", ".", "netio", ".", "consumptions", "[", "int", "(", "self", ".", "outlet", ")", "-", "1", "]" ]
[ 179, 4 ]
[ 181, 60 ]
python
en
['en', 'id', 'en']
True
NetioSwitch.cumulated_consumption_kwh
(self)
Return the total enerygy consumption since start_date.
Return the total enerygy consumption since start_date.
def cumulated_consumption_kwh(self): """Return the total enerygy consumption since start_date.""" return self.netio.cumulated_consumptions[int(self.outlet) - 1]
[ "def", "cumulated_consumption_kwh", "(", "self", ")", ":", "return", "self", ".", "netio", ".", "cumulated_consumptions", "[", "int", "(", "self", ".", "outlet", ")", "-", "1", "]" ]
[ 184, 4 ]
[ 186, 70 ]
python
en
['en', 'en', 'en']
True
NetioSwitch.start_date
(self)
Point in time when the energy accumulation started.
Point in time when the energy accumulation started.
def start_date(self): """Point in time when the energy accumulation started.""" return self.netio.start_dates[int(self.outlet) - 1]
[ "def", "start_date", "(", "self", ")", ":", "return", "self", ".", "netio", ".", "start_dates", "[", "int", "(", "self", ".", "outlet", ")", "-", "1", "]" ]
[ 189, 4 ]
[ 191, 59 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the sensor platform.
Set up the sensor platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the sensor platform.""" try: # initializing I2C bus using the auto-detected pins i2c = I2C(board.SCL, board.SDA) # initializing the sensor bmp280 = Adafruit_BMP280_I2C(i2c, address=config[CONF_I2C_ADDRESS]) except ValueError as error: # this usually happens when the board is I2C capable, but the device can't be found at the configured address if str(error.args[0]).startswith("No I2C device at address"): _LOGGER.error( "%s. Hint: Check wiring and make sure that the SDO pin is tied to either ground (0x76) or VCC (0x77)", error.args[0], ) raise PlatformNotReady() from error _LOGGER.error(error) return # use custom name if there's any name = config[CONF_NAME] # BMP280 has both temperature and pressure sensing capability add_entities( [Bmp280TemperatureSensor(bmp280, name), Bmp280PressureSensor(bmp280, name)] )
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "try", ":", "# initializing I2C bus using the auto-detected pins", "i2c", "=", "I2C", "(", "board", ".", "SCL", ",", "board", ".", "SDA", ")", "# initializing the sensor", "bmp280", "=", "Adafruit_BMP280_I2C", "(", "i2c", ",", "address", "=", "config", "[", "CONF_I2C_ADDRESS", "]", ")", "except", "ValueError", "as", "error", ":", "# this usually happens when the board is I2C capable, but the device can't be found at the configured address", "if", "str", "(", "error", ".", "args", "[", "0", "]", ")", ".", "startswith", "(", "\"No I2C device at address\"", ")", ":", "_LOGGER", ".", "error", "(", "\"%s. Hint: Check wiring and make sure that the SDO pin is tied to either ground (0x76) or VCC (0x77)\"", ",", "error", ".", "args", "[", "0", "]", ",", ")", "raise", "PlatformNotReady", "(", ")", "from", "error", "_LOGGER", ".", "error", "(", "error", ")", "return", "# use custom name if there's any", "name", "=", "config", "[", "CONF_NAME", "]", "# BMP280 has both temperature and pressure sensing capability", "add_entities", "(", "[", "Bmp280TemperatureSensor", "(", "bmp280", ",", "name", ")", ",", "Bmp280PressureSensor", "(", "bmp280", ",", "name", ")", "]", ")" ]
[ 42, 0 ]
[ 64, 5 ]
python
en
['en', 'da', 'en']
True
Bmp280Sensor.__init__
( self, bmp280: Adafruit_BMP280_I2C, name: str, unit_of_measurement: str, device_class: str, )
Initialize the sensor.
Initialize the sensor.
def __init__( self, bmp280: Adafruit_BMP280_I2C, name: str, unit_of_measurement: str, device_class: str, ): """Initialize the sensor.""" self._bmp280 = bmp280 self._name = name self._unit_of_measurement = unit_of_measurement self._device_class = device_class self._state = None self._errored = False
[ "def", "__init__", "(", "self", ",", "bmp280", ":", "Adafruit_BMP280_I2C", ",", "name", ":", "str", ",", "unit_of_measurement", ":", "str", ",", "device_class", ":", "str", ",", ")", ":", "self", ".", "_bmp280", "=", "bmp280", "self", ".", "_name", "=", "name", "self", ".", "_unit_of_measurement", "=", "unit_of_measurement", "self", ".", "_device_class", "=", "device_class", "self", ".", "_state", "=", "None", "self", ".", "_errored", "=", "False" ]
[ 70, 4 ]
[ 83, 29 ]
python
en
['en', 'en', 'en']
True
Bmp280Sensor.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" ]
[ 86, 4 ]
[ 88, 25 ]
python
en
['en', 'mi', 'en']
True
Bmp280Sensor.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" ]
[ 91, 4 ]
[ 93, 26 ]
python
en
['en', 'en', 'en']
True
Bmp280Sensor.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 self._unit_of_measurement
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "self", ".", "_unit_of_measurement" ]
[ 96, 4 ]
[ 98, 40 ]
python
en
['en', 'la', 'en']
True
Bmp280Sensor.device_class
(self)
Return the device class.
Return the device class.
def device_class(self): """Return the device class.""" return self._device_class
[ "def", "device_class", "(", "self", ")", ":", "return", "self", ".", "_device_class" ]
[ 101, 4 ]
[ 103, 33 ]
python
en
['en', 'en', 'en']
True
Bmp280Sensor.available
(self)
Return if the device is currently available.
Return if the device is currently available.
def available(self) -> bool: """Return if the device is currently available.""" return not self._errored
[ "def", "available", "(", "self", ")", "->", "bool", ":", "return", "not", "self", ".", "_errored" ]
[ 106, 4 ]
[ 108, 32 ]
python
en
['en', 'en', 'en']
True
Bmp280TemperatureSensor.__init__
(self, bmp280: Adafruit_BMP280_I2C, name: str)
Initialize the entity.
Initialize the entity.
def __init__(self, bmp280: Adafruit_BMP280_I2C, name: str): """Initialize the entity.""" super().__init__( bmp280, f"{name} Temperature", TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE )
[ "def", "__init__", "(", "self", ",", "bmp280", ":", "Adafruit_BMP280_I2C", ",", "name", ":", "str", ")", ":", "super", "(", ")", ".", "__init__", "(", "bmp280", ",", "f\"{name} Temperature\"", ",", "TEMP_CELSIUS", ",", "DEVICE_CLASS_TEMPERATURE", ")" ]
[ 114, 4 ]
[ 118, 9 ]
python
en
['en', 'en', 'en']
True
Bmp280TemperatureSensor.update
(self)
Fetch new state data for the sensor.
Fetch new state data for the sensor.
def update(self): """Fetch new state data for the sensor.""" try: self._state = round(self._bmp280.temperature, 1) if self._errored: _LOGGER.warning("Communication restored with temperature sensor") self._errored = False except OSError: # this is thrown when a working sensor is unplugged between two updates _LOGGER.warning( "Unable to read temperature data due to a communication problem" ) self._errored = True
[ "def", "update", "(", "self", ")", ":", "try", ":", "self", ".", "_state", "=", "round", "(", "self", ".", "_bmp280", ".", "temperature", ",", "1", ")", "if", "self", ".", "_errored", ":", "_LOGGER", ".", "warning", "(", "\"Communication restored with temperature sensor\"", ")", "self", ".", "_errored", "=", "False", "except", "OSError", ":", "# this is thrown when a working sensor is unplugged between two updates", "_LOGGER", ".", "warning", "(", "\"Unable to read temperature data due to a communication problem\"", ")", "self", ".", "_errored", "=", "True" ]
[ 121, 4 ]
[ 133, 32 ]
python
en
['en', 'en', 'en']
True
Bmp280PressureSensor.__init__
(self, bmp280: Adafruit_BMP280_I2C, name: str)
Initialize the entity.
Initialize the entity.
def __init__(self, bmp280: Adafruit_BMP280_I2C, name: str): """Initialize the entity.""" super().__init__( bmp280, f"{name} Pressure", PRESSURE_HPA, DEVICE_CLASS_PRESSURE )
[ "def", "__init__", "(", "self", ",", "bmp280", ":", "Adafruit_BMP280_I2C", ",", "name", ":", "str", ")", ":", "super", "(", ")", ".", "__init__", "(", "bmp280", ",", "f\"{name} Pressure\"", ",", "PRESSURE_HPA", ",", "DEVICE_CLASS_PRESSURE", ")" ]
[ 139, 4 ]
[ 143, 9 ]
python
en
['en', 'en', 'en']
True
Bmp280PressureSensor.update
(self)
Fetch new state data for the sensor.
Fetch new state data for the sensor.
def update(self): """Fetch new state data for the sensor.""" try: self._state = round(self._bmp280.pressure) if self._errored: _LOGGER.warning("Communication restored with pressure sensor") self._errored = False except OSError: # this is thrown when a working sensor is unplugged between two updates _LOGGER.warning( "Unable to read pressure data due to a communication problem" ) self._errored = True
[ "def", "update", "(", "self", ")", ":", "try", ":", "self", ".", "_state", "=", "round", "(", "self", ".", "_bmp280", ".", "pressure", ")", "if", "self", ".", "_errored", ":", "_LOGGER", ".", "warning", "(", "\"Communication restored with pressure sensor\"", ")", "self", ".", "_errored", "=", "False", "except", "OSError", ":", "# this is thrown when a working sensor is unplugged between two updates", "_LOGGER", ".", "warning", "(", "\"Unable to read pressure data due to a communication problem\"", ")", "self", ".", "_errored", "=", "True" ]
[ 146, 4 ]
[ 158, 32 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config, async_add_entities)
Initialize a Blink sensor.
Initialize a Blink sensor.
async def async_setup_entry(hass, config, async_add_entities): """Initialize a Blink sensor.""" data = hass.data[DOMAIN][config.entry_id] entities = [] for camera in data.cameras: for sensor_type in SENSORS: entities.append(BlinkSensor(data, camera, sensor_type)) async_add_entities(entities)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config", ",", "async_add_entities", ")", ":", "data", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "config", ".", "entry_id", "]", "entities", "=", "[", "]", "for", "camera", "in", "data", ".", "cameras", ":", "for", "sensor_type", "in", "SENSORS", ":", "entities", ".", "append", "(", "BlinkSensor", "(", "data", ",", "camera", ",", "sensor_type", ")", ")", "async_add_entities", "(", "entities", ")" ]
[ 25, 0 ]
[ 33, 32 ]
python
da
['en', 'da', 'it']
False
BlinkSensor.__init__
(self, data, camera, sensor_type)
Initialize sensors from Blink camera.
Initialize sensors from Blink camera.
def __init__(self, data, camera, sensor_type): """Initialize sensors from Blink camera.""" name, units, device_class = SENSORS[sensor_type] self._name = f"{DOMAIN} {camera} {name}" self._camera_name = name self._type = sensor_type self._device_class = device_class self.data = data self._camera = data.cameras[camera] self._state = None self._unit_of_measurement = units self._unique_id = f"{self._camera.serial}-{self._type}" self._sensor_key = self._type if self._type == "temperature": self._sensor_key = "temperature_calibrated"
[ "def", "__init__", "(", "self", ",", "data", ",", "camera", ",", "sensor_type", ")", ":", "name", ",", "units", ",", "device_class", "=", "SENSORS", "[", "sensor_type", "]", "self", ".", "_name", "=", "f\"{DOMAIN} {camera} {name}\"", "self", ".", "_camera_name", "=", "name", "self", ".", "_type", "=", "sensor_type", "self", ".", "_device_class", "=", "device_class", "self", ".", "data", "=", "data", "self", ".", "_camera", "=", "data", ".", "cameras", "[", "camera", "]", "self", ".", "_state", "=", "None", "self", ".", "_unit_of_measurement", "=", "units", "self", ".", "_unique_id", "=", "f\"{self._camera.serial}-{self._type}\"", "self", ".", "_sensor_key", "=", "self", ".", "_type", "if", "self", ".", "_type", "==", "\"temperature\"", ":", "self", ".", "_sensor_key", "=", "\"temperature_calibrated\"" ]
[ 39, 4 ]
[ 53, 55 ]
python
en
['en', 'en', 'en']
True
BlinkSensor.name
(self)
Return the name of the camera.
Return the name of the camera.
def name(self): """Return the name of the camera.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 56, 4 ]
[ 58, 25 ]
python
en
['en', 'en', 'en']
True
BlinkSensor.unique_id
(self)
Return the unique id for the camera sensor.
Return the unique id for the camera sensor.
def unique_id(self): """Return the unique id for the camera sensor.""" return self._unique_id
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_unique_id" ]
[ 61, 4 ]
[ 63, 30 ]
python
en
['en', 'it', 'en']
True
BlinkSensor.state
(self)
Return the camera's current state.
Return the camera's current state.
def state(self): """Return the camera's current state.""" return self._state
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "_state" ]
[ 66, 4 ]
[ 68, 26 ]
python
en
['en', 'en', 'en']
True
BlinkSensor.device_class
(self)
Return the device's class.
Return the device's class.
def device_class(self): """Return the device's class.""" return self._device_class
[ "def", "device_class", "(", "self", ")", ":", "return", "self", ".", "_device_class" ]
[ 71, 4 ]
[ 73, 33 ]
python
en
['en', 'en', 'en']
True
BlinkSensor.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 self._unit_of_measurement
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "self", ".", "_unit_of_measurement" ]
[ 76, 4 ]
[ 78, 40 ]
python
en
['en', 'la', 'en']
True