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
FluxSwitch.find_start_time
(self, now)
Return sunrise or start_time if given.
Return sunrise or start_time if given.
def find_start_time(self, now): """Return sunrise or start_time if given.""" if self._start_time: sunrise = now.replace( hour=self._start_time.hour, minute=self._start_time.minute, second=0 ) else: sunrise = get_astral_event_date(self.hass, SUN_EVENT_SUNRISE, now.date()) return sunrise
[ "def", "find_start_time", "(", "self", ",", "now", ")", ":", "if", "self", ".", "_start_time", ":", "sunrise", "=", "now", ".", "replace", "(", "hour", "=", "self", ".", "_start_time", ".", "hour", ",", "minute", "=", "self", ".", "_start_time", ".", "minute", ",", "second", "=", "0", ")", "else", ":", "sunrise", "=", "get_astral_event_date", "(", "self", ".", "hass", ",", "SUN_EVENT_SUNRISE", ",", "now", ".", "date", "(", ")", ")", "return", "sunrise" ]
[ 343, 4 ]
[ 351, 22 ]
python
en
['en', 'en', 'en']
True
FluxSwitch.find_stop_time
(self, now)
Return dusk or stop_time if given.
Return dusk or stop_time if given.
def find_stop_time(self, now): """Return dusk or stop_time if given.""" if self._stop_time: dusk = now.replace( hour=self._stop_time.hour, minute=self._stop_time.minute, second=0 ) else: dusk = get_astral_event_date(self.hass, "dusk", now.date()) return dusk
[ "def", "find_stop_time", "(", "self", ",", "now", ")", ":", "if", "self", ".", "_stop_time", ":", "dusk", "=", "now", ".", "replace", "(", "hour", "=", "self", ".", "_stop_time", ".", "hour", ",", "minute", "=", "self", ".", "_stop_time", ".", "minute", ",", "second", "=", "0", ")", "else", ":", "dusk", "=", "get_astral_event_date", "(", "self", ".", "hass", ",", "\"dusk\"", ",", "now", ".", "date", "(", ")", ")", "return", "dusk" ]
[ 353, 4 ]
[ 361, 19 ]
python
en
['en', 'en', 'en']
True
get_controller
( hass, host, username, password, port, site, verify_ssl, async_callback=None )
Create a controller object and verify authentication.
Create a controller object and verify authentication.
async def get_controller( hass, host, username, password, port, site, verify_ssl, async_callback=None ): """Create a controller object and verify authentication.""" sslcontext = None if verify_ssl: session = aiohttp_client.async_get_clientsession(hass) if isinstance(verify_ssl, str): sslcontext = ssl.create_default_context(cafile=verify_ssl) else: session = aiohttp_client.async_create_clientsession( hass, verify_ssl=verify_ssl, cookie_jar=CookieJar(unsafe=True) ) controller = aiounifi.Controller( host, username=username, password=password, port=port, site=site, websession=session, sslcontext=sslcontext, callback=async_callback, ) try: with async_timeout.timeout(10): await controller.check_unifi_os() await controller.login() return controller except aiounifi.Unauthorized as err: LOGGER.warning("Connected to UniFi at %s but not registered.", host) raise AuthenticationRequired from err except (asyncio.TimeoutError, aiounifi.RequestError) as err: LOGGER.error("Error connecting to the UniFi controller at %s", host) raise CannotConnect from err except aiounifi.AiounifiException as err: LOGGER.exception("Unknown UniFi communication error occurred") raise AuthenticationRequired from err
[ "async", "def", "get_controller", "(", "hass", ",", "host", ",", "username", ",", "password", ",", "port", ",", "site", ",", "verify_ssl", ",", "async_callback", "=", "None", ")", ":", "sslcontext", "=", "None", "if", "verify_ssl", ":", "session", "=", "aiohttp_client", ".", "async_get_clientsession", "(", "hass", ")", "if", "isinstance", "(", "verify_ssl", ",", "str", ")", ":", "sslcontext", "=", "ssl", ".", "create_default_context", "(", "cafile", "=", "verify_ssl", ")", "else", ":", "session", "=", "aiohttp_client", ".", "async_create_clientsession", "(", "hass", ",", "verify_ssl", "=", "verify_ssl", ",", "cookie_jar", "=", "CookieJar", "(", "unsafe", "=", "True", ")", ")", "controller", "=", "aiounifi", ".", "Controller", "(", "host", ",", "username", "=", "username", ",", "password", "=", "password", ",", "port", "=", "port", ",", "site", "=", "site", ",", "websession", "=", "session", ",", "sslcontext", "=", "sslcontext", ",", "callback", "=", "async_callback", ",", ")", "try", ":", "with", "async_timeout", ".", "timeout", "(", "10", ")", ":", "await", "controller", ".", "check_unifi_os", "(", ")", "await", "controller", ".", "login", "(", ")", "return", "controller", "except", "aiounifi", ".", "Unauthorized", "as", "err", ":", "LOGGER", ".", "warning", "(", "\"Connected to UniFi at %s but not registered.\"", ",", "host", ")", "raise", "AuthenticationRequired", "from", "err", "except", "(", "asyncio", ".", "TimeoutError", ",", "aiounifi", ".", "RequestError", ")", "as", "err", ":", "LOGGER", ".", "error", "(", "\"Error connecting to the UniFi controller at %s\"", ",", "host", ")", "raise", "CannotConnect", "from", "err", "except", "aiounifi", ".", "AiounifiException", "as", "err", ":", "LOGGER", ".", "exception", "(", "\"Unknown UniFi communication error occurred\"", ")", "raise", "AuthenticationRequired", "from", "err" ]
[ 430, 0 ]
[ 472, 45 ]
python
en
['en', 'en', 'en']
True
UniFiController.__init__
(self, hass, config_entry)
Initialize the system.
Initialize the system.
def __init__(self, hass, config_entry): """Initialize the system.""" self.hass = hass self.config_entry = config_entry self.available = True self.api = None self.progress = None self.wireless_clients = None self.listeners = [] self._site_name = None self._site_role = None self.entities = {}
[ "def", "__init__", "(", "self", ",", "hass", ",", "config_entry", ")", ":", "self", ".", "hass", "=", "hass", "self", ".", "config_entry", "=", "config_entry", "self", ".", "available", "=", "True", "self", ".", "api", "=", "None", "self", ".", "progress", "=", "None", "self", ".", "wireless_clients", "=", "None", "self", ".", "listeners", "=", "[", "]", "self", ".", "_site_name", "=", "None", "self", ".", "_site_role", "=", "None", "self", ".", "entities", "=", "{", "}" ]
[ 83, 4 ]
[ 96, 26 ]
python
en
['en', 'en', 'en']
True
UniFiController.controller_id
(self)
Return the controller ID.
Return the controller ID.
def controller_id(self): """Return the controller ID.""" return CONTROLLER_ID.format(host=self.host, site=self.site)
[ "def", "controller_id", "(", "self", ")", ":", "return", "CONTROLLER_ID", ".", "format", "(", "host", "=", "self", ".", "host", ",", "site", "=", "self", ".", "site", ")" ]
[ 99, 4 ]
[ 101, 67 ]
python
en
['en', 'en', 'en']
True
UniFiController.host
(self)
Return the host of this controller.
Return the host of this controller.
def host(self): """Return the host of this controller.""" return self.config_entry.data[CONF_CONTROLLER][CONF_HOST]
[ "def", "host", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "data", "[", "CONF_CONTROLLER", "]", "[", "CONF_HOST", "]" ]
[ 104, 4 ]
[ 106, 65 ]
python
en
['en', 'en', 'en']
True
UniFiController.site
(self)
Return the site of this config entry.
Return the site of this config entry.
def site(self): """Return the site of this config entry.""" return self.config_entry.data[CONF_CONTROLLER][CONF_SITE_ID]
[ "def", "site", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "data", "[", "CONF_CONTROLLER", "]", "[", "CONF_SITE_ID", "]" ]
[ 109, 4 ]
[ 111, 68 ]
python
en
['en', 'en', 'en']
True
UniFiController.site_name
(self)
Return the nice name of site.
Return the nice name of site.
def site_name(self): """Return the nice name of site.""" return self._site_name
[ "def", "site_name", "(", "self", ")", ":", "return", "self", ".", "_site_name" ]
[ 114, 4 ]
[ 116, 30 ]
python
en
['en', 'en', 'en']
True
UniFiController.site_role
(self)
Return the site user role of this controller.
Return the site user role of this controller.
def site_role(self): """Return the site user role of this controller.""" return self._site_role
[ "def", "site_role", "(", "self", ")", ":", "return", "self", ".", "_site_role" ]
[ 119, 4 ]
[ 121, 30 ]
python
en
['en', 'en', 'en']
True
UniFiController.mac
(self)
Return the mac address of this controller.
Return the mac address of this controller.
def mac(self): """Return the mac address of this controller.""" for client in self.api.clients.values(): if self.host == client.ip: return client.mac return None
[ "def", "mac", "(", "self", ")", ":", "for", "client", "in", "self", ".", "api", ".", "clients", ".", "values", "(", ")", ":", "if", "self", ".", "host", "==", "client", ".", "ip", ":", "return", "client", ".", "mac", "return", "None" ]
[ 124, 4 ]
[ 129, 19 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_track_clients
(self)
Config entry option to not track clients.
Config entry option to not track clients.
def option_track_clients(self): """Config entry option to not track clients.""" return self.config_entry.options.get(CONF_TRACK_CLIENTS, DEFAULT_TRACK_CLIENTS)
[ "def", "option_track_clients", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_TRACK_CLIENTS", ",", "DEFAULT_TRACK_CLIENTS", ")" ]
[ 134, 4 ]
[ 136, 87 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_track_wired_clients
(self)
Config entry option to not track wired clients.
Config entry option to not track wired clients.
def option_track_wired_clients(self): """Config entry option to not track wired clients.""" return self.config_entry.options.get( CONF_TRACK_WIRED_CLIENTS, DEFAULT_TRACK_WIRED_CLIENTS )
[ "def", "option_track_wired_clients", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_TRACK_WIRED_CLIENTS", ",", "DEFAULT_TRACK_WIRED_CLIENTS", ")" ]
[ 139, 4 ]
[ 143, 9 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_track_devices
(self)
Config entry option to not track devices.
Config entry option to not track devices.
def option_track_devices(self): """Config entry option to not track devices.""" return self.config_entry.options.get(CONF_TRACK_DEVICES, DEFAULT_TRACK_DEVICES)
[ "def", "option_track_devices", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_TRACK_DEVICES", ",", "DEFAULT_TRACK_DEVICES", ")" ]
[ 146, 4 ]
[ 148, 87 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_ssid_filter
(self)
Config entry option listing what SSIDs are being used to track clients.
Config entry option listing what SSIDs are being used to track clients.
def option_ssid_filter(self): """Config entry option listing what SSIDs are being used to track clients.""" return self.config_entry.options.get(CONF_SSID_FILTER, [])
[ "def", "option_ssid_filter", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_SSID_FILTER", ",", "[", "]", ")" ]
[ 151, 4 ]
[ 153, 66 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_detection_time
(self)
Config entry option defining number of seconds from last seen to away.
Config entry option defining number of seconds from last seen to away.
def option_detection_time(self): """Config entry option defining number of seconds from last seen to away.""" return timedelta( seconds=self.config_entry.options.get( CONF_DETECTION_TIME, DEFAULT_DETECTION_TIME ) )
[ "def", "option_detection_time", "(", "self", ")", ":", "return", "timedelta", "(", "seconds", "=", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_DETECTION_TIME", ",", "DEFAULT_DETECTION_TIME", ")", ")" ]
[ 156, 4 ]
[ 162, 9 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_ignore_wired_bug
(self)
Config entry option to ignore wired bug.
Config entry option to ignore wired bug.
def option_ignore_wired_bug(self): """Config entry option to ignore wired bug.""" return self.config_entry.options.get( CONF_IGNORE_WIRED_BUG, DEFAULT_IGNORE_WIRED_BUG )
[ "def", "option_ignore_wired_bug", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_IGNORE_WIRED_BUG", ",", "DEFAULT_IGNORE_WIRED_BUG", ")" ]
[ 165, 4 ]
[ 169, 9 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_poe_clients
(self)
Config entry option to control poe clients.
Config entry option to control poe clients.
def option_poe_clients(self): """Config entry option to control poe clients.""" return self.config_entry.options.get(CONF_POE_CLIENTS, DEFAULT_POE_CLIENTS)
[ "def", "option_poe_clients", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_POE_CLIENTS", ",", "DEFAULT_POE_CLIENTS", ")" ]
[ 174, 4 ]
[ 176, 83 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_block_clients
(self)
Config entry option with list of clients to control network access.
Config entry option with list of clients to control network access.
def option_block_clients(self): """Config entry option with list of clients to control network access.""" return self.config_entry.options.get(CONF_BLOCK_CLIENT, [])
[ "def", "option_block_clients", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_BLOCK_CLIENT", ",", "[", "]", ")" ]
[ 179, 4 ]
[ 181, 67 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_dpi_restrictions
(self)
Config entry option to control DPI restriction groups.
Config entry option to control DPI restriction groups.
def option_dpi_restrictions(self): """Config entry option to control DPI restriction groups.""" return self.config_entry.options.get( CONF_DPI_RESTRICTIONS, DEFAULT_DPI_RESTRICTIONS )
[ "def", "option_dpi_restrictions", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_DPI_RESTRICTIONS", ",", "DEFAULT_DPI_RESTRICTIONS", ")" ]
[ 184, 4 ]
[ 188, 9 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_allow_bandwidth_sensors
(self)
Config entry option to allow bandwidth sensors.
Config entry option to allow bandwidth sensors.
def option_allow_bandwidth_sensors(self): """Config entry option to allow bandwidth sensors.""" return self.config_entry.options.get( CONF_ALLOW_BANDWIDTH_SENSORS, DEFAULT_ALLOW_BANDWIDTH_SENSORS )
[ "def", "option_allow_bandwidth_sensors", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_ALLOW_BANDWIDTH_SENSORS", ",", "DEFAULT_ALLOW_BANDWIDTH_SENSORS", ")" ]
[ 193, 4 ]
[ 197, 9 ]
python
en
['en', 'en', 'en']
True
UniFiController.option_allow_uptime_sensors
(self)
Config entry option to allow uptime sensors.
Config entry option to allow uptime sensors.
def option_allow_uptime_sensors(self): """Config entry option to allow uptime sensors.""" return self.config_entry.options.get( CONF_ALLOW_UPTIME_SENSORS, DEFAULT_ALLOW_UPTIME_SENSORS )
[ "def", "option_allow_uptime_sensors", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_ALLOW_UPTIME_SENSORS", ",", "DEFAULT_ALLOW_UPTIME_SENSORS", ")" ]
[ 200, 4 ]
[ 204, 9 ]
python
en
['en', 'en', 'en']
True
UniFiController.async_unifi_signalling_callback
(self, signal, data)
Handle messages back from UniFi library.
Handle messages back from UniFi library.
def async_unifi_signalling_callback(self, signal, data): """Handle messages back from UniFi library.""" if signal == SIGNAL_CONNECTION_STATE: if data == STATE_DISCONNECTED and self.available: LOGGER.warning("Lost connection to UniFi controller") if (data == STATE_RUNNING and not self.available) or ( data == STATE_DISCONNECTED and self.available ): self.available = data == STATE_RUNNING async_dispatcher_send(self.hass, self.signal_reachable) if not self.available: self.hass.loop.call_later(RETRY_TIMER, self.reconnect, True) else: LOGGER.info("Connected to UniFi controller") elif signal == SIGNAL_DATA and data: if DATA_EVENT in data: clients_connected = set() devices_connected = set() wireless_clients_connected = False for event in data[DATA_EVENT]: if event.event in CLIENT_CONNECTED: clients_connected.add(event.mac) if not wireless_clients_connected and event.event in ( WIRELESS_CLIENT_CONNECTED, WIRELESS_GUEST_CONNECTED, ): wireless_clients_connected = True elif event.event in DEVICE_CONNECTED: devices_connected.add(event.mac) if wireless_clients_connected: self.update_wireless_clients() if clients_connected or devices_connected: async_dispatcher_send( self.hass, self.signal_update, clients_connected, devices_connected, ) elif DATA_CLIENT_REMOVED in data: async_dispatcher_send( self.hass, self.signal_remove, data[DATA_CLIENT_REMOVED] ) elif DATA_DPI_GROUP in data: for key in data[DATA_DPI_GROUP]: if self.api.dpi_groups[key].dpiapp_ids: async_dispatcher_send(self.hass, self.signal_update) else: async_dispatcher_send(self.hass, self.signal_remove, {key}) elif DATA_DPI_GROUP_REMOVED in data: async_dispatcher_send( self.hass, self.signal_remove, data[DATA_DPI_GROUP_REMOVED] )
[ "def", "async_unifi_signalling_callback", "(", "self", ",", "signal", ",", "data", ")", ":", "if", "signal", "==", "SIGNAL_CONNECTION_STATE", ":", "if", "data", "==", "STATE_DISCONNECTED", "and", "self", ".", "available", ":", "LOGGER", ".", "warning", "(", "\"Lost connection to UniFi controller\"", ")", "if", "(", "data", "==", "STATE_RUNNING", "and", "not", "self", ".", "available", ")", "or", "(", "data", "==", "STATE_DISCONNECTED", "and", "self", ".", "available", ")", ":", "self", ".", "available", "=", "data", "==", "STATE_RUNNING", "async_dispatcher_send", "(", "self", ".", "hass", ",", "self", ".", "signal_reachable", ")", "if", "not", "self", ".", "available", ":", "self", ".", "hass", ".", "loop", ".", "call_later", "(", "RETRY_TIMER", ",", "self", ".", "reconnect", ",", "True", ")", "else", ":", "LOGGER", ".", "info", "(", "\"Connected to UniFi controller\"", ")", "elif", "signal", "==", "SIGNAL_DATA", "and", "data", ":", "if", "DATA_EVENT", "in", "data", ":", "clients_connected", "=", "set", "(", ")", "devices_connected", "=", "set", "(", ")", "wireless_clients_connected", "=", "False", "for", "event", "in", "data", "[", "DATA_EVENT", "]", ":", "if", "event", ".", "event", "in", "CLIENT_CONNECTED", ":", "clients_connected", ".", "add", "(", "event", ".", "mac", ")", "if", "not", "wireless_clients_connected", "and", "event", ".", "event", "in", "(", "WIRELESS_CLIENT_CONNECTED", ",", "WIRELESS_GUEST_CONNECTED", ",", ")", ":", "wireless_clients_connected", "=", "True", "elif", "event", ".", "event", "in", "DEVICE_CONNECTED", ":", "devices_connected", ".", "add", "(", "event", ".", "mac", ")", "if", "wireless_clients_connected", ":", "self", ".", "update_wireless_clients", "(", ")", "if", "clients_connected", "or", "devices_connected", ":", "async_dispatcher_send", "(", "self", ".", "hass", ",", "self", ".", "signal_update", ",", "clients_connected", ",", "devices_connected", ",", ")", "elif", "DATA_CLIENT_REMOVED", "in", "data", ":", "async_dispatcher_send", "(", "self", ".", "hass", ",", "self", ".", "signal_remove", ",", "data", "[", "DATA_CLIENT_REMOVED", "]", ")", "elif", "DATA_DPI_GROUP", "in", "data", ":", "for", "key", "in", "data", "[", "DATA_DPI_GROUP", "]", ":", "if", "self", ".", "api", ".", "dpi_groups", "[", "key", "]", ".", "dpiapp_ids", ":", "async_dispatcher_send", "(", "self", ".", "hass", ",", "self", ".", "signal_update", ")", "else", ":", "async_dispatcher_send", "(", "self", ".", "hass", ",", "self", ".", "signal_remove", ",", "{", "key", "}", ")", "elif", "DATA_DPI_GROUP_REMOVED", "in", "data", ":", "async_dispatcher_send", "(", "self", ".", "hass", ",", "self", ".", "signal_remove", ",", "data", "[", "DATA_DPI_GROUP_REMOVED", "]", ")" ]
[ 207, 4 ]
[ 271, 17 ]
python
en
['en', 'en', 'en']
True
UniFiController.signal_reachable
(self)
Integration specific event to signal a change in connection status.
Integration specific event to signal a change in connection status.
def signal_reachable(self) -> str: """Integration specific event to signal a change in connection status.""" return f"unifi-reachable-{self.controller_id}"
[ "def", "signal_reachable", "(", "self", ")", "->", "str", ":", "return", "f\"unifi-reachable-{self.controller_id}\"" ]
[ 274, 4 ]
[ 276, 54 ]
python
en
['en', 'en', 'en']
True
UniFiController.signal_update
(self)
Event specific per UniFi entry to signal new data.
Event specific per UniFi entry to signal new data.
def signal_update(self): """Event specific per UniFi entry to signal new data.""" return f"unifi-update-{self.controller_id}"
[ "def", "signal_update", "(", "self", ")", ":", "return", "f\"unifi-update-{self.controller_id}\"" ]
[ 279, 4 ]
[ 281, 51 ]
python
en
['en', 'en', 'it']
True
UniFiController.signal_remove
(self)
Event specific per UniFi entry to signal removal of entities.
Event specific per UniFi entry to signal removal of entities.
def signal_remove(self): """Event specific per UniFi entry to signal removal of entities.""" return f"unifi-remove-{self.controller_id}"
[ "def", "signal_remove", "(", "self", ")", ":", "return", "f\"unifi-remove-{self.controller_id}\"" ]
[ 284, 4 ]
[ 286, 51 ]
python
en
['en', 'en', 'en']
True
UniFiController.signal_options_update
(self)
Event specific per UniFi entry to signal new options.
Event specific per UniFi entry to signal new options.
def signal_options_update(self): """Event specific per UniFi entry to signal new options.""" return f"unifi-options-{self.controller_id}"
[ "def", "signal_options_update", "(", "self", ")", ":", "return", "f\"unifi-options-{self.controller_id}\"" ]
[ 289, 4 ]
[ 291, 52 ]
python
en
['en', 'en', 'en']
True
UniFiController.update_wireless_clients
(self)
Update set of known to be wireless clients.
Update set of known to be wireless clients.
def update_wireless_clients(self): """Update set of known to be wireless clients.""" new_wireless_clients = set() for client_id in self.api.clients: if ( client_id not in self.wireless_clients and not self.api.clients[client_id].is_wired ): new_wireless_clients.add(client_id) if new_wireless_clients: self.wireless_clients |= new_wireless_clients unifi_wireless_clients = self.hass.data[UNIFI_WIRELESS_CLIENTS] unifi_wireless_clients.update_data(self.wireless_clients, self.config_entry)
[ "def", "update_wireless_clients", "(", "self", ")", ":", "new_wireless_clients", "=", "set", "(", ")", "for", "client_id", "in", "self", ".", "api", ".", "clients", ":", "if", "(", "client_id", "not", "in", "self", ".", "wireless_clients", "and", "not", "self", ".", "api", ".", "clients", "[", "client_id", "]", ".", "is_wired", ")", ":", "new_wireless_clients", ".", "add", "(", "client_id", ")", "if", "new_wireless_clients", ":", "self", ".", "wireless_clients", "|=", "new_wireless_clients", "unifi_wireless_clients", "=", "self", ".", "hass", ".", "data", "[", "UNIFI_WIRELESS_CLIENTS", "]", "unifi_wireless_clients", ".", "update_data", "(", "self", ".", "wireless_clients", ",", "self", ".", "config_entry", ")" ]
[ 293, 4 ]
[ 307, 88 ]
python
en
['en', 'en', 'en']
True
UniFiController.async_setup
(self)
Set up a UniFi controller.
Set up a UniFi controller.
async def async_setup(self): """Set up a UniFi controller.""" try: self.api = await get_controller( self.hass, **self.config_entry.data[CONF_CONTROLLER], async_callback=self.async_unifi_signalling_callback, ) await self.api.initialize() sites = await self.api.sites() for site in sites.values(): if self.site == site["name"]: self._site_name = site["desc"] break description = await self.api.site_description() self._site_role = description[0]["site_role"] except CannotConnect as err: raise ConfigEntryNotReady from err except Exception as err: # pylint: disable=broad-except LOGGER.error("Unknown error connecting with UniFi controller: %s", err) return False # Restore clients that is not a part of active clients list. entity_registry = await self.hass.helpers.entity_registry.async_get_registry() for entity in entity_registry.entities.values(): if ( entity.config_entry_id != self.config_entry.entry_id or "-" not in entity.unique_id ): continue mac = "" if entity.domain == TRACKER_DOMAIN: mac, _ = entity.unique_id.split("-", 1) elif entity.domain == SWITCH_DOMAIN: _, mac = entity.unique_id.split("-", 1) if mac in self.api.clients or mac not in self.api.clients_all: continue client = self.api.clients_all[mac] self.api.clients.process_raw([client.raw]) LOGGER.debug( "Restore disconnected client %s (%s)", entity.entity_id, client.mac, ) wireless_clients = self.hass.data[UNIFI_WIRELESS_CLIENTS] self.wireless_clients = wireless_clients.get_data(self.config_entry) self.update_wireless_clients() for platform in SUPPORTED_PLATFORMS: self.hass.async_create_task( self.hass.config_entries.async_forward_entry_setup( self.config_entry, platform ) ) self.api.start_websocket() self.config_entry.add_update_listener(self.async_config_entry_updated) return True
[ "async", "def", "async_setup", "(", "self", ")", ":", "try", ":", "self", ".", "api", "=", "await", "get_controller", "(", "self", ".", "hass", ",", "*", "*", "self", ".", "config_entry", ".", "data", "[", "CONF_CONTROLLER", "]", ",", "async_callback", "=", "self", ".", "async_unifi_signalling_callback", ",", ")", "await", "self", ".", "api", ".", "initialize", "(", ")", "sites", "=", "await", "self", ".", "api", ".", "sites", "(", ")", "for", "site", "in", "sites", ".", "values", "(", ")", ":", "if", "self", ".", "site", "==", "site", "[", "\"name\"", "]", ":", "self", ".", "_site_name", "=", "site", "[", "\"desc\"", "]", "break", "description", "=", "await", "self", ".", "api", ".", "site_description", "(", ")", "self", ".", "_site_role", "=", "description", "[", "0", "]", "[", "\"site_role\"", "]", "except", "CannotConnect", "as", "err", ":", "raise", "ConfigEntryNotReady", "from", "err", "except", "Exception", "as", "err", ":", "# pylint: disable=broad-except", "LOGGER", ".", "error", "(", "\"Unknown error connecting with UniFi controller: %s\"", ",", "err", ")", "return", "False", "# Restore clients that is not a part of active clients list.", "entity_registry", "=", "await", "self", ".", "hass", ".", "helpers", ".", "entity_registry", ".", "async_get_registry", "(", ")", "for", "entity", "in", "entity_registry", ".", "entities", ".", "values", "(", ")", ":", "if", "(", "entity", ".", "config_entry_id", "!=", "self", ".", "config_entry", ".", "entry_id", "or", "\"-\"", "not", "in", "entity", ".", "unique_id", ")", ":", "continue", "mac", "=", "\"\"", "if", "entity", ".", "domain", "==", "TRACKER_DOMAIN", ":", "mac", ",", "_", "=", "entity", ".", "unique_id", ".", "split", "(", "\"-\"", ",", "1", ")", "elif", "entity", ".", "domain", "==", "SWITCH_DOMAIN", ":", "_", ",", "mac", "=", "entity", ".", "unique_id", ".", "split", "(", "\"-\"", ",", "1", ")", "if", "mac", "in", "self", ".", "api", ".", "clients", "or", "mac", "not", "in", "self", ".", "api", ".", "clients_all", ":", "continue", "client", "=", "self", ".", "api", ".", "clients_all", "[", "mac", "]", "self", ".", "api", ".", "clients", ".", "process_raw", "(", "[", "client", ".", "raw", "]", ")", "LOGGER", ".", "debug", "(", "\"Restore disconnected client %s (%s)\"", ",", "entity", ".", "entity_id", ",", "client", ".", "mac", ",", ")", "wireless_clients", "=", "self", ".", "hass", ".", "data", "[", "UNIFI_WIRELESS_CLIENTS", "]", "self", ".", "wireless_clients", "=", "wireless_clients", ".", "get_data", "(", "self", ".", "config_entry", ")", "self", ".", "update_wireless_clients", "(", ")", "for", "platform", "in", "SUPPORTED_PLATFORMS", ":", "self", ".", "hass", ".", "async_create_task", "(", "self", ".", "hass", ".", "config_entries", ".", "async_forward_entry_setup", "(", "self", ".", "config_entry", ",", "platform", ")", ")", "self", ".", "api", ".", "start_websocket", "(", ")", "self", ".", "config_entry", ".", "add_update_listener", "(", "self", ".", "async_config_entry_updated", ")", "return", "True" ]
[ 309, 4 ]
[ 377, 19 ]
python
en
['en', 'su', 'en']
True
UniFiController.async_config_entry_updated
(hass, config_entry)
Handle signals of config entry being updated.
Handle signals of config entry being updated.
async def async_config_entry_updated(hass, config_entry) -> None: """Handle signals of config entry being updated.""" controller = hass.data[UNIFI_DOMAIN][config_entry.entry_id] async_dispatcher_send(hass, controller.signal_options_update)
[ "async", "def", "async_config_entry_updated", "(", "hass", ",", "config_entry", ")", "->", "None", ":", "controller", "=", "hass", ".", "data", "[", "UNIFI_DOMAIN", "]", "[", "config_entry", ".", "entry_id", "]", "async_dispatcher_send", "(", "hass", ",", "controller", ".", "signal_options_update", ")" ]
[ 380, 4 ]
[ 383, 69 ]
python
en
['en', 'en', 'en']
True
UniFiController.reconnect
(self, log=False)
Prepare to reconnect UniFi session.
Prepare to reconnect UniFi session.
def reconnect(self, log=False) -> None: """Prepare to reconnect UniFi session.""" if log: LOGGER.info("Will try to reconnect to UniFi controller") self.hass.loop.create_task(self.async_reconnect())
[ "def", "reconnect", "(", "self", ",", "log", "=", "False", ")", "->", "None", ":", "if", "log", ":", "LOGGER", ".", "info", "(", "\"Will try to reconnect to UniFi controller\"", ")", "self", ".", "hass", ".", "loop", ".", "create_task", "(", "self", ".", "async_reconnect", "(", ")", ")" ]
[ 386, 4 ]
[ 390, 58 ]
python
en
['en', 'it', 'en']
True
UniFiController.async_reconnect
(self)
Try to reconnect UniFi session.
Try to reconnect UniFi session.
async def async_reconnect(self) -> None: """Try to reconnect UniFi session.""" try: with async_timeout.timeout(5): await self.api.login() self.api.start_websocket() except (asyncio.TimeoutError, aiounifi.AiounifiException): self.hass.loop.call_later(RETRY_TIMER, self.reconnect)
[ "async", "def", "async_reconnect", "(", "self", ")", "->", "None", ":", "try", ":", "with", "async_timeout", ".", "timeout", "(", "5", ")", ":", "await", "self", ".", "api", ".", "login", "(", ")", "self", ".", "api", ".", "start_websocket", "(", ")", "except", "(", "asyncio", ".", "TimeoutError", ",", "aiounifi", ".", "AiounifiException", ")", ":", "self", ".", "hass", ".", "loop", ".", "call_later", "(", "RETRY_TIMER", ",", "self", ".", "reconnect", ")" ]
[ 392, 4 ]
[ 400, 66 ]
python
en
['en', 'en', 'en']
True
UniFiController.shutdown
(self, event)
Wrap the call to unifi.close. Used as an argument to EventBus.async_listen_once.
Wrap the call to unifi.close.
def shutdown(self, event) -> None: """Wrap the call to unifi.close. Used as an argument to EventBus.async_listen_once. """ self.api.stop_websocket()
[ "def", "shutdown", "(", "self", ",", "event", ")", "->", "None", ":", "self", ".", "api", ".", "stop_websocket", "(", ")" ]
[ 403, 4 ]
[ 408, 33 ]
python
en
['en', 'pt', 'en']
True
UniFiController.async_reset
(self)
Reset this controller to default state. Will cancel any scheduled setup retry and will unload the config entry.
Reset this controller to default state.
async def async_reset(self): """Reset this controller to default state. Will cancel any scheduled setup retry and will unload the config entry. """ self.api.stop_websocket() for platform in SUPPORTED_PLATFORMS: await self.hass.config_entries.async_forward_entry_unload( self.config_entry, platform ) for unsub_dispatcher in self.listeners: unsub_dispatcher() self.listeners = [] return True
[ "async", "def", "async_reset", "(", "self", ")", ":", "self", ".", "api", ".", "stop_websocket", "(", ")", "for", "platform", "in", "SUPPORTED_PLATFORMS", ":", "await", "self", ".", "hass", ".", "config_entries", ".", "async_forward_entry_unload", "(", "self", ".", "config_entry", ",", "platform", ")", "for", "unsub_dispatcher", "in", "self", ".", "listeners", ":", "unsub_dispatcher", "(", ")", "self", ".", "listeners", "=", "[", "]", "return", "True" ]
[ 410, 4 ]
[ 427, 19 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up the Monoprice 6-zone amplifier platform.
Set up the Monoprice 6-zone amplifier platform.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Monoprice 6-zone amplifier platform.""" port = config_entry.data[CONF_PORT] monoprice = hass.data[DOMAIN][config_entry.entry_id][MONOPRICE_OBJECT] sources = _get_sources(config_entry) entities = [] for i in range(1, 4): for j in range(1, 7): zone_id = (i * 10) + j _LOGGER.info("Adding zone %d for port %s", zone_id, port) entities.append( MonopriceZone(monoprice, sources, config_entry.entry_id, zone_id) ) # only call update before add if it's the first run so we can try to detect zones first_run = hass.data[DOMAIN][config_entry.entry_id][FIRST_RUN] async_add_entities(entities, first_run) platform = entity_platform.current_platform.get() def _call_service(entities, service_call): for entity in entities: if service_call.service == SERVICE_SNAPSHOT: entity.snapshot() elif service_call.service == SERVICE_RESTORE: entity.restore() @service.verify_domain_control(hass, DOMAIN) async def async_service_handle(service_call): """Handle for services.""" entities = await platform.async_extract_from_service(service_call) if not entities: return hass.async_add_executor_job(_call_service, entities, service_call) hass.services.async_register( DOMAIN, SERVICE_SNAPSHOT, async_service_handle, schema=cv.make_entity_service_schema({}), ) hass.services.async_register( DOMAIN, SERVICE_RESTORE, async_service_handle, schema=cv.make_entity_service_schema({}), )
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "port", "=", "config_entry", ".", "data", "[", "CONF_PORT", "]", "monoprice", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "config_entry", ".", "entry_id", "]", "[", "MONOPRICE_OBJECT", "]", "sources", "=", "_get_sources", "(", "config_entry", ")", "entities", "=", "[", "]", "for", "i", "in", "range", "(", "1", ",", "4", ")", ":", "for", "j", "in", "range", "(", "1", ",", "7", ")", ":", "zone_id", "=", "(", "i", "*", "10", ")", "+", "j", "_LOGGER", ".", "info", "(", "\"Adding zone %d for port %s\"", ",", "zone_id", ",", "port", ")", "entities", ".", "append", "(", "MonopriceZone", "(", "monoprice", ",", "sources", ",", "config_entry", ".", "entry_id", ",", "zone_id", ")", ")", "# only call update before add if it's the first run so we can try to detect zones", "first_run", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "config_entry", ".", "entry_id", "]", "[", "FIRST_RUN", "]", "async_add_entities", "(", "entities", ",", "first_run", ")", "platform", "=", "entity_platform", ".", "current_platform", ".", "get", "(", ")", "def", "_call_service", "(", "entities", ",", "service_call", ")", ":", "for", "entity", "in", "entities", ":", "if", "service_call", ".", "service", "==", "SERVICE_SNAPSHOT", ":", "entity", ".", "snapshot", "(", ")", "elif", "service_call", ".", "service", "==", "SERVICE_RESTORE", ":", "entity", ".", "restore", "(", ")", "@", "service", ".", "verify_domain_control", "(", "hass", ",", "DOMAIN", ")", "async", "def", "async_service_handle", "(", "service_call", ")", ":", "\"\"\"Handle for services.\"\"\"", "entities", "=", "await", "platform", ".", "async_extract_from_service", "(", "service_call", ")", "if", "not", "entities", ":", "return", "hass", ".", "async_add_executor_job", "(", "_call_service", ",", "entities", ",", "service_call", ")", "hass", ".", "services", ".", "async_register", "(", "DOMAIN", ",", "SERVICE_SNAPSHOT", ",", "async_service_handle", ",", "schema", "=", "cv", ".", "make_entity_service_schema", "(", "{", "}", ")", ",", ")", "hass", ".", "services", ".", "async_register", "(", "DOMAIN", ",", "SERVICE_RESTORE", ",", "async_service_handle", ",", "schema", "=", "cv", ".", "make_entity_service_schema", "(", "{", "}", ")", ",", ")" ]
[ 63, 0 ]
[ 115, 5 ]
python
en
['en', 'cs', 'en']
True
MonopriceZone.__init__
(self, monoprice, sources, namespace, zone_id)
Initialize new zone.
Initialize new zone.
def __init__(self, monoprice, sources, namespace, zone_id): """Initialize new zone.""" self._monoprice = monoprice # dict source_id -> source name self._source_id_name = sources[0] # dict source name -> source_id self._source_name_id = sources[1] # ordered list of all source names self._source_names = sources[2] self._zone_id = zone_id self._unique_id = f"{namespace}_{self._zone_id}" self._name = f"Zone {self._zone_id}" self._snapshot = None self._state = None self._volume = None self._source = None self._mute = None self._update_success = True
[ "def", "__init__", "(", "self", ",", "monoprice", ",", "sources", ",", "namespace", ",", "zone_id", ")", ":", "self", ".", "_monoprice", "=", "monoprice", "# dict source_id -> source name", "self", ".", "_source_id_name", "=", "sources", "[", "0", "]", "# dict source name -> source_id", "self", ".", "_source_name_id", "=", "sources", "[", "1", "]", "# ordered list of all source names", "self", ".", "_source_names", "=", "sources", "[", "2", "]", "self", ".", "_zone_id", "=", "zone_id", "self", ".", "_unique_id", "=", "f\"{namespace}_{self._zone_id}\"", "self", ".", "_name", "=", "f\"Zone {self._zone_id}\"", "self", ".", "_snapshot", "=", "None", "self", ".", "_state", "=", "None", "self", ".", "_volume", "=", "None", "self", ".", "_source", "=", "None", "self", ".", "_mute", "=", "None", "self", ".", "_update_success", "=", "True" ]
[ 121, 4 ]
[ 139, 35 ]
python
pl
['pl', 'pl', 'en']
True
MonopriceZone.update
(self)
Retrieve latest state.
Retrieve latest state.
def update(self): """Retrieve latest state.""" try: state = self._monoprice.zone_status(self._zone_id) except SerialException: self._update_success = False _LOGGER.warning("Could not update zone %d", self._zone_id) return if not state: self._update_success = False return self._state = STATE_ON if state.power else STATE_OFF self._volume = state.volume self._mute = state.mute idx = state.source if idx in self._source_id_name: self._source = self._source_id_name[idx] else: self._source = None
[ "def", "update", "(", "self", ")", ":", "try", ":", "state", "=", "self", ".", "_monoprice", ".", "zone_status", "(", "self", ".", "_zone_id", ")", "except", "SerialException", ":", "self", ".", "_update_success", "=", "False", "_LOGGER", ".", "warning", "(", "\"Could not update zone %d\"", ",", "self", ".", "_zone_id", ")", "return", "if", "not", "state", ":", "self", ".", "_update_success", "=", "False", "return", "self", ".", "_state", "=", "STATE_ON", "if", "state", ".", "power", "else", "STATE_OFF", "self", ".", "_volume", "=", "state", ".", "volume", "self", ".", "_mute", "=", "state", ".", "mute", "idx", "=", "state", ".", "source", "if", "idx", "in", "self", ".", "_source_id_name", ":", "self", ".", "_source", "=", "self", ".", "_source_id_name", "[", "idx", "]", "else", ":", "self", ".", "_source", "=", "None" ]
[ 141, 4 ]
[ 161, 31 ]
python
en
['es', 'sk', 'en']
False
MonopriceZone.entity_registry_enabled_default
(self)
Return if the entity should be enabled when first added to the entity registry.
Return if the entity should be enabled when first added to the entity registry.
def entity_registry_enabled_default(self): """Return if the entity should be enabled when first added to the entity registry.""" return self._zone_id < 20 or self._update_success
[ "def", "entity_registry_enabled_default", "(", "self", ")", ":", "return", "self", ".", "_zone_id", "<", "20", "or", "self", ".", "_update_success" ]
[ 164, 4 ]
[ 166, 57 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.device_info
(self)
Return device info for this device.
Return device info for this device.
def device_info(self): """Return device info for this device.""" return { "identifiers": {(DOMAIN, self.unique_id)}, "name": self.name, "manufacturer": "Monoprice", "model": "6-Zone Amplifier", }
[ "def", "device_info", "(", "self", ")", ":", "return", "{", "\"identifiers\"", ":", "{", "(", "DOMAIN", ",", "self", ".", "unique_id", ")", "}", ",", "\"name\"", ":", "self", ".", "name", ",", "\"manufacturer\"", ":", "\"Monoprice\"", ",", "\"model\"", ":", "\"6-Zone Amplifier\"", ",", "}" ]
[ 169, 4 ]
[ 176, 9 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.unique_id
(self)
Return unique ID for this device.
Return unique ID for this device.
def unique_id(self): """Return unique ID for this device.""" return self._unique_id
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_unique_id" ]
[ 179, 4 ]
[ 181, 30 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.name
(self)
Return the name of the zone.
Return the name of the zone.
def name(self): """Return the name of the zone.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 184, 4 ]
[ 186, 25 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.state
(self)
Return the state of the zone.
Return the state of the zone.
def state(self): """Return the state of the zone.""" return self._state
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "_state" ]
[ 189, 4 ]
[ 191, 26 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.volume_level
(self)
Volume level of the media player (0..1).
Volume level of the media player (0..1).
def volume_level(self): """Volume level of the media player (0..1).""" if self._volume is None: return None return self._volume / 38.0
[ "def", "volume_level", "(", "self", ")", ":", "if", "self", ".", "_volume", "is", "None", ":", "return", "None", "return", "self", ".", "_volume", "/", "38.0" ]
[ 194, 4 ]
[ 198, 34 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.is_volume_muted
(self)
Boolean if volume is currently muted.
Boolean if volume is currently muted.
def is_volume_muted(self): """Boolean if volume is currently muted.""" return self._mute
[ "def", "is_volume_muted", "(", "self", ")", ":", "return", "self", ".", "_mute" ]
[ 201, 4 ]
[ 203, 25 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.supported_features
(self)
Return flag of media commands that are supported.
Return flag of media commands that are supported.
def supported_features(self): """Return flag of media commands that are supported.""" return SUPPORT_MONOPRICE
[ "def", "supported_features", "(", "self", ")", ":", "return", "SUPPORT_MONOPRICE" ]
[ 206, 4 ]
[ 208, 32 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.media_title
(self)
Return the current source as medial title.
Return the current source as medial title.
def media_title(self): """Return the current source as medial title.""" return self._source
[ "def", "media_title", "(", "self", ")", ":", "return", "self", ".", "_source" ]
[ 211, 4 ]
[ 213, 27 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.source
(self)
Return the current input source of the device.
Return the current input source of the device.
def source(self): """Return the current input source of the device.""" return self._source
[ "def", "source", "(", "self", ")", ":", "return", "self", ".", "_source" ]
[ 216, 4 ]
[ 218, 27 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.source_list
(self)
List of available input sources.
List of available input sources.
def source_list(self): """List of available input sources.""" return self._source_names
[ "def", "source_list", "(", "self", ")", ":", "return", "self", ".", "_source_names" ]
[ 221, 4 ]
[ 223, 33 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.snapshot
(self)
Save zone's current state.
Save zone's current state.
def snapshot(self): """Save zone's current state.""" self._snapshot = self._monoprice.zone_status(self._zone_id)
[ "def", "snapshot", "(", "self", ")", ":", "self", ".", "_snapshot", "=", "self", ".", "_monoprice", ".", "zone_status", "(", "self", ".", "_zone_id", ")" ]
[ 225, 4 ]
[ 227, 67 ]
python
en
['nl', 'en', 'en']
True
MonopriceZone.restore
(self)
Restore saved state.
Restore saved state.
def restore(self): """Restore saved state.""" if self._snapshot: self._monoprice.restore_zone(self._snapshot) self.schedule_update_ha_state(True)
[ "def", "restore", "(", "self", ")", ":", "if", "self", ".", "_snapshot", ":", "self", ".", "_monoprice", ".", "restore_zone", "(", "self", ".", "_snapshot", ")", "self", ".", "schedule_update_ha_state", "(", "True", ")" ]
[ 229, 4 ]
[ 233, 47 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.select_source
(self, source)
Set input source.
Set input source.
def select_source(self, source): """Set input source.""" if source not in self._source_name_id: return idx = self._source_name_id[source] self._monoprice.set_source(self._zone_id, idx)
[ "def", "select_source", "(", "self", ",", "source", ")", ":", "if", "source", "not", "in", "self", ".", "_source_name_id", ":", "return", "idx", "=", "self", ".", "_source_name_id", "[", "source", "]", "self", ".", "_monoprice", ".", "set_source", "(", "self", ".", "_zone_id", ",", "idx", ")" ]
[ 235, 4 ]
[ 240, 54 ]
python
en
['fr', 'su', 'en']
False
MonopriceZone.turn_on
(self)
Turn the media player on.
Turn the media player on.
def turn_on(self): """Turn the media player on.""" self._monoprice.set_power(self._zone_id, True)
[ "def", "turn_on", "(", "self", ")", ":", "self", ".", "_monoprice", ".", "set_power", "(", "self", ".", "_zone_id", ",", "True", ")" ]
[ 242, 4 ]
[ 244, 54 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.turn_off
(self)
Turn the media player off.
Turn the media player off.
def turn_off(self): """Turn the media player off.""" self._monoprice.set_power(self._zone_id, False)
[ "def", "turn_off", "(", "self", ")", ":", "self", ".", "_monoprice", ".", "set_power", "(", "self", ".", "_zone_id", ",", "False", ")" ]
[ 246, 4 ]
[ 248, 55 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.mute_volume
(self, mute)
Mute (true) or unmute (false) media player.
Mute (true) or unmute (false) media player.
def mute_volume(self, mute): """Mute (true) or unmute (false) media player.""" self._monoprice.set_mute(self._zone_id, mute)
[ "def", "mute_volume", "(", "self", ",", "mute", ")", ":", "self", ".", "_monoprice", ".", "set_mute", "(", "self", ".", "_zone_id", ",", "mute", ")" ]
[ 250, 4 ]
[ 252, 53 ]
python
en
['en', 'la', 'it']
False
MonopriceZone.set_volume_level
(self, volume)
Set volume level, range 0..1.
Set volume level, range 0..1.
def set_volume_level(self, volume): """Set volume level, range 0..1.""" self._monoprice.set_volume(self._zone_id, int(volume * 38))
[ "def", "set_volume_level", "(", "self", ",", "volume", ")", ":", "self", ".", "_monoprice", ".", "set_volume", "(", "self", ".", "_zone_id", ",", "int", "(", "volume", "*", "38", ")", ")" ]
[ 254, 4 ]
[ 256, 67 ]
python
en
['fr', 'zu', 'en']
False
MonopriceZone.volume_up
(self)
Volume up the media player.
Volume up the media player.
def volume_up(self): """Volume up the media player.""" if self._volume is None: return self._monoprice.set_volume(self._zone_id, min(self._volume + 1, 38))
[ "def", "volume_up", "(", "self", ")", ":", "if", "self", ".", "_volume", "is", "None", ":", "return", "self", ".", "_monoprice", ".", "set_volume", "(", "self", ".", "_zone_id", ",", "min", "(", "self", ".", "_volume", "+", "1", ",", "38", ")", ")" ]
[ 258, 4 ]
[ 262, 76 ]
python
en
['en', 'en', 'en']
True
MonopriceZone.volume_down
(self)
Volume down media player.
Volume down media player.
def volume_down(self): """Volume down media player.""" if self._volume is None: return self._monoprice.set_volume(self._zone_id, max(self._volume - 1, 0))
[ "def", "volume_down", "(", "self", ")", ":", "if", "self", ".", "_volume", "is", "None", ":", "return", "self", ".", "_monoprice", ".", "set_volume", "(", "self", ".", "_zone_id", ",", "max", "(", "self", ".", "_volume", "-", "1", ",", "0", ")", ")" ]
[ 264, 4 ]
[ 268, 75 ]
python
en
['en', 'sl', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Discogs sensor.
Set up the Discogs sensor.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Discogs sensor.""" token = config[CONF_TOKEN] name = config[CONF_NAME] try: _discogs_client = discogs_client.Client(SERVER_SOFTWARE, user_token=token) discogs_data = { "user": _discogs_client.identity().name, "folders": _discogs_client.identity().collection_folders, "collection_count": _discogs_client.identity().num_collection, "wantlist_count": _discogs_client.identity().num_wantlist, } except discogs_client.exceptions.HTTPError: _LOGGER.error("API token is not valid") return sensors = [] for sensor_type in config[CONF_MONITORED_CONDITIONS]: sensors.append(DiscogsSensor(discogs_data, name, sensor_type)) add_entities(sensors, True)
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "token", "=", "config", "[", "CONF_TOKEN", "]", "name", "=", "config", "[", "CONF_NAME", "]", "try", ":", "_discogs_client", "=", "discogs_client", ".", "Client", "(", "SERVER_SOFTWARE", ",", "user_token", "=", "token", ")", "discogs_data", "=", "{", "\"user\"", ":", "_discogs_client", ".", "identity", "(", ")", ".", "name", ",", "\"folders\"", ":", "_discogs_client", ".", "identity", "(", ")", ".", "collection_folders", ",", "\"collection_count\"", ":", "_discogs_client", ".", "identity", "(", ")", ".", "num_collection", ",", "\"wantlist_count\"", ":", "_discogs_client", ".", "identity", "(", ")", ".", "num_wantlist", ",", "}", "except", "discogs_client", ".", "exceptions", ".", "HTTPError", ":", "_LOGGER", ".", "error", "(", "\"API token is not valid\"", ")", "return", "sensors", "=", "[", "]", "for", "sensor_type", "in", "config", "[", "CONF_MONITORED_CONDITIONS", "]", ":", "sensors", ".", "append", "(", "DiscogsSensor", "(", "discogs_data", ",", "name", ",", "sensor_type", ")", ")", "add_entities", "(", "sensors", ",", "True", ")" ]
[ 66, 0 ]
[ 88, 31 ]
python
en
['en', 'pt', 'en']
True
DiscogsSensor.__init__
(self, discogs_data, name, sensor_type)
Initialize the Discogs sensor.
Initialize the Discogs sensor.
def __init__(self, discogs_data, name, sensor_type): """Initialize the Discogs sensor.""" self._discogs_data = discogs_data self._name = name self._type = sensor_type self._state = None self._attrs = {}
[ "def", "__init__", "(", "self", ",", "discogs_data", ",", "name", ",", "sensor_type", ")", ":", "self", ".", "_discogs_data", "=", "discogs_data", "self", ".", "_name", "=", "name", "self", ".", "_type", "=", "sensor_type", "self", ".", "_state", "=", "None", "self", ".", "_attrs", "=", "{", "}" ]
[ 94, 4 ]
[ 100, 24 ]
python
en
['en', 'en', 'en']
True
DiscogsSensor.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return f"{self._name} {SENSORS[self._type]['name']}"
[ "def", "name", "(", "self", ")", ":", "return", "f\"{self._name} {SENSORS[self._type]['name']}\"" ]
[ 103, 4 ]
[ 105, 60 ]
python
en
['en', 'mi', 'en']
True
DiscogsSensor.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" ]
[ 108, 4 ]
[ 110, 26 ]
python
en
['en', 'en', 'en']
True
DiscogsSensor.icon
(self)
Return the icon to use in the frontend, if any.
Return the icon to use in the frontend, if any.
def icon(self): """Return the icon to use in the frontend, if any.""" return SENSORS[self._type]["icon"]
[ "def", "icon", "(", "self", ")", ":", "return", "SENSORS", "[", "self", ".", "_type", "]", "[", "\"icon\"", "]" ]
[ 113, 4 ]
[ 115, 42 ]
python
en
['en', 'en', 'en']
True
DiscogsSensor.unit_of_measurement
(self)
Return the unit this state is expressed in.
Return the unit this state is expressed in.
def unit_of_measurement(self): """Return the unit this state is expressed in.""" return SENSORS[self._type]["unit_of_measurement"]
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "SENSORS", "[", "self", ".", "_type", "]", "[", "\"unit_of_measurement\"", "]" ]
[ 118, 4 ]
[ 120, 57 ]
python
en
['en', 'en', 'en']
True
DiscogsSensor.device_state_attributes
(self)
Return the device state attributes of the sensor.
Return the device state attributes of the sensor.
def device_state_attributes(self): """Return the device state attributes of the sensor.""" if self._state is None or self._attrs is None: return None if self._type == SENSOR_RANDOM_RECORD_TYPE and self._state is not None: return { "cat_no": self._attrs["labels"][0]["catno"], "cover_image": self._attrs["cover_image"], "format": f"{self._attrs['formats'][0]['name']} ({self._attrs['formats'][0]['descriptions'][0]})", "label": self._attrs["labels"][0]["name"], "released": self._attrs["year"], ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_IDENTITY: self._discogs_data["user"], } return { ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_IDENTITY: self._discogs_data["user"], }
[ "def", "device_state_attributes", "(", "self", ")", ":", "if", "self", ".", "_state", "is", "None", "or", "self", ".", "_attrs", "is", "None", ":", "return", "None", "if", "self", ".", "_type", "==", "SENSOR_RANDOM_RECORD_TYPE", "and", "self", ".", "_state", "is", "not", "None", ":", "return", "{", "\"cat_no\"", ":", "self", ".", "_attrs", "[", "\"labels\"", "]", "[", "0", "]", "[", "\"catno\"", "]", ",", "\"cover_image\"", ":", "self", ".", "_attrs", "[", "\"cover_image\"", "]", ",", "\"format\"", ":", "f\"{self._attrs['formats'][0]['name']} ({self._attrs['formats'][0]['descriptions'][0]})\"", ",", "\"label\"", ":", "self", ".", "_attrs", "[", "\"labels\"", "]", "[", "0", "]", "[", "\"name\"", "]", ",", "\"released\"", ":", "self", ".", "_attrs", "[", "\"year\"", "]", ",", "ATTR_ATTRIBUTION", ":", "ATTRIBUTION", ",", "ATTR_IDENTITY", ":", "self", ".", "_discogs_data", "[", "\"user\"", "]", ",", "}", "return", "{", "ATTR_ATTRIBUTION", ":", "ATTRIBUTION", ",", "ATTR_IDENTITY", ":", "self", ".", "_discogs_data", "[", "\"user\"", "]", ",", "}" ]
[ 123, 4 ]
[ 142, 9 ]
python
en
['en', 'en', 'en']
True
DiscogsSensor.get_random_record
(self)
Get a random record suggestion from the user's collection.
Get a random record suggestion from the user's collection.
def get_random_record(self): """Get a random record suggestion from the user's collection.""" # Index 0 in the folders is the 'All' folder collection = self._discogs_data["folders"][0] if collection.count > 0: random_index = random.randrange(collection.count) random_record = collection.releases[random_index].release self._attrs = random_record.data return f"{random_record.data['artists'][0]['name']} - {random_record.data['title']}" return None
[ "def", "get_random_record", "(", "self", ")", ":", "# Index 0 in the folders is the 'All' folder", "collection", "=", "self", ".", "_discogs_data", "[", "\"folders\"", "]", "[", "0", "]", "if", "collection", ".", "count", ">", "0", ":", "random_index", "=", "random", ".", "randrange", "(", "collection", ".", "count", ")", "random_record", "=", "collection", ".", "releases", "[", "random_index", "]", ".", "release", "self", ".", "_attrs", "=", "random_record", ".", "data", "return", "f\"{random_record.data['artists'][0]['name']} - {random_record.data['title']}\"", "return", "None" ]
[ 144, 4 ]
[ 155, 19 ]
python
en
['en', 'en', 'en']
True
DiscogsSensor.update
(self)
Set state to the amount of records in user's collection.
Set state to the amount of records in user's collection.
def update(self): """Set state to the amount of records in user's collection.""" if self._type == SENSOR_COLLECTION_TYPE: self._state = self._discogs_data["collection_count"] elif self._type == SENSOR_WANTLIST_TYPE: self._state = self._discogs_data["wantlist_count"] else: self._state = self.get_random_record()
[ "def", "update", "(", "self", ")", ":", "if", "self", ".", "_type", "==", "SENSOR_COLLECTION_TYPE", ":", "self", ".", "_state", "=", "self", ".", "_discogs_data", "[", "\"collection_count\"", "]", "elif", "self", ".", "_type", "==", "SENSOR_WANTLIST_TYPE", ":", "self", ".", "_state", "=", "self", ".", "_discogs_data", "[", "\"wantlist_count\"", "]", "else", ":", "self", ".", "_state", "=", "self", ".", "get_random_record", "(", ")" ]
[ 157, 4 ]
[ 164, 50 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, entry, async_add_entities)
Set up Neato camera with config entry.
Set up Neato camera with config entry.
async def async_setup_entry(hass, entry, async_add_entities): """Set up Neato camera with config entry.""" dev = [] neato = hass.data.get(NEATO_LOGIN) mapdata = hass.data.get(NEATO_MAP_DATA) for robot in hass.data[NEATO_ROBOTS]: if "maps" in robot.traits: dev.append(NeatoCleaningMap(neato, robot, mapdata)) if not dev: return _LOGGER.debug("Adding robots for cleaning maps %s", dev) async_add_entities(dev, True)
[ "async", "def", "async_setup_entry", "(", "hass", ",", "entry", ",", "async_add_entities", ")", ":", "dev", "=", "[", "]", "neato", "=", "hass", ".", "data", ".", "get", "(", "NEATO_LOGIN", ")", "mapdata", "=", "hass", ".", "data", ".", "get", "(", "NEATO_MAP_DATA", ")", "for", "robot", "in", "hass", ".", "data", "[", "NEATO_ROBOTS", "]", ":", "if", "\"maps\"", "in", "robot", ".", "traits", ":", "dev", ".", "append", "(", "NeatoCleaningMap", "(", "neato", ",", "robot", ",", "mapdata", ")", ")", "if", "not", "dev", ":", "return", "_LOGGER", ".", "debug", "(", "\"Adding robots for cleaning maps %s\"", ",", "dev", ")", "async_add_entities", "(", "dev", ",", "True", ")" ]
[ 22, 0 ]
[ 35, 33 ]
python
en
['en', 'en', 'en']
True
NeatoCleaningMap.__init__
(self, neato, robot, mapdata)
Initialize Neato cleaning map.
Initialize Neato cleaning map.
def __init__(self, neato, robot, mapdata): """Initialize Neato cleaning map.""" super().__init__() self.robot = robot self.neato = neato self._mapdata = mapdata self._available = self.neato.logged_in if self.neato is not None else False self._robot_name = f"{self.robot.name} Cleaning Map" self._robot_serial = self.robot.serial self._generated_at = None self._image_url = None self._image = None
[ "def", "__init__", "(", "self", ",", "neato", ",", "robot", ",", "mapdata", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "robot", "=", "robot", "self", ".", "neato", "=", "neato", "self", ".", "_mapdata", "=", "mapdata", "self", ".", "_available", "=", "self", ".", "neato", ".", "logged_in", "if", "self", ".", "neato", "is", "not", "None", "else", "False", "self", ".", "_robot_name", "=", "f\"{self.robot.name} Cleaning Map\"", "self", ".", "_robot_serial", "=", "self", ".", "robot", ".", "serial", "self", ".", "_generated_at", "=", "None", "self", ".", "_image_url", "=", "None", "self", ".", "_image", "=", "None" ]
[ 41, 4 ]
[ 52, 26 ]
python
en
['it', 'en', 'en']
True
NeatoCleaningMap.camera_image
(self)
Return image response.
Return image response.
def camera_image(self): """Return image response.""" self.update() return self._image
[ "def", "camera_image", "(", "self", ")", ":", "self", ".", "update", "(", ")", "return", "self", ".", "_image" ]
[ 54, 4 ]
[ 57, 26 ]
python
en
['en', 'jv', 'en']
True
NeatoCleaningMap.update
(self)
Check the contents of the map list.
Check the contents of the map list.
def update(self): """Check the contents of the map list.""" if self.neato is None: _LOGGER.error("Error while updating '%s'", self.entity_id) self._image = None self._image_url = None self._available = False return _LOGGER.debug("Running camera update for '%s'", self.entity_id) try: self.neato.update_robots() except NeatoRobotException as ex: if self._available: # Print only once when available _LOGGER.error( "Neato camera connection error for '%s': %s", self.entity_id, ex ) self._image = None self._image_url = None self._available = False return image_url = None map_data = self._mapdata[self._robot_serial]["maps"][0] image_url = map_data["url"] if image_url == self._image_url: _LOGGER.debug( "The map image_url for '%s' is the same as old", self.entity_id ) return try: image = self.neato.download_map(image_url) except NeatoRobotException as ex: if self._available: # Print only once when available _LOGGER.error( "Neato camera connection error for '%s': %s", self.entity_id, ex ) self._image = None self._image_url = None self._available = False return self._image = image.read() self._image_url = image_url self._generated_at = (map_data["generated_at"].strip("Z")).replace("T", " ") self._available = True
[ "def", "update", "(", "self", ")", ":", "if", "self", ".", "neato", "is", "None", ":", "_LOGGER", ".", "error", "(", "\"Error while updating '%s'\"", ",", "self", ".", "entity_id", ")", "self", ".", "_image", "=", "None", "self", ".", "_image_url", "=", "None", "self", ".", "_available", "=", "False", "return", "_LOGGER", ".", "debug", "(", "\"Running camera update for '%s'\"", ",", "self", ".", "entity_id", ")", "try", ":", "self", ".", "neato", ".", "update_robots", "(", ")", "except", "NeatoRobotException", "as", "ex", ":", "if", "self", ".", "_available", ":", "# Print only once when available", "_LOGGER", ".", "error", "(", "\"Neato camera connection error for '%s': %s\"", ",", "self", ".", "entity_id", ",", "ex", ")", "self", ".", "_image", "=", "None", "self", ".", "_image_url", "=", "None", "self", ".", "_available", "=", "False", "return", "image_url", "=", "None", "map_data", "=", "self", ".", "_mapdata", "[", "self", ".", "_robot_serial", "]", "[", "\"maps\"", "]", "[", "0", "]", "image_url", "=", "map_data", "[", "\"url\"", "]", "if", "image_url", "==", "self", ".", "_image_url", ":", "_LOGGER", ".", "debug", "(", "\"The map image_url for '%s' is the same as old\"", ",", "self", ".", "entity_id", ")", "return", "try", ":", "image", "=", "self", ".", "neato", ".", "download_map", "(", "image_url", ")", "except", "NeatoRobotException", "as", "ex", ":", "if", "self", ".", "_available", ":", "# Print only once when available", "_LOGGER", ".", "error", "(", "\"Neato camera connection error for '%s': %s\"", ",", "self", ".", "entity_id", ",", "ex", ")", "self", ".", "_image", "=", "None", "self", ".", "_image_url", "=", "None", "self", ".", "_available", "=", "False", "return", "self", ".", "_image", "=", "image", ".", "read", "(", ")", "self", ".", "_image_url", "=", "image_url", "self", ".", "_generated_at", "=", "(", "map_data", "[", "\"generated_at\"", "]", ".", "strip", "(", "\"Z\"", ")", ")", ".", "replace", "(", "\"T\"", ",", "\" \"", ")", "self", ".", "_available", "=", "True" ]
[ 59, 4 ]
[ 105, 30 ]
python
en
['en', 'en', 'en']
True
NeatoCleaningMap.name
(self)
Return the name of this camera.
Return the name of this camera.
def name(self): """Return the name of this camera.""" return self._robot_name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_robot_name" ]
[ 108, 4 ]
[ 110, 31 ]
python
en
['en', 'en', 'en']
True
NeatoCleaningMap.unique_id
(self)
Return unique ID.
Return unique ID.
def unique_id(self): """Return unique ID.""" return self._robot_serial
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_robot_serial" ]
[ 113, 4 ]
[ 115, 33 ]
python
en
['fr', 'la', 'en']
False
NeatoCleaningMap.available
(self)
Return if the robot is available.
Return if the robot is available.
def available(self): """Return if the robot is available.""" return self._available
[ "def", "available", "(", "self", ")", ":", "return", "self", ".", "_available" ]
[ 118, 4 ]
[ 120, 30 ]
python
en
['en', 'en', 'en']
True
NeatoCleaningMap.device_info
(self)
Device info for neato robot.
Device info for neato robot.
def device_info(self): """Device info for neato robot.""" return {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}}
[ "def", "device_info", "(", "self", ")", ":", "return", "{", "\"identifiers\"", ":", "{", "(", "NEATO_DOMAIN", ",", "self", ".", "_robot_serial", ")", "}", "}" ]
[ 123, 4 ]
[ 125, 68 ]
python
it
['it', 'en', 'it']
True
NeatoCleaningMap.device_state_attributes
(self)
Return the state attributes of the vacuum cleaner.
Return the state attributes of the vacuum cleaner.
def device_state_attributes(self): """Return the state attributes of the vacuum cleaner.""" data = {} if self._generated_at is not None: data[ATTR_GENERATED_AT] = self._generated_at return data
[ "def", "device_state_attributes", "(", "self", ")", ":", "data", "=", "{", "}", "if", "self", ".", "_generated_at", "is", "not", "None", ":", "data", "[", "ATTR_GENERATED_AT", "]", "=", "self", ".", "_generated_at", "return", "data" ]
[ 128, 4 ]
[ 135, 19 ]
python
en
['en', 'en', 'en']
True
test_controlling_state_via_topic
(hass, mqtt_mock)
Test the controlling state via topic.
Test the controlling state via topic.
async def test_controlling_state_via_topic(hass, mqtt_mock): """Test the controlling state via topic.""" assert await async_setup_component( hass, switch.DOMAIN, { switch.DOMAIN: { "platform": "mqtt", "name": "test", "state_topic": "state-topic", "command_topic": "command-topic", "payload_on": 1, "payload_off": 0, } }, ) await hass.async_block_till_done() state = hass.states.get("switch.test") assert state.state == STATE_OFF assert not state.attributes.get(ATTR_ASSUMED_STATE) async_fire_mqtt_message(hass, "state-topic", "1") state = hass.states.get("switch.test") assert state.state == STATE_ON async_fire_mqtt_message(hass, "state-topic", "0") state = hass.states.get("switch.test") assert state.state == STATE_OFF
[ "async", "def", "test_controlling_state_via_topic", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "switch", ".", "DOMAIN", ",", "{", "switch", ".", "DOMAIN", ":", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"test\"", ",", "\"state_topic\"", ":", "\"state-topic\"", ",", "\"command_topic\"", ":", "\"command-topic\"", ",", "\"payload_on\"", ":", "1", ",", "\"payload_off\"", ":", "0", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_OFF", "assert", "not", "state", ".", "attributes", ".", "get", "(", "ATTR_ASSUMED_STATE", ")", "async_fire_mqtt_message", "(", "hass", ",", "\"state-topic\"", ",", "\"1\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_ON", "async_fire_mqtt_message", "(", "hass", ",", "\"state-topic\"", ",", "\"0\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_OFF" ]
[ 44, 0 ]
[ 74, 35 ]
python
en
['en', 'en', 'en']
True
test_sending_mqtt_commands_and_optimistic
(hass, mqtt_mock)
Test the sending MQTT commands in optimistic mode.
Test the sending MQTT commands in optimistic mode.
async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock): """Test the sending MQTT commands in optimistic mode.""" fake_state = ha.State("switch.test", "on") with patch( "homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state", return_value=fake_state, ): assert await async_setup_component( hass, switch.DOMAIN, { switch.DOMAIN: { "platform": "mqtt", "name": "test", "command_topic": "command-topic", "payload_on": "beer on", "payload_off": "beer off", "qos": "2", } }, ) await hass.async_block_till_done() state = hass.states.get("switch.test") assert state.state == STATE_ON assert state.attributes.get(ATTR_ASSUMED_STATE) await common.async_turn_on(hass, "switch.test") mqtt_mock.async_publish.assert_called_once_with( "command-topic", "beer on", 2, False ) mqtt_mock.async_publish.reset_mock() state = hass.states.get("switch.test") assert state.state == STATE_ON await common.async_turn_off(hass, "switch.test") mqtt_mock.async_publish.assert_called_once_with( "command-topic", "beer off", 2, False ) state = hass.states.get("switch.test") assert state.state == STATE_OFF
[ "async", "def", "test_sending_mqtt_commands_and_optimistic", "(", "hass", ",", "mqtt_mock", ")", ":", "fake_state", "=", "ha", ".", "State", "(", "\"switch.test\"", ",", "\"on\"", ")", "with", "patch", "(", "\"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state\"", ",", "return_value", "=", "fake_state", ",", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "switch", ".", "DOMAIN", ",", "{", "switch", ".", "DOMAIN", ":", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"test\"", ",", "\"command_topic\"", ":", "\"command-topic\"", ",", "\"payload_on\"", ":", "\"beer on\"", ",", "\"payload_off\"", ":", "\"beer off\"", ",", "\"qos\"", ":", "\"2\"", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_ON", "assert", "state", ".", "attributes", ".", "get", "(", "ATTR_ASSUMED_STATE", ")", "await", "common", ".", "async_turn_on", "(", "hass", ",", "\"switch.test\"", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"command-topic\"", ",", "\"beer on\"", ",", "2", ",", "False", ")", "mqtt_mock", ".", "async_publish", ".", "reset_mock", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_ON", "await", "common", ".", "async_turn_off", "(", "hass", ",", "\"switch.test\"", ")", "mqtt_mock", ".", "async_publish", ".", "assert_called_once_with", "(", "\"command-topic\"", ",", "\"beer off\"", ",", "2", ",", "False", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_OFF" ]
[ 77, 0 ]
[ 120, 35 ]
python
en
['en', 'no', 'en']
True
test_controlling_state_via_topic_and_json_message
(hass, mqtt_mock)
Test the controlling state via topic and JSON message.
Test the controlling state via topic and JSON message.
async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock): """Test the controlling state via topic and JSON message.""" assert await async_setup_component( hass, switch.DOMAIN, { switch.DOMAIN: { "platform": "mqtt", "name": "test", "state_topic": "state-topic", "command_topic": "command-topic", "payload_on": "beer on", "payload_off": "beer off", "value_template": "{{ value_json.val }}", } }, ) await hass.async_block_till_done() state = hass.states.get("switch.test") assert state.state == STATE_OFF async_fire_mqtt_message(hass, "state-topic", '{"val":"beer on"}') state = hass.states.get("switch.test") assert state.state == STATE_ON async_fire_mqtt_message(hass, "state-topic", '{"val":"beer off"}') state = hass.states.get("switch.test") assert state.state == STATE_OFF
[ "async", "def", "test_controlling_state_via_topic_and_json_message", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "switch", ".", "DOMAIN", ",", "{", "switch", ".", "DOMAIN", ":", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"test\"", ",", "\"state_topic\"", ":", "\"state-topic\"", ",", "\"command_topic\"", ":", "\"command-topic\"", ",", "\"payload_on\"", ":", "\"beer on\"", ",", "\"payload_off\"", ":", "\"beer off\"", ",", "\"value_template\"", ":", "\"{{ value_json.val }}\"", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_OFF", "async_fire_mqtt_message", "(", "hass", ",", "\"state-topic\"", ",", "'{\"val\":\"beer on\"}'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_ON", "async_fire_mqtt_message", "(", "hass", ",", "\"state-topic\"", ",", "'{\"val\":\"beer off\"}'", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_OFF" ]
[ 123, 0 ]
[ 153, 35 ]
python
en
['en', 'en', 'en']
True
test_availability_when_connection_lost
(hass, mqtt_mock)
Test availability after MQTT disconnection.
Test availability after MQTT disconnection.
async def test_availability_when_connection_lost(hass, mqtt_mock): """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_availability_when_connection_lost", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_availability_when_connection_lost", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 156, 0 ]
[ 160, 5 ]
python
en
['en', 'en', 'en']
True
test_availability_without_topic
(hass, mqtt_mock)
Test availability without defined availability topic.
Test availability without defined availability topic.
async def test_availability_without_topic(hass, mqtt_mock): """Test availability without defined availability topic.""" await help_test_availability_without_topic( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_availability_without_topic", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_availability_without_topic", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 163, 0 ]
[ 167, 5 ]
python
en
['en', 'en', 'en']
True
test_default_availability_payload
(hass, mqtt_mock)
Test availability by default payload with defined topic.
Test availability by default payload with defined topic.
async def test_default_availability_payload(hass, mqtt_mock): """Test availability by default payload with defined topic.""" config = { switch.DOMAIN: { "platform": "mqtt", "name": "test", "state_topic": "state-topic", "command_topic": "command-topic", "payload_on": 1, "payload_off": 0, } } await help_test_default_availability_payload( hass, mqtt_mock, switch.DOMAIN, config, True, "state-topic", "1" )
[ "async", "def", "test_default_availability_payload", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "{", "switch", ".", "DOMAIN", ":", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"test\"", ",", "\"state_topic\"", ":", "\"state-topic\"", ",", "\"command_topic\"", ":", "\"command-topic\"", ",", "\"payload_on\"", ":", "1", ",", "\"payload_off\"", ":", "0", ",", "}", "}", "await", "help_test_default_availability_payload", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "config", ",", "True", ",", "\"state-topic\"", ",", "\"1\"", ")" ]
[ 170, 0 ]
[ 185, 5 ]
python
en
['en', 'en', 'en']
True
test_custom_availability_payload
(hass, mqtt_mock)
Test availability by custom payload with defined topic.
Test availability by custom payload with defined topic.
async def test_custom_availability_payload(hass, mqtt_mock): """Test availability by custom payload with defined topic.""" config = { switch.DOMAIN: { "platform": "mqtt", "name": "test", "state_topic": "state-topic", "command_topic": "command-topic", "payload_on": 1, "payload_off": 0, } } await help_test_custom_availability_payload( hass, mqtt_mock, switch.DOMAIN, config, True, "state-topic", "1" )
[ "async", "def", "test_custom_availability_payload", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "{", "switch", ".", "DOMAIN", ":", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"test\"", ",", "\"state_topic\"", ":", "\"state-topic\"", ",", "\"command_topic\"", ":", "\"command-topic\"", ",", "\"payload_on\"", ":", "1", ",", "\"payload_off\"", ":", "0", ",", "}", "}", "await", "help_test_custom_availability_payload", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "config", ",", "True", ",", "\"state-topic\"", ",", "\"1\"", ")" ]
[ 188, 0 ]
[ 203, 5 ]
python
en
['en', 'en', 'en']
True
test_custom_state_payload
(hass, mqtt_mock)
Test the state payload.
Test the state payload.
async def test_custom_state_payload(hass, mqtt_mock): """Test the state payload.""" assert await async_setup_component( hass, switch.DOMAIN, { switch.DOMAIN: { "platform": "mqtt", "name": "test", "state_topic": "state-topic", "command_topic": "command-topic", "payload_on": 1, "payload_off": 0, "state_on": "HIGH", "state_off": "LOW", } }, ) await hass.async_block_till_done() state = hass.states.get("switch.test") assert state.state == STATE_OFF assert not state.attributes.get(ATTR_ASSUMED_STATE) async_fire_mqtt_message(hass, "state-topic", "HIGH") state = hass.states.get("switch.test") assert state.state == STATE_ON async_fire_mqtt_message(hass, "state-topic", "LOW") state = hass.states.get("switch.test") assert state.state == STATE_OFF
[ "async", "def", "test_custom_state_payload", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "switch", ".", "DOMAIN", ",", "{", "switch", ".", "DOMAIN", ":", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"test\"", ",", "\"state_topic\"", ":", "\"state-topic\"", ",", "\"command_topic\"", ":", "\"command-topic\"", ",", "\"payload_on\"", ":", "1", ",", "\"payload_off\"", ":", "0", ",", "\"state_on\"", ":", "\"HIGH\"", ",", "\"state_off\"", ":", "\"LOW\"", ",", "}", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_OFF", "assert", "not", "state", ".", "attributes", ".", "get", "(", "ATTR_ASSUMED_STATE", ")", "async_fire_mqtt_message", "(", "hass", ",", "\"state-topic\"", ",", "\"HIGH\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_ON", "async_fire_mqtt_message", "(", "hass", ",", "\"state-topic\"", ",", "\"LOW\"", ")", "state", "=", "hass", ".", "states", ".", "get", "(", "\"switch.test\"", ")", "assert", "state", ".", "state", "==", "STATE_OFF" ]
[ 206, 0 ]
[ 238, 35 ]
python
en
['en', 'en', 'en']
True
test_setting_attribute_via_mqtt_json_message
(hass, mqtt_mock)
Test the setting of attribute via MQTT with JSON payload.
Test the setting of attribute via MQTT with JSON payload.
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock): """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_setting_attribute_via_mqtt_json_message", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_setting_attribute_via_mqtt_json_message", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 241, 0 ]
[ 245, 5 ]
python
en
['en', 'en', 'en']
True
test_setting_attribute_with_template
(hass, mqtt_mock)
Test the setting of attribute via MQTT with JSON payload.
Test the setting of attribute via MQTT with JSON payload.
async def test_setting_attribute_with_template(hass, mqtt_mock): """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_setting_attribute_with_template", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_setting_attribute_with_template", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 248, 0 ]
[ 252, 5 ]
python
en
['en', 'en', 'en']
True
test_update_with_json_attrs_not_dict
(hass, mqtt_mock, caplog)
Test attributes get extracted from a JSON result.
Test attributes get extracted from a JSON result.
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog): """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, mqtt_mock, caplog, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_update_with_json_attrs_not_dict", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "await", "help_test_update_with_json_attrs_not_dict", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 255, 0 ]
[ 259, 5 ]
python
en
['en', 'en', 'en']
True
test_update_with_json_attrs_bad_JSON
(hass, mqtt_mock, caplog)
Test attributes get extracted from a JSON result.
Test attributes get extracted from a JSON result.
async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog): """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_JSON( hass, mqtt_mock, caplog, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_update_with_json_attrs_bad_JSON", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "await", "help_test_update_with_json_attrs_bad_JSON", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 262, 0 ]
[ 266, 5 ]
python
en
['en', 'en', 'en']
True
test_discovery_update_attr
(hass, mqtt_mock, caplog)
Test update of discovered MQTTAttributes.
Test update of discovered MQTTAttributes.
async def test_discovery_update_attr(hass, mqtt_mock, caplog): """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, mqtt_mock, caplog, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_discovery_update_attr", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "await", "help_test_discovery_update_attr", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 269, 0 ]
[ 273, 5 ]
python
en
['en', 'en', 'en']
True
test_unique_id
(hass, mqtt_mock)
Test unique id option only creates one switch per unique_id.
Test unique id option only creates one switch per unique_id.
async def test_unique_id(hass, mqtt_mock): """Test unique id option only creates one switch per unique_id.""" config = { switch.DOMAIN: [ { "platform": "mqtt", "name": "Test 1", "state_topic": "test-topic", "command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE", }, { "platform": "mqtt", "name": "Test 2", "state_topic": "test-topic", "command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE", }, ] } await help_test_unique_id(hass, mqtt_mock, switch.DOMAIN, config)
[ "async", "def", "test_unique_id", "(", "hass", ",", "mqtt_mock", ")", ":", "config", "=", "{", "switch", ".", "DOMAIN", ":", "[", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"Test 1\"", ",", "\"state_topic\"", ":", "\"test-topic\"", ",", "\"command_topic\"", ":", "\"command-topic\"", ",", "\"unique_id\"", ":", "\"TOTALLY_UNIQUE\"", ",", "}", ",", "{", "\"platform\"", ":", "\"mqtt\"", ",", "\"name\"", ":", "\"Test 2\"", ",", "\"state_topic\"", ":", "\"test-topic\"", ",", "\"command_topic\"", ":", "\"command-topic\"", ",", "\"unique_id\"", ":", "\"TOTALLY_UNIQUE\"", ",", "}", ",", "]", "}", "await", "help_test_unique_id", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "config", ")" ]
[ 276, 0 ]
[ 296, 69 ]
python
en
['en', 'en', 'en']
True
test_discovery_removal_switch
(hass, mqtt_mock, caplog)
Test removal of discovered switch.
Test removal of discovered switch.
async def test_discovery_removal_switch(hass, mqtt_mock, caplog): """Test removal of discovered switch.""" data = ( '{ "name": "test",' ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) await help_test_discovery_removal(hass, mqtt_mock, caplog, switch.DOMAIN, data)
[ "async", "def", "test_discovery_removal_switch", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "data", "=", "(", "'{ \"name\": \"test\",'", "' \"state_topic\": \"test_topic\",'", "' \"command_topic\": \"test_topic\" }'", ")", "await", "help_test_discovery_removal", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "switch", ".", "DOMAIN", ",", "data", ")" ]
[ 299, 0 ]
[ 306, 83 ]
python
en
['en', 'en', 'en']
True
test_discovery_update_switch_topic_template
(hass, mqtt_mock, caplog)
Test update of discovered switch.
Test update of discovered switch.
async def test_discovery_update_switch_topic_template(hass, mqtt_mock, caplog): """Test update of discovered switch.""" config1 = copy.deepcopy(DEFAULT_CONFIG[switch.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[switch.DOMAIN]) config1["name"] = "Beer" config2["name"] = "Milk" config1["state_topic"] = "switch/state1" config2["state_topic"] = "switch/state2" config1["value_template"] = "{{ value_json.state1.state }}" config2["value_template"] = "{{ value_json.state2.state }}" state_data1 = [ ([("switch/state1", '{"state1":{"state":"ON"}}')], "on", None), ] state_data2 = [ ([("switch/state2", '{"state2":{"state":"OFF"}}')], "off", None), ([("switch/state2", '{"state2":{"state":"ON"}}')], "on", None), ([("switch/state1", '{"state1":{"state":"OFF"}}')], "on", None), ([("switch/state1", '{"state2":{"state":"OFF"}}')], "on", None), ([("switch/state2", '{"state1":{"state":"OFF"}}')], "on", None), ([("switch/state2", '{"state2":{"state":"OFF"}}')], "off", None), ] data1 = json.dumps(config1) data2 = json.dumps(config2) await help_test_discovery_update( hass, mqtt_mock, caplog, switch.DOMAIN, data1, data2, state_data1=state_data1, state_data2=state_data2, )
[ "async", "def", "test_discovery_update_switch_topic_template", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "config1", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", "[", "switch", ".", "DOMAIN", "]", ")", "config2", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", "[", "switch", ".", "DOMAIN", "]", ")", "config1", "[", "\"name\"", "]", "=", "\"Beer\"", "config2", "[", "\"name\"", "]", "=", "\"Milk\"", "config1", "[", "\"state_topic\"", "]", "=", "\"switch/state1\"", "config2", "[", "\"state_topic\"", "]", "=", "\"switch/state2\"", "config1", "[", "\"value_template\"", "]", "=", "\"{{ value_json.state1.state }}\"", "config2", "[", "\"value_template\"", "]", "=", "\"{{ value_json.state2.state }}\"", "state_data1", "=", "[", "(", "[", "(", "\"switch/state1\"", ",", "'{\"state1\":{\"state\":\"ON\"}}'", ")", "]", ",", "\"on\"", ",", "None", ")", ",", "]", "state_data2", "=", "[", "(", "[", "(", "\"switch/state2\"", ",", "'{\"state2\":{\"state\":\"OFF\"}}'", ")", "]", ",", "\"off\"", ",", "None", ")", ",", "(", "[", "(", "\"switch/state2\"", ",", "'{\"state2\":{\"state\":\"ON\"}}'", ")", "]", ",", "\"on\"", ",", "None", ")", ",", "(", "[", "(", "\"switch/state1\"", ",", "'{\"state1\":{\"state\":\"OFF\"}}'", ")", "]", ",", "\"on\"", ",", "None", ")", ",", "(", "[", "(", "\"switch/state1\"", ",", "'{\"state2\":{\"state\":\"OFF\"}}'", ")", "]", ",", "\"on\"", ",", "None", ")", ",", "(", "[", "(", "\"switch/state2\"", ",", "'{\"state1\":{\"state\":\"OFF\"}}'", ")", "]", ",", "\"on\"", ",", "None", ")", ",", "(", "[", "(", "\"switch/state2\"", ",", "'{\"state2\":{\"state\":\"OFF\"}}'", ")", "]", ",", "\"off\"", ",", "None", ")", ",", "]", "data1", "=", "json", ".", "dumps", "(", "config1", ")", "data2", "=", "json", ".", "dumps", "(", "config2", ")", "await", "help_test_discovery_update", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "switch", ".", "DOMAIN", ",", "data1", ",", "data2", ",", "state_data1", "=", "state_data1", ",", "state_data2", "=", "state_data2", ",", ")" ]
[ 309, 0 ]
[ 343, 5 ]
python
en
['en', 'en', 'en']
True
test_discovery_update_switch_template
(hass, mqtt_mock, caplog)
Test update of discovered switch.
Test update of discovered switch.
async def test_discovery_update_switch_template(hass, mqtt_mock, caplog): """Test update of discovered switch.""" config1 = copy.deepcopy(DEFAULT_CONFIG[switch.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[switch.DOMAIN]) config1["name"] = "Beer" config2["name"] = "Milk" config1["state_topic"] = "switch/state1" config2["state_topic"] = "switch/state1" config1["value_template"] = "{{ value_json.state1.state }}" config2["value_template"] = "{{ value_json.state2.state }}" state_data1 = [ ([("switch/state1", '{"state1":{"state":"ON"}}')], "on", None), ] state_data2 = [ ([("switch/state1", '{"state2":{"state":"OFF"}}')], "off", None), ([("switch/state1", '{"state2":{"state":"ON"}}')], "on", None), ([("switch/state1", '{"state1":{"state":"OFF"}}')], "on", None), ([("switch/state1", '{"state2":{"state":"OFF"}}')], "off", None), ] data1 = json.dumps(config1) data2 = json.dumps(config2) await help_test_discovery_update( hass, mqtt_mock, caplog, switch.DOMAIN, data1, data2, state_data1=state_data1, state_data2=state_data2, )
[ "async", "def", "test_discovery_update_switch_template", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "config1", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", "[", "switch", ".", "DOMAIN", "]", ")", "config2", "=", "copy", ".", "deepcopy", "(", "DEFAULT_CONFIG", "[", "switch", ".", "DOMAIN", "]", ")", "config1", "[", "\"name\"", "]", "=", "\"Beer\"", "config2", "[", "\"name\"", "]", "=", "\"Milk\"", "config1", "[", "\"state_topic\"", "]", "=", "\"switch/state1\"", "config2", "[", "\"state_topic\"", "]", "=", "\"switch/state1\"", "config1", "[", "\"value_template\"", "]", "=", "\"{{ value_json.state1.state }}\"", "config2", "[", "\"value_template\"", "]", "=", "\"{{ value_json.state2.state }}\"", "state_data1", "=", "[", "(", "[", "(", "\"switch/state1\"", ",", "'{\"state1\":{\"state\":\"ON\"}}'", ")", "]", ",", "\"on\"", ",", "None", ")", ",", "]", "state_data2", "=", "[", "(", "[", "(", "\"switch/state1\"", ",", "'{\"state2\":{\"state\":\"OFF\"}}'", ")", "]", ",", "\"off\"", ",", "None", ")", ",", "(", "[", "(", "\"switch/state1\"", ",", "'{\"state2\":{\"state\":\"ON\"}}'", ")", "]", ",", "\"on\"", ",", "None", ")", ",", "(", "[", "(", "\"switch/state1\"", ",", "'{\"state1\":{\"state\":\"OFF\"}}'", ")", "]", ",", "\"on\"", ",", "None", ")", ",", "(", "[", "(", "\"switch/state1\"", ",", "'{\"state2\":{\"state\":\"OFF\"}}'", ")", "]", ",", "\"off\"", ",", "None", ")", ",", "]", "data1", "=", "json", ".", "dumps", "(", "config1", ")", "data2", "=", "json", ".", "dumps", "(", "config2", ")", "await", "help_test_discovery_update", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "switch", ".", "DOMAIN", ",", "data1", ",", "data2", ",", "state_data1", "=", "state_data1", ",", "state_data2", "=", "state_data2", ",", ")" ]
[ 346, 0 ]
[ 378, 5 ]
python
en
['en', 'en', 'en']
True
test_discovery_update_unchanged_switch
(hass, mqtt_mock, caplog)
Test update of discovered switch.
Test update of discovered switch.
async def test_discovery_update_unchanged_switch(hass, mqtt_mock, caplog): """Test update of discovered switch.""" data1 = ( '{ "name": "Beer",' ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) with patch( "homeassistant.components.mqtt.switch.MqttSwitch.discovery_update" ) as discovery_update: await help_test_discovery_update_unchanged( hass, mqtt_mock, caplog, switch.DOMAIN, data1, discovery_update )
[ "async", "def", "test_discovery_update_unchanged_switch", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "data1", "=", "(", "'{ \"name\": \"Beer\",'", "' \"state_topic\": \"test_topic\",'", "' \"command_topic\": \"test_topic\" }'", ")", "with", "patch", "(", "\"homeassistant.components.mqtt.switch.MqttSwitch.discovery_update\"", ")", "as", "discovery_update", ":", "await", "help_test_discovery_update_unchanged", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "switch", ".", "DOMAIN", ",", "data1", ",", "discovery_update", ")" ]
[ 381, 0 ]
[ 393, 9 ]
python
en
['en', 'en', 'en']
True
test_discovery_broken
(hass, mqtt_mock, caplog)
Test handling of bad discovery message.
Test handling of bad discovery message.
async def test_discovery_broken(hass, mqtt_mock, caplog): """Test handling of bad discovery message.""" data1 = '{ "name": "Beer" }' data2 = ( '{ "name": "Milk",' ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) await help_test_discovery_broken( hass, mqtt_mock, caplog, switch.DOMAIN, data1, data2 )
[ "async", "def", "test_discovery_broken", "(", "hass", ",", "mqtt_mock", ",", "caplog", ")", ":", "data1", "=", "'{ \"name\": \"Beer\" }'", "data2", "=", "(", "'{ \"name\": \"Milk\",'", "' \"state_topic\": \"test_topic\",'", "' \"command_topic\": \"test_topic\" }'", ")", "await", "help_test_discovery_broken", "(", "hass", ",", "mqtt_mock", ",", "caplog", ",", "switch", ".", "DOMAIN", ",", "data1", ",", "data2", ")" ]
[ 397, 0 ]
[ 407, 5 ]
python
en
['en', 'en', 'en']
True
test_entity_device_info_with_connection
(hass, mqtt_mock)
Test MQTT switch device registry integration.
Test MQTT switch device registry integration.
async def test_entity_device_info_with_connection(hass, mqtt_mock): """Test MQTT switch device registry integration.""" await help_test_entity_device_info_with_connection( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_device_info_with_connection", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_device_info_with_connection", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 410, 0 ]
[ 414, 5 ]
python
en
['en', 'en', 'en']
True
test_entity_device_info_with_identifier
(hass, mqtt_mock)
Test MQTT switch device registry integration.
Test MQTT switch device registry integration.
async def test_entity_device_info_with_identifier(hass, mqtt_mock): """Test MQTT switch device registry integration.""" await help_test_entity_device_info_with_identifier( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_device_info_with_identifier", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_device_info_with_identifier", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 417, 0 ]
[ 421, 5 ]
python
en
['en', 'en', 'en']
True
test_entity_device_info_update
(hass, mqtt_mock)
Test device registry update.
Test device registry update.
async def test_entity_device_info_update(hass, mqtt_mock): """Test device registry update.""" await help_test_entity_device_info_update( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_device_info_update", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_device_info_update", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 424, 0 ]
[ 428, 5 ]
python
en
['fr', 'fy', 'en']
False
test_entity_device_info_remove
(hass, mqtt_mock)
Test device registry remove.
Test device registry remove.
async def test_entity_device_info_remove(hass, mqtt_mock): """Test device registry remove.""" await help_test_entity_device_info_remove( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_device_info_remove", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_device_info_remove", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 431, 0 ]
[ 435, 5 ]
python
en
['fr', 'en', 'en']
True
test_entity_id_update_subscriptions
(hass, mqtt_mock)
Test MQTT subscriptions are managed when entity_id is updated.
Test MQTT subscriptions are managed when entity_id is updated.
async def test_entity_id_update_subscriptions(hass, mqtt_mock): """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_id_update_subscriptions", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_id_update_subscriptions", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 438, 0 ]
[ 442, 5 ]
python
en
['en', 'en', 'en']
True
test_entity_id_update_discovery_update
(hass, mqtt_mock)
Test MQTT discovery update when entity_id is updated.
Test MQTT discovery update when entity_id is updated.
async def test_entity_id_update_discovery_update(hass, mqtt_mock): """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_id_update_discovery_update", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_id_update_discovery_update", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 445, 0 ]
[ 449, 5 ]
python
en
['en', 'en', 'en']
True
test_entity_debug_info_message
(hass, mqtt_mock)
Test MQTT debug info.
Test MQTT debug info.
async def test_entity_debug_info_message(hass, mqtt_mock): """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, mqtt_mock, switch.DOMAIN, DEFAULT_CONFIG )
[ "async", "def", "test_entity_debug_info_message", "(", "hass", ",", "mqtt_mock", ")", ":", "await", "help_test_entity_debug_info_message", "(", "hass", ",", "mqtt_mock", ",", "switch", ".", "DOMAIN", ",", "DEFAULT_CONFIG", ")" ]
[ 452, 0 ]
[ 456, 5 ]
python
es
['es', 'mt', 'it']
False