Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
NextBusDepartureSensor.name
(self)
Return sensor name. Uses an auto generated name based on the data from the API unless a custom name is provided in the configuration.
Return sensor name.
def name(self): """Return sensor name. Uses an auto generated name based on the data from the API unless a custom name is provided in the configuration. """ if self._custom_name: return self._custom_name return self._name
[ "def", "name", "(", "self", ")", ":", "if", "self", ".", "_custom_name", ":", "return", "self", ".", "_custom_name", "return", "self", ".", "_name" ]
[ 136, 4 ]
[ 145, 25 ]
python
en
['en', 'id', 'en']
True
NextBusDepartureSensor.device_class
(self)
Return the device class.
Return the device class.
def device_class(self): """Return the device class.""" return DEVICE_CLASS_TIMESTAMP
[ "def", "device_class", "(", "self", ")", ":", "return", "DEVICE_CLASS_TIMESTAMP" ]
[ 148, 4 ]
[ 150, 37 ]
python
en
['en', 'en', 'en']
True
NextBusDepartureSensor.state
(self)
Return current state of the sensor.
Return current state of the sensor.
def state(self): """Return current state of the sensor.""" return self._state
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "_state" ]
[ 153, 4 ]
[ 155, 26 ]
python
en
['en', 'en', 'en']
True
NextBusDepartureSensor.device_state_attributes
(self)
Return additional state attributes.
Return additional state attributes.
def device_state_attributes(self): """Return additional state attributes.""" return self._attributes
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "self", ".", "_attributes" ]
[ 158, 4 ]
[ 160, 31 ]
python
en
['en', 'en', 'en']
True
NextBusDepartureSensor.icon
(self)
Return icon to be used for this sensor.
Return icon to be used for this sensor.
def icon(self): """Return icon to be used for this sensor.""" # Would be nice if we could determine if the line is a train or bus # however that doesn't seem to be available to us. Using bus for now. return ICON
[ "def", "icon", "(", "self", ")", ":", "# Would be nice if we could determine if the line is a train or bus", "# however that doesn't seem to be available to us. Using bus for now.", "return", "ICON" ]
[ 163, 4 ]
[ 167, 19 ]
python
en
['en', 'en', 'en']
True
NextBusDepartureSensor.update
(self)
Update sensor with new departures times.
Update sensor with new departures times.
def update(self): """Update sensor with new departures times.""" # Note: using Multi because there is a bug with the single stop impl results = self._client.get_predictions_for_multi_stops( [{"stop_tag": self.stop, "route_tag": self.route}], self.agency ) self._log_d...
[ "def", "update", "(", "self", ")", ":", "# Note: using Multi because there is a bug with the single stop impl", "results", "=", "self", ".", "_client", ".", "get_predictions_for_multi_stops", "(", "[", "{", "\"stop_tag\"", ":", "self", ".", "stop", ",", "\"route_tag\"",...
[ 169, 4 ]
[ 234, 21 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass: HomeAssistantType, config: dict)
Set up the twinkly integration.
Set up the twinkly integration.
async def async_setup(hass: HomeAssistantType, config: dict): """Set up the twinkly integration.""" return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistantType", ",", "config", ":", "dict", ")", ":", "return", "True" ]
[ 11, 0 ]
[ 14, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass: HomeAssistantType, config_entry: ConfigEntry)
Set up entries from config flow.
Set up entries from config flow.
async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry): """Set up entries from config flow.""" # We setup the client here so if at some point we add any other entity for this device, # we will be able to properly share the connection. uuid = config_entry.data[CONF_ENTRY_ID] ...
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistantType", ",", "config_entry", ":", "ConfigEntry", ")", ":", "# We setup the client here so if at some point we add any other entity for this device,", "# we will be able to properly share the connection.", "uuid", "="...
[ 17, 0 ]
[ 32, 15 ]
python
en
['en', 'en', 'en']
True
async_unload_entry
(hass: HomeAssistantType, config_entry: ConfigEntry)
Remove a twinkly entry.
Remove a twinkly entry.
async def async_unload_entry(hass: HomeAssistantType, config_entry: ConfigEntry): """Remove a twinkly entry.""" # For now light entries don't have unload method, so we don't have to async_forward_entry_unload # However we still have to cleanup the shared client! uuid = config_entry.data[CONF_ENTRY_ID] ...
[ "async", "def", "async_unload_entry", "(", "hass", ":", "HomeAssistantType", ",", "config_entry", ":", "ConfigEntry", ")", ":", "# For now light entries don't have unload method, so we don't have to async_forward_entry_unload", "# However we still have to cleanup the shared client!", "...
[ 35, 0 ]
[ 43, 15 ]
python
en
['en', 'en', 'en']
True
make_new_folder
(*paths)
Cria diretório caso ele ainda não exista e retorna o path correspondente.
Cria diretório caso ele ainda não exista e retorna o path correspondente.
def make_new_folder(*paths): """Cria diretório caso ele ainda não exista e retorna o path correspondente.""" folder_path = os.path.join(*paths) if not os.path.exists(folder_path): os.makedirs(folder_path) return folder_path
[ "def", "make_new_folder", "(", "*", "paths", ")", ":", "folder_path", "=", "os", ".", "path", ".", "join", "(", "*", "paths", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "folder_path", ")", ":", "os", ".", "makedirs", "(", "folder_path",...
[ 4, 0 ]
[ 10, 22 ]
python
pt
['pt', 'pt', 'pt']
True
csv_file
(final_list)
Exporta CSV com informações gerais dos papers.
Exporta CSV com informações gerais dos papers.
def csv_file(final_list): """Exporta CSV com informações gerais dos papers.""" print('Salvando arquivo .csv com todas as informações: autores/instituições, título, tipo, evento, ano, link do pdf') df = pd.DataFrame(final_list, columns=['Autor(es)/Instituições', 'Título', 'Tipo', 'Evento', 'Ano', 'Link do Ar...
[ "def", "csv_file", "(", "final_list", ")", ":", "print", "(", "'Salvando arquivo .csv com todas as informações: autores/instituições, título, tipo, evento, ano, link do pdf')", "", "df", "=", "pd", ".", "DataFrame", "(", "final_list", ",", "columns", "=", "[", "'Autor(es)/I...
[ 13, 0 ]
[ 18, 31 ]
python
pt
['pt', 'pt', 'pt']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the SCSGate cover.
Set up the SCSGate cover.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the SCSGate cover.""" devices = config.get(CONF_DEVICES) covers = [] logger = logging.getLogger(__name__) scsgate = hass.data[DOMAIN] if devices: for entity_info in devices.values(): if entity_inf...
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "devices", "=", "config", ".", "get", "(", "CONF_DEVICES", ")", "covers", "=", "[", "]", "logger", "=", "logging", ".", "getLogger", "...
[ 21, 0 ]
[ 44, 24 ]
python
en
['en', 'en', 'en']
True
SCSGateCover.__init__
(self, scs_id, name, logger, scsgate)
Initialize the cover.
Initialize the cover.
def __init__(self, scs_id, name, logger, scsgate): """Initialize the cover.""" self._scs_id = scs_id self._name = name self._logger = logger self._scsgate = scsgate
[ "def", "__init__", "(", "self", ",", "scs_id", ",", "name", ",", "logger", ",", "scsgate", ")", ":", "self", ".", "_scs_id", "=", "scs_id", "self", ".", "_name", "=", "name", "self", ".", "_logger", "=", "logger", "self", ".", "_scsgate", "=", "scsga...
[ 50, 4 ]
[ 55, 31 ]
python
en
['en', 'en', 'en']
True
SCSGateCover.scs_id
(self)
Return the SCSGate ID.
Return the SCSGate ID.
def scs_id(self): """Return the SCSGate ID.""" return self._scs_id
[ "def", "scs_id", "(", "self", ")", ":", "return", "self", ".", "_scs_id" ]
[ 58, 4 ]
[ 60, 27 ]
python
en
['en', 'co', 'en']
True
SCSGateCover.should_poll
(self)
No polling needed.
No polling needed.
def should_poll(self): """No polling needed.""" return False
[ "def", "should_poll", "(", "self", ")", ":", "return", "False" ]
[ 63, 4 ]
[ 65, 20 ]
python
en
['en', 'en', 'en']
True
SCSGateCover.name
(self)
Return the name of the cover.
Return the name of the cover.
def name(self): """Return the name of the cover.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 68, 4 ]
[ 70, 25 ]
python
en
['en', 'en', 'en']
True
SCSGateCover.is_closed
(self)
Return if the cover is closed.
Return if the cover is closed.
def is_closed(self): """Return if the cover is closed.""" return None
[ "def", "is_closed", "(", "self", ")", ":", "return", "None" ]
[ 73, 4 ]
[ 75, 19 ]
python
en
['en', 'en', 'en']
True
SCSGateCover.open_cover
(self, **kwargs)
Move the cover.
Move the cover.
def open_cover(self, **kwargs): """Move the cover.""" self._scsgate.append_task(RaiseRollerShutterTask(target=self._scs_id))
[ "def", "open_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_scsgate", ".", "append_task", "(", "RaiseRollerShutterTask", "(", "target", "=", "self", ".", "_scs_id", ")", ")" ]
[ 77, 4 ]
[ 79, 78 ]
python
en
['en', 'en', 'en']
True
SCSGateCover.close_cover
(self, **kwargs)
Move the cover down.
Move the cover down.
def close_cover(self, **kwargs): """Move the cover down.""" self._scsgate.append_task(LowerRollerShutterTask(target=self._scs_id))
[ "def", "close_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_scsgate", ".", "append_task", "(", "LowerRollerShutterTask", "(", "target", "=", "self", ".", "_scs_id", ")", ")" ]
[ 81, 4 ]
[ 83, 78 ]
python
en
['en', 'en', 'en']
True
SCSGateCover.stop_cover
(self, **kwargs)
Stop the cover.
Stop the cover.
def stop_cover(self, **kwargs): """Stop the cover.""" self._scsgate.append_task(HaltRollerShutterTask(target=self._scs_id))
[ "def", "stop_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_scsgate", ".", "append_task", "(", "HaltRollerShutterTask", "(", "target", "=", "self", ".", "_scs_id", ")", ")" ]
[ 85, 4 ]
[ 87, 77 ]
python
en
['en', 'en', 'en']
True
SCSGateCover.process_event
(self, message)
Handle a SCSGate message related with this cover.
Handle a SCSGate message related with this cover.
def process_event(self, message): """Handle a SCSGate message related with this cover.""" self._logger.debug("Cover %s, got message %s", self._scs_id, message.toggled)
[ "def", "process_event", "(", "self", ",", "message", ")", ":", "self", ".", "_logger", ".", "debug", "(", "\"Cover %s, got message %s\"", ",", "self", ".", "_scs_id", ",", "message", ".", "toggled", ")" ]
[ 89, 4 ]
[ 91, 85 ]
python
en
['en', 'en', 'en']
True
setup
(hass, base_config)
Set up the mychevy component.
Set up the mychevy component.
def setup(hass, base_config): """Set up the mychevy component.""" config = base_config.get(DOMAIN) email = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) country = config.get(CONF_COUNTRY) hass.data[DOMAIN] = MyChevyHub( mc.MyChevy(email, password, country), hass, base_c...
[ "def", "setup", "(", "hass", ",", "base_config", ")", ":", "config", "=", "base_config", ".", "get", "(", "DOMAIN", ")", "email", "=", "config", ".", "get", "(", "CONF_USERNAME", ")", "password", "=", "config", ".", "get", "(", "CONF_PASSWORD", ")", "c...
[ 71, 0 ]
[ 83, 15 ]
python
en
['en', 'fr', 'en']
True
EVSensorConfig.__init__
( self, name, attr, unit_of_measurement=None, icon=None, extra_attrs=None )
Create new sensor configuration.
Create new sensor configuration.
def __init__( self, name, attr, unit_of_measurement=None, icon=None, extra_attrs=None ): """Create new sensor configuration.""" self.name = name self.attr = attr self.extra_attrs = extra_attrs or [] self.unit_of_measurement = unit_of_measurement self.icon = ic...
[ "def", "__init__", "(", "self", ",", "name", ",", "attr", ",", "unit_of_measurement", "=", "None", ",", "icon", "=", "None", ",", "extra_attrs", "=", "None", ")", ":", "self", ".", "name", "=", "name", "self", ".", "attr", "=", "attr", "self", ".", ...
[ 50, 4 ]
[ 58, 24 ]
python
en
['pl', 'ro', 'en']
False
EVBinarySensorConfig.__init__
(self, name, attr, device_class=None)
Create new binary sensor configuration.
Create new binary sensor configuration.
def __init__(self, name, attr, device_class=None): """Create new binary sensor configuration.""" self.name = name self.attr = attr self.device_class = device_class
[ "def", "__init__", "(", "self", ",", "name", ",", "attr", ",", "device_class", "=", "None", ")", ":", "self", ".", "name", "=", "name", "self", ".", "attr", "=", "attr", "self", ".", "device_class", "=", "device_class" ]
[ 64, 4 ]
[ 68, 40 ]
python
en
['en', 'it', 'en']
True
MyChevyHub.__init__
(self, client, hass, hass_config)
Initialize MyChevy Hub.
Initialize MyChevy Hub.
def __init__(self, client, hass, hass_config): """Initialize MyChevy Hub.""" super().__init__() self._client = client self.hass = hass self.hass_config = hass_config self.cars = [] self.status = None self.ready = False
[ "def", "__init__", "(", "self", ",", "client", ",", "hass", ",", "hass_config", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "_client", "=", "client", "self", ".", "hass", "=", "hass", "self", ".", "hass_config", "=", "hass_co...
[ 100, 4 ]
[ 108, 26 ]
python
cs
['cs', 'pl', 'en']
False
MyChevyHub.update
(self)
Update sensors from mychevy website. This is a synchronous polling call that takes a very long time (like 2 to 3 minutes long time)
Update sensors from mychevy website.
def update(self): """Update sensors from mychevy website. This is a synchronous polling call that takes a very long time (like 2 to 3 minutes long time) """ self._client.login() self._client.get_cars() self.cars = self._client.cars if self.ready is not T...
[ "def", "update", "(", "self", ")", ":", "self", ".", "_client", ".", "login", "(", ")", "self", ".", "_client", ".", "get_cars", "(", ")", "self", ".", "cars", "=", "self", ".", "_client", ".", "cars", "if", "self", ".", "ready", "is", "not", "Tr...
[ 111, 4 ]
[ 127, 46 ]
python
en
['en', 'en', 'en']
True
MyChevyHub.get_car
(self, vid)
Compatibility to work with one car.
Compatibility to work with one car.
def get_car(self, vid): """Compatibility to work with one car.""" if self.cars: for car in self.cars: if car.vid == vid: return car return None
[ "def", "get_car", "(", "self", ",", "vid", ")", ":", "if", "self", ".", "cars", ":", "for", "car", "in", "self", ".", "cars", ":", "if", "car", ".", "vid", "==", "vid", ":", "return", "car", "return", "None" ]
[ 129, 4 ]
[ 135, 19 ]
python
en
['en', 'en', 'en']
True
MyChevyHub.run
(self)
Thread run loop.
Thread run loop.
def run(self): """Thread run loop.""" # We add the status device first outside of the loop # And then busy wait on threads while True: try: _LOGGER.info("Starting mychevy loop") self.update() self.hass.helpers.dispatcher.dispat...
[ "def", "run", "(", "self", ")", ":", "# We add the status device first outside of the loop", "# And then busy wait on threads", "while", "True", ":", "try", ":", "_LOGGER", ".", "info", "(", "\"Starting mychevy loop\"", ")", "self", ".", "update", "(", ")", "self", ...
[ 137, 4 ]
[ 154, 52 ]
python
en
['es', 'mn', 'en']
False
host_valid
(host)
Return True if hostname or IP address is valid.
Return True if hostname or IP address is valid.
def host_valid(host): """Return True if hostname or IP address is valid.""" try: if ipaddress.ip_address(host).version == (4 or 6): return True except ValueError: disallowed = re.compile(r"[^a-zA-Z\d\-]") return all(x and not disallowed.search(x) for x in host.split("."))
[ "def", "host_valid", "(", "host", ")", ":", "try", ":", "if", "ipaddress", ".", "ip_address", "(", "host", ")", ".", "version", "==", "(", "4", "or", "6", ")", ":", "return", "True", "except", "ValueError", ":", "disallowed", "=", "re", ".", "compile...
[ 32, 0 ]
[ 39, 75 ]
python
en
['en', 'af', 'en']
True
_try_connect_and_fetch_basic_info
(host, token)
Attempt to connect and call the ping endpoint and, if successful, fetch basic information.
Attempt to connect and call the ping endpoint and, if successful, fetch basic information.
def _try_connect_and_fetch_basic_info(host, token): """Attempt to connect and call the ping endpoint and, if successful, fetch basic information.""" # Perform the ping. This doesn't validate authentication. controller = VilfoClient(host=host, token=token) result = {"type": None, "data": {}} try: ...
[ "def", "_try_connect_and_fetch_basic_info", "(", "host", ",", "token", ")", ":", "# Perform the ping. This doesn't validate authentication.", "controller", "=", "VilfoClient", "(", "host", "=", "host", ",", "token", "=", "token", ")", "result", "=", "{", "\"type\"", ...
[ 42, 0 ]
[ 73, 17 ]
python
en
['en', 'en', 'en']
True
validate_input
(hass: core.HomeAssistant, data)
Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user.
Validate the user input allows us to connect.
async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user. """ # Validate the host before doing anything else. if not host_valid(data[CONF_HOST]): raise InvalidHost con...
[ "async", "def", "validate_input", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "data", ")", ":", "# Validate the host before doing anything else.", "if", "not", "host_valid", "(", "data", "[", "CONF_HOST", "]", ")", ":", "raise", "InvalidHost", "config", ...
[ 76, 0 ]
[ 102, 17 ]
python
en
['en', 'en', 'en']
True
DomainConfigFlow.async_step_user
(self, user_input=None)
Handle the initial step.
Handle the initial step.
async def async_step_user(self, user_input=None): """Handle the initial step.""" errors = {} if user_input is not None: try: info = await validate_input(self.hass, user_input) except InvalidHost: errors[CONF_HOST] = "wrong_host" ...
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "try", ":", "info", "=", "await", "validate_input", "(", "self", ".", "hass", ",", "user_in...
[ 111, 4 ]
[ 134, 9 ]
python
en
['en', 'en', 'en']
True
scale_jpeg_camera_image
(cam_image, width, height)
Scale a camera image as close as possible to one of the supported scaling factors.
Scale a camera image as close as possible to one of the supported scaling factors.
def scale_jpeg_camera_image(cam_image, width, height): """Scale a camera image as close as possible to one of the supported scaling factors.""" turbo_jpeg = TurboJPEGSingleton.instance() if not turbo_jpeg: return cam_image.content (current_width, current_height, _, _) = turbo_jpeg.decode_header...
[ "def", "scale_jpeg_camera_image", "(", "cam_image", ",", "width", ",", "height", ")", ":", "turbo_jpeg", "=", "TurboJPEGSingleton", ".", "instance", "(", ")", "if", "not", "turbo_jpeg", ":", "return", "cam_image", ".", "content", "(", "current_width", ",", "cu...
[ 9, 0 ]
[ 32, 5 ]
python
en
['en', 'en', 'en']
True
TurboJPEGSingleton.instance
()
Singleton for TurboJPEG.
Singleton for TurboJPEG.
def instance(): """Singleton for TurboJPEG.""" if TurboJPEGSingleton.__instance is None: TurboJPEGSingleton() return TurboJPEGSingleton.__instance
[ "def", "instance", "(", ")", ":", "if", "TurboJPEGSingleton", ".", "__instance", "is", "None", ":", "TurboJPEGSingleton", "(", ")", "return", "TurboJPEGSingleton", ".", "__instance" ]
[ 47, 4 ]
[ 51, 44 ]
python
en
['en', 'no', 'en']
True
TurboJPEGSingleton.__init__
(self)
Try to create TurboJPEG only once.
Try to create TurboJPEG only once.
def __init__(self): """Try to create TurboJPEG only once.""" try: # TurboJPEG checks for libturbojpeg # when its created, but it imports # numpy which may or may not work so # we have to guard the import here. from turbojpeg import TurboJPEG #...
[ "def", "__init__", "(", "self", ")", ":", "try", ":", "# TurboJPEG checks for libturbojpeg", "# when its created, but it imports", "# numpy which may or may not work so", "# we have to guard the import here.", "from", "turbojpeg", "import", "TurboJPEG", "# pylint: disable=import-outs...
[ 53, 4 ]
[ 67, 49 ]
python
en
['en', 'en', 'en']
True
_setattr
(model, name, module)
Parameters ---------- model : pytorch model The model to speed up by quantization name : str name of pytorch module module : torch.nn.Module Layer module of pytorch model
Parameters ---------- model : pytorch model The model to speed up by quantization name : str name of pytorch module module : torch.nn.Module Layer module of pytorch model
def _setattr(model, name, module): """ Parameters ---------- model : pytorch model The model to speed up by quantization name : str name of pytorch module module : torch.nn.Module Layer module of pytorch model """ name_list = name.split(".") for name in name_l...
[ "def", "_setattr", "(", "model", ",", "name", ",", "module", ")", ":", "name_list", "=", "name", ".", "split", "(", "\".\"", ")", "for", "name", "in", "name_list", "[", ":", "-", "1", "]", ":", "model", "=", "getattr", "(", "model", ",", "name", ...
[ 34, 0 ]
[ 48, 41 ]
python
en
['en', 'error', 'th']
False
unwrapper
(model_onnx, index2name, config)
Fill onnx config and remove wrapper node in onnx Parameters ---------- model_onnx : onnx model Onnx model which is converted from pytorch model index2name : dict Dictionary of layer index and name config : dict Config recording name of layers and calibration parameters ...
Fill onnx config and remove wrapper node in onnx
def unwrapper(model_onnx, index2name, config): """ Fill onnx config and remove wrapper node in onnx Parameters ---------- model_onnx : onnx model Onnx model which is converted from pytorch model index2name : dict Dictionary of layer index and name config : dict Confi...
[ "def", "unwrapper", "(", "model_onnx", ",", "index2name", ",", "config", ")", ":", "# Support Gemm, Conv, Relu, Clip(Relu6) and Maxpool", "support_op", "=", "[", "'Gemm'", ",", "'Conv'", ",", "'Relu'", ",", "'Clip'", ",", "'MaxP'", "]", "idx", "=", "0", "onnx_co...
[ 50, 0 ]
[ 91, 34 ]
python
en
['en', 'error', 'th']
False
torch_to_onnx
(model, config, input_shape, model_path, input_names, output_names)
Convert torch model to onnx model and get layer bit config of onnx model. Parameters ---------- model : pytorch model The model to speed up by quantization config : dict Config recording bit number and name of layers input_shape : tuple The input shape of model, shall p...
Convert torch model to onnx model and get layer bit config of onnx model.
def torch_to_onnx(model, config, input_shape, model_path, input_names, output_names): """ Convert torch model to onnx model and get layer bit config of onnx model. Parameters ---------- model : pytorch model The model to speed up by quantization config : dict Config recording bi...
[ "def", "torch_to_onnx", "(", "model", ",", "config", ",", "input_shape", ",", "model_path", ",", "input_names", ",", "output_names", ")", ":", "# Support Gemm, Conv, Relu, Clip(Relu6) and MaxPool", "support_op", "=", "[", "torch", ".", "nn", ".", "Conv2d", ",", "t...
[ 93, 0 ]
[ 147, 34 ]
python
en
['en', 'error', 'th']
False
LayernameModuleWrapper.__init__
(self, module, module_bit)
Parameters ---------- module : torch.nn.Module Layer module of pytorch model module_bit : int Bit width setting for module
Parameters ---------- module : torch.nn.Module Layer module of pytorch model module_bit : int Bit width setting for module
def __init__(self, module, module_bit) -> None: """ Parameters ---------- module : torch.nn.Module Layer module of pytorch model module_bit : int Bit width setting for module """ super().__init__() self.module = module self....
[ "def", "__init__", "(", "self", ",", "module", ",", "module_bit", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "module", "=", "module", "self", ".", "module_bit", "=", "module_bit" ]
[ 16, 4 ]
[ 27, 36 ]
python
en
['en', 'error', 'th']
False
check_output_command
(file_path, head=None, tail=None)
call check_output command to read content from a file
call check_output command to read content from a file
def check_output_command(file_path, head=None, tail=None): """call check_output command to read content from a file""" if os.path.exists(file_path): if sys.platform == 'win32': cmds = ['powershell.exe', 'type', file_path] if head: cmds += ['|', 'select', '-first',...
[ "def", "check_output_command", "(", "file_path", ",", "head", "=", "None", ",", "tail", "=", "None", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "file_path", ")", ":", "if", "sys", ".", "platform", "==", "'win32'", ":", "cmds", "=", "[", ...
[ 11, 0 ]
[ 30, 15 ]
python
en
['en', 'en', 'en']
True
kill_command
(pid)
kill command
kill command
def kill_command(pid): """kill command""" if sys.platform == 'win32': process = psutil.Process(pid=pid) process.send_signal(signal.CTRL_BREAK_EVENT) else: cmds = ['kill', str(pid)] call(cmds)
[ "def", "kill_command", "(", "pid", ")", ":", "if", "sys", ".", "platform", "==", "'win32'", ":", "process", "=", "psutil", ".", "Process", "(", "pid", "=", "pid", ")", "process", ".", "send_signal", "(", "signal", ".", "CTRL_BREAK_EVENT", ")", "else", ...
[ 33, 0 ]
[ 40, 18 ]
python
en
['en', 'mg', 'en']
False
install_package_command
(package_name)
Install python package from pip. Parameters ---------- package_name: str The name of package to be installed.
Install python package from pip.
def install_package_command(package_name): """ Install python package from pip. Parameters ---------- package_name: str The name of package to be installed. """ call(_get_pip_install() + [package_name], shell=False)
[ "def", "install_package_command", "(", "package_name", ")", ":", "call", "(", "_get_pip_install", "(", ")", "+", "[", "package_name", "]", ",", "shell", "=", "False", ")" ]
[ 43, 0 ]
[ 52, 58 ]
python
en
['en', 'error', 'th']
False
install_requirements_command
(requirements_path)
Install packages from `requirements.txt` in `requirements_path`. Parameters ---------- requirements_path: str Path to the directory that contains `requirements.txt`.
Install packages from `requirements.txt` in `requirements_path`.
def install_requirements_command(requirements_path): """ Install packages from `requirements.txt` in `requirements_path`. Parameters ---------- requirements_path: str Path to the directory that contains `requirements.txt`. """ return call(_get_pip_install() + ["-r", requirements_pat...
[ "def", "install_requirements_command", "(", "requirements_path", ")", ":", "return", "call", "(", "_get_pip_install", "(", ")", "+", "[", "\"-r\"", ",", "requirements_path", "]", ",", "shell", "=", "False", ")" ]
[ 55, 0 ]
[ 64, 76 ]
python
en
['en', 'error', 'th']
False
validate_input
(hass: core.HomeAssistant, data)
Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user.
Validate the user input allows us to connect.
async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user. """ hub_address = data[CONF_HOST] websession = async_get_clientsession(hass) pv_request = AioRequest(hub_address, loo...
[ "async", "def", "validate_input", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "data", ")", ":", "hub_address", "=", "data", "[", "CONF_HOST", "]", "websession", "=", "async_get_clientsession", "(", "hass", ")", "pv_request", "=", "AioRequest", "(", ...
[ 21, 0 ]
[ 44, 5 ]
python
en
['en', 'en', 'en']
True
ConfigFlow.__init__
(self)
Initialize the powerview config flow.
Initialize the powerview config flow.
def __init__(self): """Initialize the powerview config flow.""" self.powerview_config = {}
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "powerview_config", "=", "{", "}" ]
[ 53, 4 ]
[ 55, 34 ]
python
en
['en', 'en', 'en']
True
ConfigFlow.async_step_user
(self, user_input=None)
Handle the initial step.
Handle the initial step.
async def async_step_user(self, user_input=None): """Handle the initial step.""" errors = {} if user_input is not None: if self._host_already_configured(user_input[CONF_HOST]): return self.async_abort(reason="already_configured") try: info ...
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "if", "self", ".", "_host_already_configured", "(", "user_input", "[", "CONF_HOST", "]", ")", ...
[ 57, 4 ]
[ 79, 9 ]
python
en
['en', 'en', 'en']
True
ConfigFlow.async_step_import
(self, user_input=None)
Handle the initial step.
Handle the initial step.
async def async_step_import(self, user_input=None): """Handle the initial step.""" return await self.async_step_user(user_input)
[ "async", "def", "async_step_import", "(", "self", ",", "user_input", "=", "None", ")", ":", "return", "await", "self", ".", "async_step_user", "(", "user_input", ")" ]
[ 81, 4 ]
[ 83, 53 ]
python
en
['en', 'en', 'en']
True
ConfigFlow.async_step_homekit
(self, homekit_info)
Handle HomeKit discovery.
Handle HomeKit discovery.
async def async_step_homekit(self, homekit_info): """Handle HomeKit discovery.""" # If we already have the host configured do # not open connections to it if we can avoid it. if self._host_already_configured(homekit_info[CONF_HOST]): return self.async_abort(reason="already_c...
[ "async", "def", "async_step_homekit", "(", "self", ",", "homekit_info", ")", ":", "# If we already have the host configured do", "# not open connections to it if we can avoid it.", "if", "self", ".", "_host_already_configured", "(", "homekit_info", "[", "CONF_HOST", "]", ")",...
[ 85, 4 ]
[ 111, 43 ]
python
en
['fr', 'xh', 'en']
False
ConfigFlow.async_step_link
(self, user_input=None)
Attempt to link with Powerview.
Attempt to link with Powerview.
async def async_step_link(self, user_input=None): """Attempt to link with Powerview.""" if user_input is not None: return self.async_create_entry( title=self.powerview_config[CONF_NAME], data={CONF_HOST: self.powerview_config[CONF_HOST]}, ) ...
[ "async", "def", "async_step_link", "(", "self", ",", "user_input", "=", "None", ")", ":", "if", "user_input", "is", "not", "None", ":", "return", "self", ".", "async_create_entry", "(", "title", "=", "self", ".", "powerview_config", "[", "CONF_NAME", "]", ...
[ 113, 4 ]
[ 123, 9 ]
python
en
['en', 'en', 'en']
True
ConfigFlow._host_already_configured
(self, host)
See if we already have a hub with the host address configured.
See if we already have a hub with the host address configured.
def _host_already_configured(self, host): """See if we already have a hub with the host address configured.""" existing_hosts = { entry.data[CONF_HOST] for entry in self._async_current_entries() if CONF_HOST in entry.data } return host in existing_host...
[ "def", "_host_already_configured", "(", "self", ",", "host", ")", ":", "existing_hosts", "=", "{", "entry", ".", "data", "[", "CONF_HOST", "]", "for", "entry", "in", "self", ".", "_async_current_entries", "(", ")", "if", "CONF_HOST", "in", "entry", ".", "d...
[ 125, 4 ]
[ 132, 37 ]
python
en
['en', 'en', 'en']
True
test_load_values_when_added_to_hass
(hass)
Test that sensor initializes with observations of relevant entities.
Test that sensor initializes with observations of relevant entities.
async def test_load_values_when_added_to_hass(hass): """Test that sensor initializes with observations of relevant entities.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platf...
[ "async", "def", "test_load_values_when_added_to_hass", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", "...
[ 23, 0 ]
[ 52, 77 ]
python
en
['en', 'en', 'en']
True
test_unknown_state_does_not_influence_probability
(hass)
Test that an unknown state does not change the output probability.
Test that an unknown state does not change the output probability.
async def test_unknown_state_does_not_influence_probability(hass): """Test that an unknown state does not change the output probability.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { ...
[ "async", "def", "test_unknown_state_does_not_influence_probability", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"pl...
[ 55, 0 ]
[ 83, 53 ]
python
en
['en', 'en', 'en']
True
test_sensor_numeric_state
(hass)
Test sensor on numeric state platform observations.
Test sensor on numeric state platform observations.
async def test_sensor_numeric_state(hass): """Test sensor on numeric state platform observations.""" config = { "binary_sensor": { "platform": "bayesian", "name": "Test_Binary", "observations": [ { "platform": "numeric_state", ...
[ "async", "def", "test_sensor_numeric_state", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"platform\"", ":", "\"bayesian\"", ",", "\"name\"", ":", "\"Test_Binary\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":", "\"n...
[ 86, 0 ]
[ 158, 31 ]
python
en
['en', 'da', 'en']
True
test_sensor_state
(hass)
Test sensor on state platform observations.
Test sensor on state platform observations.
async def test_sensor_state(hass): """Test sensor on state platform observations.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platform": "state", "entity_i...
[ "async", "def", "test_sensor_state", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":", "\"state\"",...
[ 161, 0 ]
[ 215, 31 ]
python
en
['en', 'da', 'en']
True
test_sensor_value_template
(hass)
Test sensor on template platform observations.
Test sensor on template platform observations.
async def test_sensor_value_template(hass): """Test sensor on template platform observations.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platform": "template", ...
[ "async", "def", "test_sensor_value_template", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":", "\"...
[ 218, 0 ]
[ 271, 31 ]
python
en
['en', 'da', 'en']
True
test_threshold
(hass)
Test sensor on probability threshold limits.
Test sensor on probability threshold limits.
async def test_threshold(hass): """Test sensor on probability threshold limits.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platform": "state", "entity_id"...
[ "async", "def", "test_threshold", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":", "\"state\"", ...
[ 274, 0 ]
[ 302, 30 ]
python
en
['en', 'zu', 'en']
True
test_multiple_observations
(hass)
Test sensor with multiple observations of same entity.
Test sensor with multiple observations of same entity.
async def test_multiple_observations(hass): """Test sensor with multiple observations of same entity.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platform": "state", ...
[ "async", "def", "test_multiple_observations", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":", "\"...
[ 305, 0 ]
[ 369, 31 ]
python
en
['en', 'da', 'en']
True
test_probability_updates
(hass)
Test probability update function.
Test probability update function.
async def test_probability_updates(hass): """Test probability update function.""" prob_given_true = [0.3, 0.6, 0.8] prob_given_false = [0.7, 0.4, 0.2] prior = 0.5 for pt, pf in zip(prob_given_true, prob_given_false): prior = bayesian.update_probability(prior, pt, pf) assert round(abs(0...
[ "async", "def", "test_probability_updates", "(", "hass", ")", ":", "prob_given_true", "=", "[", "0.3", ",", "0.6", ",", "0.8", "]", "prob_given_false", "=", "[", "0.7", ",", "0.4", ",", "0.2", "]", "prior", "=", "0.5", "for", "pt", ",", "pf", "in", "...
[ 372, 0 ]
[ 390, 57 ]
python
en
['en', 'en', 'en']
True
test_observed_entities
(hass)
Test sensor on observed entities.
Test sensor on observed entities.
async def test_observed_entities(hass): """Test sensor on observed entities.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platform": "state", "entity_id": "...
[ "async", "def", "test_observed_entities", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":", "\"stat...
[ 393, 0 ]
[ 443, 5 ]
python
en
['en', 'et', 'en']
True
test_state_attributes_are_serializable
(hass)
Test sensor on observed entities.
Test sensor on observed entities.
async def test_state_attributes_are_serializable(hass): """Test sensor on observed entities.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platform": "state", ...
[ "async", "def", "test_state_attributes_are_serializable", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ...
[ 446, 0 ]
[ 499, 25 ]
python
en
['en', 'et', 'en']
True
test_template_error
(hass, caplog)
Test sensor with template error.
Test sensor with template error.
async def test_template_error(hass, caplog): """Test sensor with template error.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platform": "template", "value_...
[ "async", "def", "test_template_error", "(", "hass", ",", "caplog", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ...
[ 502, 0 ]
[ 526, 31 ]
python
en
['en', 'ro', 'en']
True
test_update_request_with_template
(hass)
Test sensor on template platform observations that gets an update request.
Test sensor on template platform observations that gets an update request.
async def test_update_request_with_template(hass): """Test sensor on template platform observations that gets an update request.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "pl...
[ "async", "def", "test_update_request_with_template", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":"...
[ 529, 0 ]
[ 562, 70 ]
python
en
['en', 'da', 'en']
True
test_update_request_without_template
(hass)
Test sensor on template platform observations that gets an update request.
Test sensor on template platform observations that gets an update request.
async def test_update_request_without_template(hass): """Test sensor on template platform observations that gets an update request.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { ...
[ "async", "def", "test_update_request_without_template", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ...
[ 565, 0 ]
[ 602, 70 ]
python
en
['en', 'da', 'en']
True
test_monitored_sensor_goes_away
(hass)
Test sensor on template platform observations that goes away.
Test sensor on template platform observations that goes away.
async def test_monitored_sensor_goes_away(hass): """Test sensor on template platform observations that goes away.""" config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { "platform": "state...
[ "async", "def", "test_monitored_sensor_goes_away", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":", ...
[ 605, 0 ]
[ 638, 69 ]
python
en
['en', 'da', 'en']
True
test_reload
(hass)
Verify we can reload bayesian sensors.
Verify we can reload bayesian sensors.
async def test_reload(hass): """Verify we can reload bayesian sensors.""" config = { "binary_sensor": { "name": "test", "platform": "bayesian", "observations": [ { "platform": "state", "entity_id": "sensor.test_...
[ "async", "def", "test_reload", "(", "hass", ")", ":", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"test\"", ",", "\"platform\"", ":", "\"bayesian\"", ",", "\"observations\"", ":", "[", "{", "\"platform\"", ":", "\"state\"", ",", "\"...
[ 641, 0 ]
[ 686, 49 ]
python
en
['en', 'en', 'en']
True
test_template_triggers
(hass)
Test sensor with template triggers.
Test sensor with template triggers.
async def test_template_triggers(hass): """Test sensor with template triggers.""" hass.states.async_set("input_boolean.test", STATE_OFF) config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { ...
[ "async", "def", "test_template_triggers", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"input_boolean.test\"", ",", "STATE_OFF", ")", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platfor...
[ 693, 0 ]
[ 727, 39 ]
python
en
['en', 'en', 'en']
True
test_state_triggers
(hass)
Test sensor with state triggers.
Test sensor with state triggers.
async def test_state_triggers(hass): """Test sensor with state triggers.""" hass.states.async_set("sensor.test_monitored", STATE_OFF) config = { "binary_sensor": { "name": "Test_Binary", "platform": "bayesian", "observations": [ { ...
[ "async", "def", "test_state_triggers", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"sensor.test_monitored\"", ",", "STATE_OFF", ")", "config", "=", "{", "\"binary_sensor\"", ":", "{", "\"name\"", ":", "\"Test_Binary\"", ",", "\"platfor...
[ 730, 0 ]
[ 766, 39 ]
python
en
['en', 'en', 'en']
True
test_config_entry_withings_api
(hass: HomeAssistant)
Test ConfigEntryWithingsApi.
Test ConfigEntryWithingsApi.
async def test_config_entry_withings_api(hass: HomeAssistant) -> None: """Test ConfigEntryWithingsApi.""" config_entry = MockConfigEntry( data={"token": {"access_token": "mock_access_token", "expires_at": 1111111}} ) config_entry.add_to_hass(hass) implementation_mock = MagicMock(spec=Abstra...
[ "async", "def", "test_config_entry_withings_api", "(", "hass", ":", "HomeAssistant", ")", "->", "None", ":", "config_entry", "=", "MockConfigEntry", "(", "data", "=", "{", "\"token\"", ":", "{", "\"access_token\"", ":", "\"mock_access_token\"", ",", "\"expires_at\""...
[ 29, 0 ]
[ 53, 49 ]
python
en
['en', 'zu', 'en']
False
test_webhook_post
( hass: HomeAssistant, component_factory: ComponentFactory, aiohttp_client, user_id: int, arg_user_id: Any, arg_appli: Any, expected_code: int, )
Test webhook callback.
Test webhook callback.
async def test_webhook_post( hass: HomeAssistant, component_factory: ComponentFactory, aiohttp_client, user_id: int, arg_user_id: Any, arg_appli: Any, expected_code: int, ) -> None: """Test webhook callback.""" person0 = new_profile_config("person0", user_id) await component_fac...
[ "async", "def", "test_webhook_post", "(", "hass", ":", "HomeAssistant", ",", "component_factory", ":", "ComponentFactory", ",", "aiohttp_client", ",", "user_id", ":", "int", ",", "arg_user_id", ":", "Any", ",", "arg_appli", ":", "Any", ",", "expected_code", ":",...
[ 68, 0 ]
[ 102, 40 ]
python
en
['en', 'zu', 'en']
True
test_webhook_head
( hass: HomeAssistant, component_factory: ComponentFactory, aiohttp_client, )
Test head method on webhook view.
Test head method on webhook view.
async def test_webhook_head( hass: HomeAssistant, component_factory: ComponentFactory, aiohttp_client, ) -> None: """Test head method on webhook view.""" person0 = new_profile_config("person0", 0) await component_factory.configure_component(profile_configs=(person0,)) await component_factor...
[ "async", "def", "test_webhook_head", "(", "hass", ":", "HomeAssistant", ",", "component_factory", ":", "ComponentFactory", ",", "aiohttp_client", ",", ")", "->", "None", ":", "person0", "=", "new_profile_config", "(", "\"person0\"", ",", "0", ")", "await", "comp...
[ 105, 0 ]
[ 119, 29 ]
python
en
['en', 'et', 'en']
True
test_webhook_put
( hass: HomeAssistant, component_factory: ComponentFactory, aiohttp_client, )
Test webhook callback.
Test webhook callback.
async def test_webhook_put( hass: HomeAssistant, component_factory: ComponentFactory, aiohttp_client, ) -> None: """Test webhook callback.""" person0 = new_profile_config("person0", 0) await component_factory.configure_component(profile_configs=(person0,)) await component_factory.setup_prof...
[ "async", "def", "test_webhook_put", "(", "hass", ":", "HomeAssistant", ",", "component_factory", ":", "ComponentFactory", ",", "aiohttp_client", ",", ")", "->", "None", ":", "person0", "=", "new_profile_config", "(", "\"person0\"", ",", "0", ")", "await", "compo...
[ 122, 0 ]
[ 143, 28 ]
python
en
['en', 'zu', 'en']
True
test_data_manager_webhook_subscription
( hass: HomeAssistant, component_factory: ComponentFactory, aioclient_mock: AiohttpClientMocker, )
Test data manager webhook subscriptions.
Test data manager webhook subscriptions.
async def test_data_manager_webhook_subscription( hass: HomeAssistant, component_factory: ComponentFactory, aioclient_mock: AiohttpClientMocker, ) -> None: """Test data manager webhook subscriptions.""" person0 = new_profile_config("person0", 0) await component_factory.configure_component(profil...
[ "async", "def", "test_data_manager_webhook_subscription", "(", "hass", ":", "HomeAssistant", ",", "component_factory", ":", "ComponentFactory", ",", "aioclient_mock", ":", "AiohttpClientMocker", ",", ")", "->", "None", ":", "person0", "=", "new_profile_config", "(", "...
[ 146, 0 ]
[ 241, 5 ]
python
en
['fr', 'en', 'en']
True
setup_bans
(hass, app, login_threshold)
Create IP Ban middleware for the app.
Create IP Ban middleware for the app.
def setup_bans(hass, app, login_threshold): """Create IP Ban middleware for the app.""" app.middlewares.append(ban_middleware) app[KEY_FAILED_LOGIN_ATTEMPTS] = defaultdict(int) app[KEY_LOGIN_THRESHOLD] = login_threshold async def ban_startup(app): """Initialize bans when app starts up.""" ...
[ "def", "setup_bans", "(", "hass", ",", "app", ",", "login_threshold", ")", ":", "app", ".", "middlewares", ".", "append", "(", "ban_middleware", ")", "app", "[", "KEY_FAILED_LOGIN_ATTEMPTS", "]", "=", "defaultdict", "(", "int", ")", "app", "[", "KEY_LOGIN_TH...
[ 39, 0 ]
[ 51, 38 ]
python
en
['en', 'en', 'en']
True
ban_middleware
(request, handler)
IP Ban middleware.
IP Ban middleware.
async def ban_middleware(request, handler): """IP Ban middleware.""" if KEY_BANNED_IPS not in request.app: _LOGGER.error("IP Ban middleware loaded but banned IPs not loaded") return await handler(request) # Verify if IP is not banned ip_address_ = ip_address(request.remote) is_banne...
[ "async", "def", "ban_middleware", "(", "request", ",", "handler", ")", ":", "if", "KEY_BANNED_IPS", "not", "in", "request", ".", "app", ":", "_LOGGER", ".", "error", "(", "\"IP Ban middleware loaded but banned IPs not loaded\"", ")", "return", "await", "handler", ...
[ 55, 0 ]
[ 74, 13 ]
python
en
['id', 'jv', 'en']
False
log_invalid_auth
(func)
Decorate function to handle invalid auth or failed login attempts.
Decorate function to handle invalid auth or failed login attempts.
def log_invalid_auth(func): """Decorate function to handle invalid auth or failed login attempts.""" async def handle_req(view, request, *args, **kwargs): """Try to log failed login attempts if response status >= 400.""" resp = await func(view, request, *args, **kwargs) if resp.status >...
[ "def", "log_invalid_auth", "(", "func", ")", ":", "async", "def", "handle_req", "(", "view", ",", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "\"\"\"Try to log failed login attempts if response status >= 400.\"\"\"", "resp", "=", "await", "func...
[ 77, 0 ]
[ 87, 21 ]
python
en
['en', 'en', 'en']
True
process_wrong_login
(request)
Process a wrong login attempt. Increase failed login attempts counter for remote IP address. Add ip ban entry if failed login attempts exceeds threshold.
Process a wrong login attempt.
async def process_wrong_login(request): """Process a wrong login attempt. Increase failed login attempts counter for remote IP address. Add ip ban entry if failed login attempts exceeds threshold. """ hass = request.app["hass"] remote_addr = ip_address(request.remote) remote_host = request...
[ "async", "def", "process_wrong_login", "(", "request", ")", ":", "hass", "=", "request", ".", "app", "[", "\"hass\"", "]", "remote_addr", "=", "ip_address", "(", "request", ".", "remote", ")", "remote_host", "=", "request", ".", "remote", "try", ":", "remo...
[ 90, 0 ]
[ 149, 9 ]
python
en
['en', 'lb', 'en']
True
process_success_login
(request)
Process a success login attempt. Reset failed login attempts counter for remote IP address. No release IP address from banned list function, it can only be done by manual modify ip bans config file.
Process a success login attempt.
async def process_success_login(request): """Process a success login attempt. Reset failed login attempts counter for remote IP address. No release IP address from banned list function, it can only be done by manual modify ip bans config file. """ remote_addr = ip_address(request.remote) #...
[ "async", "def", "process_success_login", "(", "request", ")", ":", "remote_addr", "=", "ip_address", "(", "request", ".", "remote", ")", "# Check if ban middleware is loaded", "if", "KEY_BANNED_IPS", "not", "in", "request", ".", "app", "or", "request", ".", "app",...
[ 152, 0 ]
[ 172, 63 ]
python
en
['en', 'lb', 'en']
True
async_load_ip_bans_config
(hass: HomeAssistant, path: str)
Load list of banned IPs from config file.
Load list of banned IPs from config file.
async def async_load_ip_bans_config(hass: HomeAssistant, path: str) -> List[IpBan]: """Load list of banned IPs from config file.""" ip_list: List[IpBan] = [] try: list_ = await hass.async_add_executor_job(load_yaml_config_file, path) except FileNotFoundError: return ip_list except H...
[ "async", "def", "async_load_ip_bans_config", "(", "hass", ":", "HomeAssistant", ",", "path", ":", "str", ")", "->", "List", "[", "IpBan", "]", ":", "ip_list", ":", "List", "[", "IpBan", "]", "=", "[", "]", "try", ":", "list_", "=", "await", "hass", "...
[ 184, 0 ]
[ 204, 18 ]
python
en
['en', 'en', 'en']
True
update_ip_bans_config
(path: str, ip_ban: IpBan)
Update config file with new banned IP address.
Update config file with new banned IP address.
def update_ip_bans_config(path: str, ip_ban: IpBan) -> None: """Update config file with new banned IP address.""" with open(path, "a") as out: ip_ = { str(ip_ban.ip_address): { ATTR_BANNED_AT: ip_ban.banned_at.strftime("%Y-%m-%dT%H:%M:%S") } } out....
[ "def", "update_ip_bans_config", "(", "path", ":", "str", ",", "ip_ban", ":", "IpBan", ")", "->", "None", ":", "with", "open", "(", "path", ",", "\"a\"", ")", "as", "out", ":", "ip_", "=", "{", "str", "(", "ip_ban", ".", "ip_address", ")", ":", "{",...
[ 207, 0 ]
[ 216, 28 ]
python
en
['en', 'en', 'en']
True
IpBan.__init__
(self, ip_ban: str, banned_at: Optional[datetime] = None)
Initialize IP Ban object.
Initialize IP Ban object.
def __init__(self, ip_ban: str, banned_at: Optional[datetime] = None) -> None: """Initialize IP Ban object.""" self.ip_address = ip_address(ip_ban) self.banned_at = banned_at or datetime.utcnow()
[ "def", "__init__", "(", "self", ",", "ip_ban", ":", "str", ",", "banned_at", ":", "Optional", "[", "datetime", "]", "=", "None", ")", "->", "None", ":", "self", ".", "ip_address", "=", "ip_address", "(", "ip_ban", ")", "self", ".", "banned_at", "=", ...
[ 178, 4 ]
[ 181, 55 ]
python
en
['en', 'en', 'it']
True
_init_header
(request: web.Request)
Create initial header.
Create initial header.
def _init_header(request: web.Request) -> Dict[str, str]: """Create initial header.""" headers = { X_HASSIO: os.environ.get("HASSIO_TOKEN", ""), CONTENT_TYPE: request.content_type, } # Add user data user = request.get("hass_user") if user is not None: headers[X_HASS_USER...
[ "def", "_init_header", "(", "request", ":", "web", ".", "Request", ")", "->", "Dict", "[", "str", ",", "str", "]", ":", "headers", "=", "{", "X_HASSIO", ":", "os", ".", "environ", ".", "get", "(", "\"HASSIO_TOKEN\"", ",", "\"\"", ")", ",", "CONTENT_T...
[ 131, 0 ]
[ 144, 18 ]
python
en
['en', 'gd', 'en']
True
_get_timeout
(path: str)
Return timeout for a URL path.
Return timeout for a URL path.
def _get_timeout(path: str) -> int: """Return timeout for a URL path.""" if NO_TIMEOUT.match(path): return 0 return 300
[ "def", "_get_timeout", "(", "path", ":", "str", ")", "->", "int", ":", "if", "NO_TIMEOUT", ".", "match", "(", "path", ")", ":", "return", "0", "return", "300" ]
[ 147, 0 ]
[ 151, 14 ]
python
en
['en', 'en', 'en']
True
_need_auth
(hass, path: str)
Return if a path need authentication.
Return if a path need authentication.
def _need_auth(hass, path: str) -> bool: """Return if a path need authentication.""" if not async_is_onboarded(hass) and NO_AUTH_ONBOARDING.match(path): return False if NO_AUTH.match(path): return False return True
[ "def", "_need_auth", "(", "hass", ",", "path", ":", "str", ")", "->", "bool", ":", "if", "not", "async_is_onboarded", "(", "hass", ")", "and", "NO_AUTH_ONBOARDING", ".", "match", "(", "path", ")", ":", "return", "False", "if", "NO_AUTH", ".", "match", ...
[ 154, 0 ]
[ 160, 15 ]
python
en
['en', 'en', 'en']
True
HassIOView.__init__
(self, host: str, websession: aiohttp.ClientSession)
Initialize a Hass.io base view.
Initialize a Hass.io base view.
def __init__(self, host: str, websession: aiohttp.ClientSession): """Initialize a Hass.io base view.""" self._host = host self._websession = websession
[ "def", "__init__", "(", "self", ",", "host", ":", "str", ",", "websession", ":", "aiohttp", ".", "ClientSession", ")", ":", "self", ".", "_host", "=", "host", "self", ".", "_websession", "=", "websession" ]
[ 52, 4 ]
[ 55, 37 ]
python
en
['it', 'en', 'en']
True
HassIOView._handle
( self, request: web.Request, path: str )
Route data to Hass.io.
Route data to Hass.io.
async def _handle( self, request: web.Request, path: str ) -> Union[web.Response, web.StreamResponse]: """Route data to Hass.io.""" hass = request.app["hass"] if _need_auth(hass, path) and not request[KEY_AUTHENTICATED]: return web.Response(status=HTTP_UNAUTHORIZED) ...
[ "async", "def", "_handle", "(", "self", ",", "request", ":", "web", ".", "Request", ",", "path", ":", "str", ")", "->", "Union", "[", "web", ".", "Response", ",", "web", ".", "StreamResponse", "]", ":", "hass", "=", "request", ".", "app", "[", "\"h...
[ 57, 4 ]
[ 65, 55 ]
python
en
['en', 'en', 'en']
True
HassIOView._command_proxy
( self, path: str, request: web.Request )
Return a client request with proxy origin for Hass.io supervisor. This method is a coroutine.
Return a client request with proxy origin for Hass.io supervisor.
async def _command_proxy( self, path: str, request: web.Request ) -> Union[web.Response, web.StreamResponse]: """Return a client request with proxy origin for Hass.io supervisor. This method is a coroutine. """ read_timeout = _get_timeout(path) data = None he...
[ "async", "def", "_command_proxy", "(", "self", ",", "path", ":", "str", ",", "request", ":", "web", ".", "Request", ")", "->", "Union", "[", "web", ".", "Response", ",", "web", ".", "StreamResponse", "]", ":", "read_timeout", "=", "_get_timeout", "(", ...
[ 71, 4 ]
[ 128, 30 ]
python
en
['en', 'en', 'en']
True
test_config_per_platform
(mock_def)
Test config per platform method.
Test config per platform method.
def test_config_per_platform(mock_def): """Test config per platform method.""" assert scripts.get_default_config_dir() == "/default" assert scripts.extract_config_dir() == "/default" assert scripts.extract_config_dir([""]) == "/default" assert scripts.extract_config_dir(["-c", "/arg"]) == "/arg" ...
[ "def", "test_config_per_platform", "(", "mock_def", ")", ":", "assert", "scripts", ".", "get_default_config_dir", "(", ")", "==", "\"/default\"", "assert", "scripts", ".", "extract_config_dir", "(", ")", "==", "\"/default\"", "assert", "scripts", ".", "extract_confi...
[ 7, 0 ]
[ 13, 65 ]
python
da
['no', 'da', 'it']
False
OpenWeatherMapConfigFlow.async_get_options_flow
(config_entry)
Get the options flow for this handler.
Get the options flow for this handler.
def async_get_options_flow(config_entry): """Get the options flow for this handler.""" return OpenWeatherMapOptionsFlow(config_entry)
[ "def", "async_get_options_flow", "(", "config_entry", ")", ":", "return", "OpenWeatherMapOptionsFlow", "(", "config_entry", ")" ]
[ 36, 4 ]
[ 38, 54 ]
python
en
['en', 'en', 'en']
True
OpenWeatherMapConfigFlow.async_step_user
(self, user_input=None)
Handle a flow initialized by the user.
Handle a flow initialized by the user.
async def async_step_user(self, user_input=None): """Handle a flow initialized by the user.""" errors = {} if user_input is not None: latitude = user_input[CONF_LATITUDE] longitude = user_input[CONF_LONGITUDE] await self.async_set_unique_id(f"{latitude}-{lon...
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "latitude", "=", "user_input", "[", "CONF_LATITUDE", "]", "longitude", "=", "user_input", "[", ...
[ 40, 4 ]
[ 86, 86 ]
python
en
['en', 'en', 'en']
True
OpenWeatherMapOptionsFlow.__init__
(self, config_entry)
Initialize options flow.
Initialize options flow.
def __init__(self, config_entry): """Initialize options flow.""" self.config_entry = config_entry
[ "def", "__init__", "(", "self", ",", "config_entry", ")", ":", "self", ".", "config_entry", "=", "config_entry" ]
[ 92, 4 ]
[ 94, 40 ]
python
en
['en', 'en', 'en']
True
OpenWeatherMapOptionsFlow.async_step_init
(self, user_input=None)
Manage the options.
Manage the options.
async def async_step_init(self, user_input=None): """Manage the options.""" if user_input is not None: return self.async_create_entry(title="", data=user_input) return self.async_show_form( step_id="init", data_schema=self._get_options_schema(), )
[ "async", "def", "async_step_init", "(", "self", ",", "user_input", "=", "None", ")", ":", "if", "user_input", "is", "not", "None", ":", "return", "self", ".", "async_create_entry", "(", "title", "=", "\"\"", ",", "data", "=", "user_input", ")", "return", ...
[ 96, 4 ]
[ 104, 9 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
( hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities )
Set up discovered switches.
Set up discovered switches.
async def async_setup_entry( hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities ) -> None: """Set up discovered switches.""" devs = [] for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]: devs.append(HassAqualinkThermostat(dev)) async_add_entities(devs, True)
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistantType", ",", "config_entry", ":", "ConfigEntry", ",", "async_add_entities", ")", "->", "None", ":", "devs", "=", "[", "]", "for", "dev", "in", "hass", ".", "data", "[", "AQUALINK_DOMAIN", "]...
[ 31, 0 ]
[ 38, 34 ]
python
en
['en', 'en', 'en']
True
HassAqualinkThermostat.name
(self)
Return the name of the thermostat.
Return the name of the thermostat.
def name(self) -> str: """Return the name of the thermostat.""" return self.dev.label.split(" ")[0]
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "self", ".", "dev", ".", "label", ".", "split", "(", "\" \"", ")", "[", "0", "]" ]
[ 45, 4 ]
[ 47, 43 ]
python
en
['en', 'en', 'en']
True
HassAqualinkThermostat.supported_features
(self)
Return the list of supported features.
Return the list of supported features.
def supported_features(self) -> int: """Return the list of supported features.""" return SUPPORT_TARGET_TEMPERATURE
[ "def", "supported_features", "(", "self", ")", "->", "int", ":", "return", "SUPPORT_TARGET_TEMPERATURE" ]
[ 50, 4 ]
[ 52, 41 ]
python
en
['en', 'en', 'en']
True
HassAqualinkThermostat.hvac_modes
(self)
Return the list of supported HVAC modes.
Return the list of supported HVAC modes.
def hvac_modes(self) -> List[str]: """Return the list of supported HVAC modes.""" return CLIMATE_SUPPORTED_MODES
[ "def", "hvac_modes", "(", "self", ")", "->", "List", "[", "str", "]", ":", "return", "CLIMATE_SUPPORTED_MODES" ]
[ 55, 4 ]
[ 57, 38 ]
python
en
['en', 'en', 'en']
True
HassAqualinkThermostat.pump
(self)
Return the pump device for the current thermostat.
Return the pump device for the current thermostat.
def pump(self) -> AqualinkPump: """Return the pump device for the current thermostat.""" pump = f"{self.name.lower()}_pump" return self.dev.system.devices[pump]
[ "def", "pump", "(", "self", ")", "->", "AqualinkPump", ":", "pump", "=", "f\"{self.name.lower()}_pump\"", "return", "self", ".", "dev", ".", "system", ".", "devices", "[", "pump", "]" ]
[ 60, 4 ]
[ 63, 44 ]
python
en
['en', 'en', 'en']
True
HassAqualinkThermostat.hvac_mode
(self)
Return the current HVAC mode.
Return the current HVAC mode.
def hvac_mode(self) -> str: """Return the current HVAC mode.""" state = AqualinkState(self.heater.state) if state == AqualinkState.ON: return HVAC_MODE_HEAT return HVAC_MODE_OFF
[ "def", "hvac_mode", "(", "self", ")", "->", "str", ":", "state", "=", "AqualinkState", "(", "self", ".", "heater", ".", "state", ")", "if", "state", "==", "AqualinkState", ".", "ON", ":", "return", "HVAC_MODE_HEAT", "return", "HVAC_MODE_OFF" ]
[ 66, 4 ]
[ 71, 28 ]
python
en
['en', 'co', 'en']
True
HassAqualinkThermostat.async_set_hvac_mode
(self, hvac_mode: str)
Turn the underlying heater switch on or off.
Turn the underlying heater switch on or off.
async def async_set_hvac_mode(self, hvac_mode: str) -> None: """Turn the underlying heater switch on or off.""" if hvac_mode == HVAC_MODE_HEAT: await self.heater.turn_on() elif hvac_mode == HVAC_MODE_OFF: await self.heater.turn_off() else: _LOGGER.warn...
[ "async", "def", "async_set_hvac_mode", "(", "self", ",", "hvac_mode", ":", "str", ")", "->", "None", ":", "if", "hvac_mode", "==", "HVAC_MODE_HEAT", ":", "await", "self", ".", "heater", ".", "turn_on", "(", ")", "elif", "hvac_mode", "==", "HVAC_MODE_OFF", ...
[ 74, 4 ]
[ 81, 68 ]
python
en
['en', 'en', 'en']
True
HassAqualinkThermostat.temperature_unit
(self)
Return the unit of measurement.
Return the unit of measurement.
def temperature_unit(self) -> str: """Return the unit of measurement.""" if self.dev.system.temp_unit == "F": return TEMP_FAHRENHEIT return TEMP_CELSIUS
[ "def", "temperature_unit", "(", "self", ")", "->", "str", ":", "if", "self", ".", "dev", ".", "system", ".", "temp_unit", "==", "\"F\"", ":", "return", "TEMP_FAHRENHEIT", "return", "TEMP_CELSIUS" ]
[ 84, 4 ]
[ 88, 27 ]
python
en
['en', 'la', 'en']
True
HassAqualinkThermostat.min_temp
(self)
Return the minimum temperature supported by the thermostat.
Return the minimum temperature supported by the thermostat.
def min_temp(self) -> int: """Return the minimum temperature supported by the thermostat.""" if self.temperature_unit == TEMP_FAHRENHEIT: return AQUALINK_TEMP_FAHRENHEIT_LOW return AQUALINK_TEMP_CELSIUS_LOW
[ "def", "min_temp", "(", "self", ")", "->", "int", ":", "if", "self", ".", "temperature_unit", "==", "TEMP_FAHRENHEIT", ":", "return", "AQUALINK_TEMP_FAHRENHEIT_LOW", "return", "AQUALINK_TEMP_CELSIUS_LOW" ]
[ 91, 4 ]
[ 95, 40 ]
python
en
['en', 'en', 'en']
True