Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
test_subscribe
(hass, mqtt_mock)
Test the subscription.
Test the subscription.
async def test_subscribe(hass, mqtt_mock): """Test the subscription.""" sub_topic = "foo" assert await add_eventstream(hass, sub_topic=sub_topic) await hass.async_block_till_done() # Verify that the this entity was subscribed to the topic mqtt_mock.async_subscribe.assert_called_with(sub_topic, ...
[ "async", "def", "test_subscribe", "(", "hass", ",", "mqtt_mock", ")", ":", "sub_topic", "=", "\"foo\"", "assert", "await", "add_eventstream", "(", "hass", ",", "sub_topic", "=", "sub_topic", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "# Veri...
[ 49, 0 ]
[ 56, 72 ]
python
en
['en', 'en', 'en']
True
test_state_changed_event_sends_message
(hass, mqtt_mock)
Test the sending of a new message if event changed.
Test the sending of a new message if event changed.
async def test_state_changed_event_sends_message(hass, mqtt_mock): """Test the sending of a new message if event changed.""" now = dt_util.as_utc(dt_util.now()) e_id = "fake.entity" pub_topic = "bar" with patch( ("homeassistant.core.dt_util.utcnow"), return_value=now, ): ...
[ "async", "def", "test_state_changed_event_sends_message", "(", "hass", ",", "mqtt_mock", ")", ":", "now", "=", "dt_util", ".", "as_utc", "(", "dt_util", ".", "now", "(", ")", ")", "e_id", "=", "\"fake.entity\"", "pub_topic", "=", "\"bar\"", "with", "patch", ...
[ 59, 0 ]
[ 103, 26 ]
python
en
['en', 'en', 'en']
True
test_time_event_does_not_send_message
(hass, mqtt_mock)
Test the sending of a new message if time event.
Test the sending of a new message if time event.
async def test_time_event_does_not_send_message(hass, mqtt_mock): """Test the sending of a new message if time event.""" assert await add_eventstream(hass, pub_topic="bar") await hass.async_block_till_done() # Reset the mock because it will have already gotten calls for the # mqtt_eventstream state...
[ "async", "def", "test_time_event_does_not_send_message", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "add_eventstream", "(", "hass", ",", "pub_topic", "=", "\"bar\"", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "# Reset the mock bec...
[ 106, 0 ]
[ 116, 45 ]
python
en
['en', 'en', 'en']
True
test_receiving_remote_event_fires_hass_event
(hass, mqtt_mock)
Test the receiving of the remotely fired event.
Test the receiving of the remotely fired event.
async def test_receiving_remote_event_fires_hass_event(hass, mqtt_mock): """Test the receiving of the remotely fired event.""" sub_topic = "foo" assert await add_eventstream(hass, sub_topic=sub_topic) await hass.async_block_till_done() calls = [] @callback def listener(_): calls.ap...
[ "async", "def", "test_receiving_remote_event_fires_hass_event", "(", "hass", ",", "mqtt_mock", ")", ":", "sub_topic", "=", "\"foo\"", "assert", "await", "add_eventstream", "(", "hass", ",", "sub_topic", "=", "sub_topic", ")", "await", "hass", ".", "async_block_till_...
[ 119, 0 ]
[ 140, 26 ]
python
en
['en', 'en', 'en']
True
test_ignored_event_doesnt_send_over_stream
(hass, mqtt_mock)
Test the ignoring of sending events if defined.
Test the ignoring of sending events if defined.
async def test_ignored_event_doesnt_send_over_stream(hass, mqtt_mock): """Test the ignoring of sending events if defined.""" assert await add_eventstream(hass, pub_topic="bar", ignore_event=["state_changed"]) await hass.async_block_till_done() e_id = "entity.test_id" event = {} event["event_typ...
[ "async", "def", "test_ignored_event_doesnt_send_over_stream", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "add_eventstream", "(", "hass", ",", "pub_topic", "=", "\"bar\"", ",", "ignore_event", "=", "[", "\"state_changed\"", "]", ")", "await", "hass...
[ 143, 0 ]
[ 162, 45 ]
python
en
['en', 'en', 'en']
True
test_wrong_ignored_event_sends_over_stream
(hass, mqtt_mock)
Test the ignoring of sending events if defined.
Test the ignoring of sending events if defined.
async def test_wrong_ignored_event_sends_over_stream(hass, mqtt_mock): """Test the ignoring of sending events if defined.""" assert await add_eventstream(hass, pub_topic="bar", ignore_event=["statee_changed"]) await hass.async_block_till_done() e_id = "entity.test_id" event = {} event["event_ty...
[ "async", "def", "test_wrong_ignored_event_sends_over_stream", "(", "hass", ",", "mqtt_mock", ")", ":", "assert", "await", "add_eventstream", "(", "hass", ",", "pub_topic", "=", "\"bar\"", ",", "ignore_event", "=", "[", "\"statee_changed\"", "]", ")", "await", "has...
[ 165, 0 ]
[ 185, 41 ]
python
en
['en', 'en', 'en']
True
validate_input
(hass: core.HomeAssistant, data)
Validate the user input allows us to connect.
Validate the user input allows us to connect.
async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect.""" auth = Auth(f"HomeAssistant/{const.__version__}") try: token = await hass.async_add_executor_job( auth.fetch_token, data["username"], data["password"], ...
[ "async", "def", "validate_input", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "data", ")", ":", "auth", "=", "Auth", "(", "f\"HomeAssistant/{const.__version__}\"", ")", "try", ":", "token", "=", "await", "hass", ".", "async_add_executor_job", "(", "au...
[ 14, 0 ]
[ 31, 16 ]
python
en
['en', 'en', 'en']
True
RingConfigFlow.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: token = await validate_input(self.hass, user_input) await self.async_set_unique_id(user_input["username"]) ret...
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "try", ":", "token", "=", "await", "validate_input", "(", "self", ".", "hass", ",", "user_i...
[ 42, 4 ]
[ 69, 9 ]
python
en
['en', 'en', 'en']
True
RingConfigFlow.async_step_2fa
(self, user_input=None)
Handle 2fa step.
Handle 2fa step.
async def async_step_2fa(self, user_input=None): """Handle 2fa step.""" if user_input: return await self.async_step_user({**self.user_pass, **user_input}) return self.async_show_form( step_id="2fa", data_schema=vol.Schema({"2fa": str}), )
[ "async", "def", "async_step_2fa", "(", "self", ",", "user_input", "=", "None", ")", ":", "if", "user_input", ":", "return", "await", "self", ".", "async_step_user", "(", "{", "*", "*", "self", ".", "user_pass", ",", "*", "*", "user_input", "}", ")", "r...
[ 71, 4 ]
[ 79, 9 ]
python
en
['it', 'sm', 'en']
False
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up myStrom Binary Sensor.
Set up myStrom Binary Sensor.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up myStrom Binary Sensor.""" hass.http.register_view(MyStromView(async_add_entities)) return True
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "hass", ".", "http", ".", "register_view", "(", "MyStromView", "(", "async_add_entities", ")", ")", "return", "True" ]
[ 11, 0 ]
[ 15, 15 ]
python
en
['en', 'hr', 'en']
True
MyStromView.__init__
(self, add_entities)
Initialize the myStrom URL endpoint.
Initialize the myStrom URL endpoint.
def __init__(self, add_entities): """Initialize the myStrom URL endpoint.""" self.buttons = {} self.add_entities = add_entities
[ "def", "__init__", "(", "self", ",", "add_entities", ")", ":", "self", ".", "buttons", "=", "{", "}", "self", ".", "add_entities", "=", "add_entities" ]
[ 25, 4 ]
[ 28, 40 ]
python
en
['en', 'en', 'en']
True
MyStromView.get
(self, request)
Handle the GET request received from a myStrom button.
Handle the GET request received from a myStrom button.
async def get(self, request): """Handle the GET request received from a myStrom button.""" res = await self._handle(request.app["hass"], request.query) return res
[ "async", "def", "get", "(", "self", ",", "request", ")", ":", "res", "=", "await", "self", ".", "_handle", "(", "request", ".", "app", "[", "\"hass\"", "]", ",", "request", ".", "query", ")", "return", "res" ]
[ 30, 4 ]
[ 33, 18 ]
python
en
['en', 'en', 'en']
True
MyStromView._handle
(self, hass, data)
Handle requests to the myStrom endpoint.
Handle requests to the myStrom endpoint.
async def _handle(self, hass, data): """Handle requests to the myStrom endpoint.""" button_action = next( (parameter for parameter in data if parameter in self.supported_actions), None, ) if button_action is None: _LOGGER.error("Received unidentified ...
[ "async", "def", "_handle", "(", "self", ",", "hass", ",", "data", ")", ":", "button_action", "=", "next", "(", "(", "parameter", "for", "parameter", "in", "data", "if", "parameter", "in", "self", ".", "supported_actions", ")", ",", "None", ",", ")", "i...
[ 35, 4 ]
[ 58, 62 ]
python
en
['en', 'en', 'en']
True
MyStromBinarySensor.__init__
(self, button_id)
Initialize the myStrom Binary sensor.
Initialize the myStrom Binary sensor.
def __init__(self, button_id): """Initialize the myStrom Binary sensor.""" self._button_id = button_id self._state = None
[ "def", "__init__", "(", "self", ",", "button_id", ")", ":", "self", ".", "_button_id", "=", "button_id", "self", ".", "_state", "=", "None" ]
[ 64, 4 ]
[ 67, 26 ]
python
en
['en', 'pl', 'en']
True
MyStromBinarySensor.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return self._button_id
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_button_id" ]
[ 70, 4 ]
[ 72, 30 ]
python
en
['en', 'mi', 'en']
True
MyStromBinarySensor.should_poll
(self)
No polling needed.
No polling needed.
def should_poll(self): """No polling needed.""" return False
[ "def", "should_poll", "(", "self", ")", ":", "return", "False" ]
[ 75, 4 ]
[ 77, 20 ]
python
en
['en', 'en', 'en']
True
MyStromBinarySensor.is_on
(self)
Return true if the binary sensor is on.
Return true if the binary sensor is on.
def is_on(self): """Return true if the binary sensor is on.""" return self._state
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "_state" ]
[ 80, 4 ]
[ 82, 26 ]
python
en
['en', 'fy', 'en']
True
MyStromBinarySensor.async_on_update
(self, value)
Receive an update.
Receive an update.
def async_on_update(self, value): """Receive an update.""" self._state = value self.async_write_ha_state()
[ "def", "async_on_update", "(", "self", ",", "value", ")", ":", "self", ".", "_state", "=", "value", "self", ".", "async_write_ha_state", "(", ")" ]
[ 85, 4 ]
[ 88, 35 ]
python
en
['en', 'lb', 'en']
True
get_random_proxy
()
get random proxy from proxypool :return: proxy
get random proxy from proxypool :return: proxy
def get_random_proxy(): """ get random proxy from proxypool :return: proxy """ return requests.get(proxypool_url).text.strip()
[ "def", "get_random_proxy", "(", ")", ":", "return", "requests", ".", "get", "(", "proxypool_url", ")", ".", "text", ".", "strip", "(", ")" ]
[ 7, 0 ]
[ 12, 51 ]
python
en
['en', 'error', 'th']
False
crawl
(url, proxy)
use proxy to crawl page :param url: page url :param proxy: proxy, such as 8.8.8.8:8888 :return: html
use proxy to crawl page :param url: page url :param proxy: proxy, such as 8.8.8.8:8888 :return: html
def crawl(url, proxy): """ use proxy to crawl page :param url: page url :param proxy: proxy, such as 8.8.8.8:8888 :return: html """ proxies = {'http': 'http://' + proxy} return requests.get(url, proxies=proxies).text
[ "def", "crawl", "(", "url", ",", "proxy", ")", ":", "proxies", "=", "{", "'http'", ":", "'http://'", "+", "proxy", "}", "return", "requests", ".", "get", "(", "url", ",", "proxies", "=", "proxies", ")", ".", "text" ]
[ 15, 0 ]
[ 23, 50 ]
python
en
['en', 'error', 'th']
False
main
()
main method, entry point :return: none
main method, entry point :return: none
def main(): """ main method, entry point :return: none """ proxy = get_random_proxy() print('get random proxy', proxy) html = crawl(target_url, proxy) print(html)
[ "def", "main", "(", ")", ":", "proxy", "=", "get_random_proxy", "(", ")", "print", "(", "'get random proxy'", ",", "proxy", ")", "html", "=", "crawl", "(", "target_url", ",", "proxy", ")", "print", "(", "html", ")" ]
[ 26, 0 ]
[ 34, 15 ]
python
en
['en', 'error', 'th']
False
test_reproducing_states
(hass, caplog)
Test reproducing Input datetime states.
Test reproducing Input datetime states.
async def test_reproducing_states(hass, caplog): """Test reproducing Input datetime states.""" hass.states.async_set( "input_datetime.entity_datetime", "2010-10-10 01:20:00", {"has_date": True, "has_time": True}, ) hass.states.async_set( "input_datetime.entity_time", "01:...
[ "async", "def", "test_reproducing_states", "(", "hass", ",", "caplog", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"input_datetime.entity_datetime\"", ",", "\"2010-10-10 01:20:00\"", ",", "{", "\"has_date\"", ":", "True", ",", "\"has_time\"", ":", "T...
[ 6, 0 ]
[ 74, 37 ]
python
en
['fr', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the platform for a Skybell device.
Set up the platform for a Skybell device.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the platform for a Skybell device.""" cond = config[CONF_MONITORED_CONDITIONS] names = {} names[IMAGE_ACTIVITY] = config.get(CONF_ACTIVITY_NAME) names[IMAGE_AVATAR] = config.get(CONF_AVATAR_NAME) skybell = hass.data.g...
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "cond", "=", "config", "[", "CONF_MONITORED_CONDITIONS", "]", "names", "=", "{", "}", "names", "[", "IMAGE_ACTIVITY", "]", "=", "config", ...
[ 34, 0 ]
[ 47, 31 ]
python
en
['en', 'en', 'en']
True
SkybellCamera.__init__
(self, device, camera_type, name=None)
Initialize a camera for a Skybell device.
Initialize a camera for a Skybell device.
def __init__(self, device, camera_type, name=None): """Initialize a camera for a Skybell device.""" self._type = camera_type SkybellDevice.__init__(self, device) Camera.__init__(self) if name is not None: self._name = f"{self._device.name} {name}" else: ...
[ "def", "__init__", "(", "self", ",", "device", ",", "camera_type", ",", "name", "=", "None", ")", ":", "self", ".", "_type", "=", "camera_type", "SkybellDevice", ".", "__init__", "(", "self", ",", "device", ")", "Camera", ".", "__init__", "(", "self", ...
[ 53, 4 ]
[ 63, 29 ]
python
en
['ca', 'en', 'en']
True
SkybellCamera.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 66, 4 ]
[ 68, 25 ]
python
en
['en', 'mi', 'en']
True
SkybellCamera.image_url
(self)
Get the camera image url based on type.
Get the camera image url based on type.
def image_url(self): """Get the camera image url based on type.""" if self._type == IMAGE_ACTIVITY: return self._device.activity_image return self._device.image
[ "def", "image_url", "(", "self", ")", ":", "if", "self", ".", "_type", "==", "IMAGE_ACTIVITY", ":", "return", "self", ".", "_device", ".", "activity_image", "return", "self", ".", "_device", ".", "image" ]
[ 71, 4 ]
[ 75, 33 ]
python
en
['en', 'en', 'en']
True
SkybellCamera.camera_image
(self)
Get the latest camera image.
Get the latest camera image.
def camera_image(self): """Get the latest camera image.""" super().update() if self._url != self.image_url: self._url = self.image_url try: self._response = requests.get(self._url, stream=True, timeout=10) except requests.HTTPError as err: ...
[ "def", "camera_image", "(", "self", ")", ":", "super", "(", ")", ".", "update", "(", ")", "if", "self", ".", "_url", "!=", "self", ".", "image_url", ":", "self", ".", "_url", "=", "self", ".", "image_url", "try", ":", "self", ".", "_response", "=",...
[ 77, 4 ]
[ 93, 37 ]
python
en
['en', 'en', 'en']
True
maxmin
(time, swe)
return the maximum, the minimum and the date of each one of a series of values :param time: time serie :param swe: snow water equivalent series :return:
return the maximum, the minimum and the date of each one of a series of values
def maxmin(time, swe): """ return the maximum, the minimum and the date of each one of a series of values :param time: time serie :param swe: snow water equivalent series :return: """ assert time.ndim == 1 and swe.ndim == 1 and len(time) == len(swe) try : maximum = np.max(swe) ...
[ "def", "maxmin", "(", "time", ",", "swe", ")", ":", "assert", "time", ".", "ndim", "==", "1", "and", "swe", ".", "ndim", "==", "1", "and", "len", "(", "time", ")", "==", "len", "(", "swe", ")", "try", ":", "maximum", "=", "np", ".", "max", "(...
[ 2, 0 ]
[ 25, 47 ]
python
en
['en', 'error', 'th']
False
amount_snowmelt
(maximum, time, swe)
return the amount of the snow melt knowing the maximum of the swe :param maximum: maximum of snow water equivalent :param time: time serie :param swe: snow water equivalent series :return:
return the amount of the snow melt knowing the maximum of the swe
def amount_snowmelt(maximum, time, swe): """ return the amount of the snow melt knowing the maximum of the swe :param maximum: maximum of snow water equivalent :param time: time serie :param swe: snow water equivalent series :return: """ assert time.ndim == 1 and swe.n...
[ "def", "amount_snowmelt", "(", "maximum", ",", "time", ",", "swe", ")", ":", "assert", "time", ".", "ndim", "==", "1", "and", "swe", ".", "ndim", "==", "1", "and", "len", "(", "time", ")", "==", "len", "(", "swe", ")", "sum", "=", "0", "index_of_...
[ 27, 0 ]
[ 42, 14 ]
python
en
['en', 'error', 'th']
False
amount_precipitation
(maximum,swe,cum_precip)
return the amount of the rain fell from the beginning of the year to the maximum of snow :param cum_sum: cumulated precipitation of the rain :return:
return the amount of the rain fell from the beginning of the year to the maximum of snow
def amount_precipitation(maximum,swe,cum_precip): """ return the amount of the rain fell from the beginning of the year to the maximum of snow :param cum_sum: cumulated precipitation of the rain :return: """ index_max = np.where(swe == maximum)[0][0] try : pr...
[ "def", "amount_precipitation", "(", "maximum", ",", "swe", ",", "cum_precip", ")", ":", "index_max", "=", "np", ".", "where", "(", "swe", "==", "maximum", ")", "[", "0", "]", "[", "0", "]", "try", ":", "precipitation", "=", "cum_precip", "[", "index_ma...
[ 44, 0 ]
[ 56, 24 ]
python
en
['en', 'error', 'th']
False
test_google_entity_sync_serialize_with_local_sdk
(hass)
Test sync serialize attributes of a GoogleEntity.
Test sync serialize attributes of a GoogleEntity.
async def test_google_entity_sync_serialize_with_local_sdk(hass): """Test sync serialize attributes of a GoogleEntity.""" hass.states.async_set("light.ceiling_lights", "off") hass.config.api = Mock(port=1234, use_ssl=True) await async_process_ha_core_config( hass, {"external_url": "https...
[ "async", "def", "test_google_entity_sync_serialize_with_local_sdk", "(", "hass", ")", ":", "hass", ".", "states", ".", "async_set", "(", "\"light.ceiling_lights\"", ",", "\"off\"", ")", "hass", ".", "config", ".", "api", "=", "Mock", "(", "port", "=", "1234", ...
[ 25, 0 ]
[ 67, 49 ]
python
en
['en', 'en', 'en']
True
test_config_local_sdk
(hass, hass_client)
Test the local SDK.
Test the local SDK.
async def test_config_local_sdk(hass, hass_client): """Test the local SDK.""" command_events = async_capture_events(hass, EVENT_COMMAND_RECEIVED) turn_on_calls = async_mock_service(hass, "light", "turn_on") hass.states.async_set("light.ceiling_lights", "off") assert await async_setup_component(hass...
[ "async", "def", "test_config_local_sdk", "(", "hass", ",", "hass_client", ")", ":", "command_events", "=", "async_capture_events", "(", "hass", ",", "EVENT_COMMAND_RECEIVED", ")", "turn_on_calls", "=", "async_mock_service", "(", "hass", ",", "\"light\"", ",", "\"tur...
[ 70, 0 ]
[ 129, 35 ]
python
en
['en', 'en', 'en']
True
test_config_local_sdk_if_disabled
(hass, hass_client)
Test the local SDK.
Test the local SDK.
async def test_config_local_sdk_if_disabled(hass, hass_client): """Test the local SDK.""" assert await async_setup_component(hass, "webhook", {}) config = MockConfig( hass=hass, local_sdk_webhook_id="mock-webhook-id", local_sdk_user_id="mock-user-id", enabled=False, ) ...
[ "async", "def", "test_config_local_sdk_if_disabled", "(", "hass", ",", "hass_client", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "\"webhook\"", ",", "{", "}", ")", "config", "=", "MockConfig", "(", "hass", "=", "hass", ",", "local_...
[ 132, 0 ]
[ 162, 35 ]
python
en
['en', 'en', 'en']
True
test_agent_user_id_storage
(hass, hass_storage)
Test a disconnect message.
Test a disconnect message.
async def test_agent_user_id_storage(hass, hass_storage): """Test a disconnect message.""" hass_storage["google_assistant"] = { "version": 1, "key": "google_assistant", "data": {"agent_user_ids": {"agent_1": {}}}, } store = helpers.GoogleConfigStore(hass) await store.async_...
[ "async", "def", "test_agent_user_id_storage", "(", "hass", ",", "hass_storage", ")", ":", "hass_storage", "[", "\"google_assistant\"", "]", "=", "{", "\"version\"", ":", "1", ",", "\"key\"", ":", "\"google_assistant\"", ",", "\"data\"", ":", "{", "\"agent_user_ids...
[ 165, 0 ]
[ 197, 65 ]
python
en
['it', 'en', 'en']
True
test_agent_user_id_connect
()
Test the connection and disconnection of users.
Test the connection and disconnection of users.
async def test_agent_user_id_connect(): """Test the connection and disconnection of users.""" config = MockConfig() store = config._store await config.async_connect_agent_user("agent_2") assert store.add_agent_user_id.call_args == call("agent_2") await config.async_connect_agent_user("agent_1"...
[ "async", "def", "test_agent_user_id_connect", "(", ")", ":", "config", "=", "MockConfig", "(", ")", "store", "=", "config", ".", "_store", "await", "config", ".", "async_connect_agent_user", "(", "\"agent_2\"", ")", "assert", "store", ".", "add_agent_user_id", "...
[ 200, 0 ]
[ 215, 63 ]
python
en
['en', 'en', 'en']
True
test_report_state_all
(agents)
Test a disconnect message.
Test a disconnect message.
async def test_report_state_all(agents): """Test a disconnect message.""" config = MockConfig(agent_user_ids=agents) data = {} with patch.object(config, "async_report_state") as mock: await config.async_report_state_all(data) assert sorted(mock.mock_calls) == sorted( [call(da...
[ "async", "def", "test_report_state_all", "(", "agents", ")", ":", "config", "=", "MockConfig", "(", "agent_user_ids", "=", "agents", ")", "data", "=", "{", "}", "with", "patch", ".", "object", "(", "config", ",", "\"async_report_state\"", ")", "as", "mock", ...
[ 219, 0 ]
[ 227, 9 ]
python
en
['it', 'en', 'en']
True
test_sync_entities_all
(agents, result)
Test sync entities .
Test sync entities .
async def test_sync_entities_all(agents, result): """Test sync entities .""" config = MockConfig(agent_user_ids=set(agents.keys())) with patch.object( config, "async_sync_entities", side_effect=lambda agent_user_id: agents[agent_user_id], ) as mock: res = await config.asy...
[ "async", "def", "test_sync_entities_all", "(", "agents", ",", "result", ")", ":", "config", "=", "MockConfig", "(", "agent_user_ids", "=", "set", "(", "agents", ".", "keys", "(", ")", ")", ")", "with", "patch", ".", "object", "(", "config", ",", "\"async...
[ 234, 0 ]
[ 244, 28 ]
python
en
['fr', 'en', 'it']
False
test_supported_features_string
(caplog)
Test bad supported features.
Test bad supported features.
def test_supported_features_string(caplog): """Test bad supported features.""" entity = helpers.GoogleEntity( None, None, State("test.entity_id", "on", {"supported_features": "invalid"}) ) assert entity.is_supported() is False assert "Entity test.entity_id contains invalid supported_features...
[ "def", "test_supported_features_string", "(", "caplog", ")", ":", "entity", "=", "helpers", ".", "GoogleEntity", "(", "None", ",", "None", ",", "State", "(", "\"test.entity_id\"", ",", "\"on\"", ",", "{", "\"supported_features\"", ":", "\"invalid\"", "}", ")", ...
[ 247, 0 ]
[ 253, 84 ]
python
en
['en', 'en', 'en']
True
test_component_unload_config_entry
(hass, config_entry)
Test that loading and unloading of a config entry works.
Test that loading and unloading of a config entry works.
async def test_component_unload_config_entry(hass, config_entry): """Test that loading and unloading of a config entry works.""" config_entry.add_to_hass(hass) with patch( "aio_geojson_geonetnz_quakes.GeonetnzQuakesFeedManager.update" ) as mock_feed_manager_update: # Load config entry. ...
[ "async", "def", "test_component_unload_config_entry", "(", "hass", ",", "config_entry", ")", ":", "config_entry", ".", "add_to_hass", "(", "hass", ")", "with", "patch", "(", "\"aio_geojson_geonetnz_quakes.GeonetnzQuakesFeedManager.update\"", ")", "as", "mock_feed_manager_up...
[ 6, 0 ]
[ 20, 73 ]
python
en
['en', 'en', 'en']
True
TileFlowHandler.__init__
(self)
Initialize the config flow.
Initialize the config flow.
def __init__(self): """Initialize the config flow.""" self.data_schema = vol.Schema( {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str} )
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "data_schema", "=", "vol", ".", "Schema", "(", "{", "vol", ".", "Required", "(", "CONF_USERNAME", ")", ":", "str", ",", "vol", ".", "Required", "(", "CONF_PASSWORD", ")", ":", "str", "}", ")" ]
[ 18, 4 ]
[ 22, 9 ]
python
en
['en', 'en', 'en']
True
TileFlowHandler._show_form
(self, errors=None)
Show the form to the user.
Show the form to the user.
async def _show_form(self, errors=None): """Show the form to the user.""" return self.async_show_form( step_id="user", data_schema=self.data_schema, errors=errors or {} )
[ "async", "def", "_show_form", "(", "self", ",", "errors", "=", "None", ")", ":", "return", "self", ".", "async_show_form", "(", "step_id", "=", "\"user\"", ",", "data_schema", "=", "self", ".", "data_schema", ",", "errors", "=", "errors", "or", "{", "}",...
[ 24, 4 ]
[ 28, 9 ]
python
en
['en', 'en', 'en']
True
TileFlowHandler.async_step_import
(self, import_config)
Import a config entry from configuration.yaml.
Import a config entry from configuration.yaml.
async def async_step_import(self, import_config): """Import a config entry from configuration.yaml.""" return await self.async_step_user(import_config)
[ "async", "def", "async_step_import", "(", "self", ",", "import_config", ")", ":", "return", "await", "self", ".", "async_step_user", "(", "import_config", ")" ]
[ 30, 4 ]
[ 32, 56 ]
python
en
['en', 'en', 'en']
True
TileFlowHandler.async_step_user
(self, user_input=None)
Handle the start of the config flow.
Handle the start of the config flow.
async def async_step_user(self, user_input=None): """Handle the start of the config flow.""" if not user_input: return await self._show_form() await self.async_set_unique_id(user_input[CONF_USERNAME]) self._abort_if_unique_id_configured() session = aiohttp_client.as...
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "if", "not", "user_input", ":", "return", "await", "self", ".", "_show_form", "(", ")", "await", "self", ".", "async_set_unique_id", "(", "user_input", "[", "CONF_USERN...
[ 34, 4 ]
[ 51, 88 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up a Point's sensors based on a config entry.
Set up a Point's sensors based on a config entry.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up a Point's sensors based on a config entry.""" async def async_discover_sensor(device_id): """Discover and add a discovered sensor.""" client = hass.data[POINT_DOMAIN][config_entry.entry_id] async_add_entities...
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "async", "def", "async_discover_sensor", "(", "device_id", ")", ":", "\"\"\"Discover and add a discovered sensor.\"\"\"", "client", "=", "hass", ".", "data", "[...
[ 30, 0 ]
[ 46, 5 ]
python
en
['en', 'en', 'en']
True
MinutPointSensor.__init__
(self, point_client, device_id, device_class)
Initialize the sensor.
Initialize the sensor.
def __init__(self, point_client, device_id, device_class): """Initialize the sensor.""" super().__init__(point_client, device_id, device_class) self._device_prop = SENSOR_TYPES[device_class]
[ "def", "__init__", "(", "self", ",", "point_client", ",", "device_id", ",", "device_class", ")", ":", "super", "(", ")", ".", "__init__", "(", "point_client", ",", "device_id", ",", "device_class", ")", "self", ".", "_device_prop", "=", "SENSOR_TYPES", "[", ...
[ 52, 4 ]
[ 55, 54 ]
python
en
['en', 'en', 'en']
True
MinutPointSensor._update_callback
(self)
Update the value of the sensor.
Update the value of the sensor.
async def _update_callback(self): """Update the value of the sensor.""" _LOGGER.debug("Update sensor value for %s", self) if self.is_updated: self._value = await self.device.sensor(self.device_class) self._updated = parse_datetime(self.device.last_update) self.asy...
[ "async", "def", "_update_callback", "(", "self", ")", ":", "_LOGGER", ".", "debug", "(", "\"Update sensor value for %s\"", ",", "self", ")", "if", "self", ".", "is_updated", ":", "self", ".", "_value", "=", "await", "self", ".", "device", ".", "sensor", "(...
[ 57, 4 ]
[ 63, 35 ]
python
en
['en', 'en', 'en']
True
MinutPointSensor.icon
(self)
Return the icon representation.
Return the icon representation.
def icon(self): """Return the icon representation.""" return self._device_prop[0]
[ "def", "icon", "(", "self", ")", ":", "return", "self", ".", "_device_prop", "[", "0", "]" ]
[ 66, 4 ]
[ 68, 35 ]
python
en
['en', 'it', 'en']
True
MinutPointSensor.state
(self)
Return the state of the sensor.
Return the state of the sensor.
def state(self): """Return the state of the sensor.""" if self.value is None: return None return round(self.value, self._device_prop[1])
[ "def", "state", "(", "self", ")", ":", "if", "self", ".", "value", "is", "None", ":", "return", "None", "return", "round", "(", "self", ".", "value", ",", "self", ".", "_device_prop", "[", "1", "]", ")" ]
[ 71, 4 ]
[ 75, 54 ]
python
en
['en', 'en', 'en']
True
MinutPointSensor.unit_of_measurement
(self)
Return the unit of measurement.
Return the unit of measurement.
def unit_of_measurement(self): """Return the unit of measurement.""" return self._device_prop[2]
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "self", ".", "_device_prop", "[", "2", "]" ]
[ 78, 4 ]
[ 80, 35 ]
python
en
['en', 'la', 'en']
True
get_file_revision
(revision, file_path)
Fetches the requested Git revision of the given Chromium file.
Fetches the requested Git revision of the given Chromium file.
def get_file_revision(revision, file_path): """Fetches the requested Git revision of the given Chromium file.""" url = f'https://raw.githubusercontent.com/chromium/chromium/{revision}/{file_path}' with urlopen(url) as http_response: return http_response.read().decode()
[ "def", "get_file_revision", "(", "revision", ",", "file_path", ")", ":", "url", "=", "f'https://raw.githubusercontent.com/chromium/chromium/{revision}/{file_path}'", "with", "urlopen", "(", "url", ")", "as", "http_response", ":", "return", "http_response", ".", "read", ...
[ 30, 0 ]
[ 34, 44 ]
python
en
['en', 'en', 'en']
True
get_current_revision
()
Get the current revision of llvmPackages_git.
Get the current revision of llvmPackages_git.
def get_current_revision(): """Get the current revision of llvmPackages_git.""" with open(DEFAULT_NIX) as f: for line in f: rev = re.search(r'^ rev = "(.*)";', line) if rev: return rev.group(1) sys.exit(1)
[ "def", "get_current_revision", "(", ")", ":", "with", "open", "(", "DEFAULT_NIX", ")", "as", "f", ":", "for", "line", "in", "f", ":", "rev", "=", "re", ".", "search", "(", "r'^ rev = \"(.*)\";'", ",", "line", ")", "if", "rev", ":", "return", "rev", ...
[ 45, 0 ]
[ 52, 15 ]
python
en
['en', 'en', 'en']
True
nix_prefetch_url
(url, algo='sha256')
Prefetches the content of the given URL.
Prefetches the content of the given URL.
def nix_prefetch_url(url, algo='sha256'): """Prefetches the content of the given URL.""" print(f'nix-prefetch-url {url}') out = subprocess.check_output(['nix-prefetch-url', '--type', algo, '--unpack', url]) return out.decode('utf-8').rstrip()
[ "def", "nix_prefetch_url", "(", "url", ",", "algo", "=", "'sha256'", ")", ":", "print", "(", "f'nix-prefetch-url {url}'", ")", "out", "=", "subprocess", ".", "check_output", "(", "[", "'nix-prefetch-url'", ",", "'--type'", ",", "algo", ",", "'--unpack'", ",", ...
[ 55, 0 ]
[ 59, 39 ]
python
en
['en', 'en', 'en']
True
authenticate_bridge
(hass: core.HomeAssistant, bridge: aiohue.Bridge)
Create a bridge object and verify authentication.
Create a bridge object and verify authentication.
async def authenticate_bridge(hass: core.HomeAssistant, bridge: aiohue.Bridge): """Create a bridge object and verify authentication.""" try: with async_timeout.timeout(10): # Create username if we don't have one if not bridge.username: device_name = unicode_slug.s...
[ "async", "def", "authenticate_bridge", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "bridge", ":", "aiohue", ".", "Bridge", ")", ":", "try", ":", "with", "async_timeout", ".", "timeout", "(", "10", ")", ":", "# Create username if we don't have one", "i...
[ 252, 0 ]
[ 277, 45 ]
python
en
['en', 'en', 'en']
True
_update_listener
(hass, entry)
Handle options update.
Handle options update.
async def _update_listener(hass, entry): """Handle options update.""" await hass.config_entries.async_reload(entry.entry_id)
[ "async", "def", "_update_listener", "(", "hass", ",", "entry", ")", ":", "await", "hass", ".", "config_entries", ".", "async_reload", "(", "entry", ".", "entry_id", ")" ]
[ 280, 0 ]
[ 282, 58 ]
python
en
['en', 'nl', 'en']
True
HueBridge.__init__
(self, hass, config_entry)
Initialize the system.
Initialize the system.
def __init__(self, hass, config_entry): """Initialize the system.""" self.config_entry = config_entry self.hass = hass self.available = True self.authorized = False self.api = None self.parallel_updates_semaphore = None # Jobs to be executed when API is re...
[ "def", "__init__", "(", "self", ",", "hass", ",", "config_entry", ")", ":", "self", ".", "config_entry", "=", "config_entry", "self", ".", "hass", "=", "hass", "self", ".", "available", "=", "True", "self", ".", "authorized", "=", "False", "self", ".", ...
[ 41, 4 ]
[ 52, 47 ]
python
en
['en', 'en', 'en']
True
HueBridge.host
(self)
Return the host of this bridge.
Return the host of this bridge.
def host(self): """Return the host of this bridge.""" return self.config_entry.data["host"]
[ "def", "host", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "data", "[", "\"host\"", "]" ]
[ 55, 4 ]
[ 57, 45 ]
python
en
['en', 'la', 'en']
True
HueBridge.allow_unreachable
(self)
Allow unreachable light bulbs.
Allow unreachable light bulbs.
def allow_unreachable(self): """Allow unreachable light bulbs.""" return self.config_entry.options.get( CONF_ALLOW_UNREACHABLE, DEFAULT_ALLOW_UNREACHABLE )
[ "def", "allow_unreachable", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_ALLOW_UNREACHABLE", ",", "DEFAULT_ALLOW_UNREACHABLE", ")" ]
[ 60, 4 ]
[ 64, 9 ]
python
en
['en', 'ga', 'en']
True
HueBridge.allow_groups
(self)
Allow groups defined in the Hue bridge.
Allow groups defined in the Hue bridge.
def allow_groups(self): """Allow groups defined in the Hue bridge.""" return self.config_entry.options.get( CONF_ALLOW_HUE_GROUPS, DEFAULT_ALLOW_HUE_GROUPS )
[ "def", "allow_groups", "(", "self", ")", ":", "return", "self", ".", "config_entry", ".", "options", ".", "get", "(", "CONF_ALLOW_HUE_GROUPS", ",", "DEFAULT_ALLOW_HUE_GROUPS", ")" ]
[ 67, 4 ]
[ 71, 9 ]
python
en
['en', 'en', 'en']
True
HueBridge.async_setup
(self, tries=0)
Set up a phue bridge based on host parameter.
Set up a phue bridge based on host parameter.
async def async_setup(self, tries=0): """Set up a phue bridge based on host parameter.""" host = self.host hass = self.hass bridge = aiohue.Bridge( host, username=self.config_entry.data["username"], websession=aiohttp_client.async_get_clientsession(ha...
[ "async", "def", "async_setup", "(", "self", ",", "tries", "=", "0", ")", ":", "host", "=", "self", ".", "host", "hass", "=", "self", ".", "hass", "bridge", "=", "aiohue", ".", "Bridge", "(", "host", ",", "username", "=", "self", ".", "config_entry", ...
[ 73, 4 ]
[ 127, 19 ]
python
en
['en', 'da', 'en']
True
HueBridge.async_request_call
(self, task)
Limit parallel requests to Hue hub. The Hue hub can only handle a certain amount of parallel requests, total. Although we limit our parallel requests, we still will run into issues because other products are hitting up Hue. ClientOSError means hub closed the socket on us. Conte...
Limit parallel requests to Hue hub.
async def async_request_call(self, task): """Limit parallel requests to Hue hub. The Hue hub can only handle a certain amount of parallel requests, total. Although we limit our parallel requests, we still will run into issues because other products are hitting up Hue. ClientOSE...
[ "async", "def", "async_request_call", "(", "self", ",", "task", ")", ":", "async", "with", "self", ".", "parallel_updates_semaphore", ":", "for", "tries", "in", "range", "(", "4", ")", ":", "try", ":", "return", "await", "task", "(", ")", "except", "(", ...
[ 129, 4 ]
[ 160, 63 ]
python
en
['en', 'en', 'en']
True
HueBridge.async_reset
(self)
Reset this bridge to default state. Will cancel any scheduled setup retry and will unload the config entry.
Reset this bridge to default state.
async def async_reset(self): """Reset this bridge to default state. Will cancel any scheduled setup retry and will unload the config entry. """ # The bridge can be in 3 states: # - Setup was successful, self.api is not None # - Authentication was wrong, self.ap...
[ "async", "def", "async_reset", "(", "self", ")", ":", "# The bridge can be in 3 states:", "# - Setup was successful, self.api is not None", "# - Authentication was wrong, self.api is None, not retrying setup.", "# If the authentication was wrong.", "if", "self", ".", "api", "is", "...
[ 162, 4 ]
[ 197, 35 ]
python
en
['en', 'la', 'en']
True
HueBridge.hue_activate_scene
(self, call, updated=False, hide_warnings=False)
Service to call directly into bridge to set scenes.
Service to call directly into bridge to set scenes.
async def hue_activate_scene(self, call, updated=False, hide_warnings=False): """Service to call directly into bridge to set scenes.""" group_name = call.data[ATTR_GROUP_NAME] scene_name = call.data[ATTR_SCENE_NAME] group = next( (group for group in self.api.groups.values() ...
[ "async", "def", "hue_activate_scene", "(", "self", ",", "call", ",", "updated", "=", "False", ",", "hide_warnings", "=", "False", ")", ":", "group_name", "=", "call", ".", "data", "[", "ATTR_GROUP_NAME", "]", "scene_name", "=", "call", ".", "data", "[", ...
[ 199, 4 ]
[ 238, 87 ]
python
en
['en', 'en', 'en']
True
HueBridge.handle_unauthorized_error
(self)
Create a new config flow when the authorization is no longer valid.
Create a new config flow when the authorization is no longer valid.
async def handle_unauthorized_error(self): """Create a new config flow when the authorization is no longer valid.""" if not self.authorized: # we already created a new config flow, no need to do it again return LOGGER.error( "Unable to authorize to bridge %s, ...
[ "async", "def", "handle_unauthorized_error", "(", "self", ")", ":", "if", "not", "self", ".", "authorized", ":", "# we already created a new config flow, no need to do it again", "return", "LOGGER", ".", "error", "(", "\"Unable to authorize to bridge %s, setup the linking again...
[ 240, 4 ]
[ 249, 48 ]
python
en
['en', 'en', 'en']
True
MixedOp.__init__
(self, mutable)
Parameters ---------- mutable : LayerChoice A LayerChoice in user model
Parameters ---------- mutable : LayerChoice A LayerChoice in user model
def __init__(self, mutable): """ Parameters ---------- mutable : LayerChoice A LayerChoice in user model """ super(MixedOp, self).__init__() self.ap_path_alpha = nn.Parameter(torch.Tensor(len(mutable))) self.ap_path_wb = nn.Parameter(torch.Tens...
[ "def", "__init__", "(", "self", ",", "mutable", ")", ":", "super", "(", "MixedOp", ",", "self", ")", ".", "__init__", "(", ")", "self", ".", "ap_path_alpha", "=", "nn", ".", "Parameter", "(", "torch", ".", "Tensor", "(", "len", "(", "mutable", ")", ...
[ 47, 4 ]
[ 63, 37 ]
python
en
['en', 'error', 'th']
False
MixedOp.forward
(self, mutable, x)
Define forward of LayerChoice. For 'full_v2', backward is also defined. The 'two' mode is explained in section 3.2.1 in the paper. The 'full_v2' mode is explained in Appendix D in the paper. Parameters ---------- mutable : LayerChoice this layer's mutable ...
Define forward of LayerChoice. For 'full_v2', backward is also defined. The 'two' mode is explained in section 3.2.1 in the paper. The 'full_v2' mode is explained in Appendix D in the paper.
def forward(self, mutable, x): """ Define forward of LayerChoice. For 'full_v2', backward is also defined. The 'two' mode is explained in section 3.2.1 in the paper. The 'full_v2' mode is explained in Appendix D in the paper. Parameters ---------- mutable : Layer...
[ "def", "forward", "(", "self", ",", "mutable", ",", "x", ")", ":", "if", "MixedOp", ".", "forward_mode", "==", "'full'", "or", "MixedOp", ".", "forward_mode", "==", "'two'", ":", "output", "=", "0", "for", "_i", "in", "self", ".", "active_index", ":", ...
[ 76, 4 ]
[ 126, 21 ]
python
en
['en', 'error', 'th']
False
MixedOp.probs_over_ops
(self)
Apply softmax on alpha to generate probability distribution Returns ------- pytorch tensor probability distribution
Apply softmax on alpha to generate probability distribution
def probs_over_ops(self): """ Apply softmax on alpha to generate probability distribution Returns ------- pytorch tensor probability distribution """ probs = F.softmax(self.ap_path_alpha, dim=0) # softmax to probability return probs
[ "def", "probs_over_ops", "(", "self", ")", ":", "probs", "=", "F", ".", "softmax", "(", "self", ".", "ap_path_alpha", ",", "dim", "=", "0", ")", "# softmax to probability", "return", "probs" ]
[ 129, 4 ]
[ 139, 20 ]
python
en
['en', 'error', 'th']
False
MixedOp.chosen_index
(self)
choose the op with max prob Returns ------- int index of the chosen one numpy.float32 prob of the chosen one
choose the op with max prob
def chosen_index(self): """ choose the op with max prob Returns ------- int index of the chosen one numpy.float32 prob of the chosen one """ probs = self.probs_over_ops.data.cpu().numpy() index = int(np.argmax(probs)) ...
[ "def", "chosen_index", "(", "self", ")", ":", "probs", "=", "self", ".", "probs_over_ops", ".", "data", ".", "cpu", "(", ")", ".", "numpy", "(", ")", "index", "=", "int", "(", "np", ".", "argmax", "(", "probs", ")", ")", "return", "index", ",", "...
[ 142, 4 ]
[ 155, 34 ]
python
en
['en', 'error', 'th']
False
MixedOp.active_op
(self, mutable)
assume only one path is active Returns ------- PyTorch module the chosen operation
assume only one path is active
def active_op(self, mutable): """ assume only one path is active Returns ------- PyTorch module the chosen operation """ return mutable[self.active_index[0]]
[ "def", "active_op", "(", "self", ",", "mutable", ")", ":", "return", "mutable", "[", "self", ".", "active_index", "[", "0", "]", "]" ]
[ 157, 4 ]
[ 166, 44 ]
python
en
['en', 'error', 'th']
False
MixedOp.active_op_index
(self)
return active op's index, the active op is sampled Returns ------- int index of the active op
return active op's index, the active op is sampled
def active_op_index(self): """ return active op's index, the active op is sampled Returns ------- int index of the active op """ return self.active_index[0]
[ "def", "active_op_index", "(", "self", ")", ":", "return", "self", ".", "active_index", "[", "0", "]" ]
[ 169, 4 ]
[ 178, 35 ]
python
en
['en', 'error', 'th']
False
MixedOp.set_chosen_op_active
(self)
set chosen index, active and inactive indexes
set chosen index, active and inactive indexes
def set_chosen_op_active(self): """ set chosen index, active and inactive indexes """ chosen_idx, _ = self.chosen_index self.active_index = [chosen_idx] self.inactive_index = [_i for _i in range(0, chosen_idx)] + \ [_i for _i in range(chosen_...
[ "def", "set_chosen_op_active", "(", "self", ")", ":", "chosen_idx", ",", "_", "=", "self", ".", "chosen_index", "self", ".", "active_index", "=", "[", "chosen_idx", "]", "self", ".", "inactive_index", "=", "[", "_i", "for", "_i", "in", "range", "(", "0",...
[ 180, 4 ]
[ 187, 82 ]
python
en
['en', 'error', 'th']
False
MixedOp.binarize
(self, mutable)
Sample based on alpha, and set binary weights accordingly. ap_path_wb is set in this function, which is called binarize. Parameters ---------- mutable : LayerChoice this layer's mutable
Sample based on alpha, and set binary weights accordingly. ap_path_wb is set in this function, which is called binarize.
def binarize(self, mutable): """ Sample based on alpha, and set binary weights accordingly. ap_path_wb is set in this function, which is called binarize. Parameters ---------- mutable : LayerChoice this layer's mutable """ self.log_prob = None...
[ "def", "binarize", "(", "self", ",", "mutable", ")", ":", "self", ".", "log_prob", "=", "None", "# reset binary gates", "self", ".", "ap_path_wb", ".", "data", ".", "zero_", "(", ")", "probs", "=", "self", ".", "probs_over_ops", "if", "MixedOp", ".", "fo...
[ 189, 4 ]
[ 231, 33 ]
python
en
['en', 'error', 'th']
False
MixedOp.set_arch_param_grad
(self, mutable)
Calculate alpha gradient for this LayerChoice. It is calculated using gradient of binary gate, probs of ops.
Calculate alpha gradient for this LayerChoice. It is calculated using gradient of binary gate, probs of ops.
def set_arch_param_grad(self, mutable): """ Calculate alpha gradient for this LayerChoice. It is calculated using gradient of binary gate, probs of ops. """ binary_grads = self.ap_path_wb.grad.data if self.active_op(mutable).is_zero_layer(): self.ap_path_alpha...
[ "def", "set_arch_param_grad", "(", "self", ",", "mutable", ")", ":", "binary_grads", "=", "self", ".", "ap_path_wb", ".", "grad", ".", "data", "if", "self", ".", "active_op", "(", "mutable", ")", ".", "is_zero_layer", "(", ")", ":", "self", ".", "ap_path...
[ 240, 4 ]
[ 271, 14 ]
python
en
['en', 'error', 'th']
False
MixedOp.rescale_updated_arch_param
(self)
rescale architecture weights for the 'two' mode.
rescale architecture weights for the 'two' mode.
def rescale_updated_arch_param(self): """ rescale architecture weights for the 'two' mode. """ if not isinstance(self.active_index[0], tuple): assert self.active_op.is_zero_layer() return involved_idx = [idx for idx, _ in (self.active_index + self.inactive...
[ "def", "rescale_updated_arch_param", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "active_index", "[", "0", "]", ",", "tuple", ")", ":", "assert", "self", ".", "active_op", ".", "is_zero_layer", "(", ")", "return", "involved_idx", "=...
[ 273, 4 ]
[ 289, 50 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.__init__
(self, model)
Init a MixedOp instance for each mutable i.e., LayerChoice. And register the instantiated MixedOp in corresponding LayerChoice. If does not register it in LayerChoice, DataParallel does not work then, because architecture weights are not included in the DataParallel model. When ...
Init a MixedOp instance for each mutable i.e., LayerChoice. And register the instantiated MixedOp in corresponding LayerChoice. If does not register it in LayerChoice, DataParallel does not work then, because architecture weights are not included in the DataParallel model. When ...
def __init__(self, model): """ Init a MixedOp instance for each mutable i.e., LayerChoice. And register the instantiated MixedOp in corresponding LayerChoice. If does not register it in LayerChoice, DataParallel does not work then, because architecture weights are not included in...
[ "def", "__init__", "(", "self", ",", "model", ")", ":", "super", "(", "ProxylessNasMutator", ",", "self", ")", ".", "__init__", "(", "model", ")", "self", ".", "_unused_modules", "=", "None", "self", ".", "mutable_list", "=", "[", "]", "for", "mutable", ...
[ 298, 4 ]
[ 317, 56 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.on_forward_layer_choice
(self, mutable, *args, **kwargs)
Callback of layer choice forward. This function defines the forward logic of the input mutable. So mutable is only interface, its real implementation is defined in mutator. Parameters ---------- mutable: LayerChoice forward logic of this input mutable ...
Callback of layer choice forward. This function defines the forward logic of the input mutable. So mutable is only interface, its real implementation is defined in mutator.
def on_forward_layer_choice(self, mutable, *args, **kwargs): """ Callback of layer choice forward. This function defines the forward logic of the input mutable. So mutable is only interface, its real implementation is defined in mutator. Parameters ---------- mut...
[ "def", "on_forward_layer_choice", "(", "self", ",", "mutable", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# FIXME: return mask, to be consistent with other algorithms", "idx", "=", "mutable", ".", "registered_module", ".", "active_op_index", "return", "muta...
[ 319, 4 ]
[ 343, 71 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.reset_binary_gates
(self)
For each LayerChoice, binarize binary weights based on alpha to only activate one op. It traverses all the mutables in the model to do this.
For each LayerChoice, binarize binary weights based on alpha to only activate one op. It traverses all the mutables in the model to do this.
def reset_binary_gates(self): """ For each LayerChoice, binarize binary weights based on alpha to only activate one op. It traverses all the mutables in the model to do this. """ for mutable in self.undedup_mutables: mutable.registered_module.binarize(mutable)
[ "def", "reset_binary_gates", "(", "self", ")", ":", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "mutable", ".", "registered_module", ".", "binarize", "(", "mutable", ")" ]
[ 345, 4 ]
[ 352, 55 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.set_chosen_op_active
(self)
For each LayerChoice, set the op with highest alpha as the chosen op. Usually used for validation.
For each LayerChoice, set the op with highest alpha as the chosen op. Usually used for validation.
def set_chosen_op_active(self): """ For each LayerChoice, set the op with highest alpha as the chosen op. Usually used for validation. """ for mutable in self.undedup_mutables: mutable.registered_module.set_chosen_op_active()
[ "def", "set_chosen_op_active", "(", "self", ")", ":", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "mutable", ".", "registered_module", ".", "set_chosen_op_active", "(", ")" ]
[ 354, 4 ]
[ 360, 60 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.num_arch_params
(self)
The number of mutables, i.e., LayerChoice Returns ------- int the number of LayerChoice in user model
The number of mutables, i.e., LayerChoice
def num_arch_params(self): """ The number of mutables, i.e., LayerChoice Returns ------- int the number of LayerChoice in user model """ return len(self.mutable_list)
[ "def", "num_arch_params", "(", "self", ")", ":", "return", "len", "(", "self", ".", "mutable_list", ")" ]
[ 362, 4 ]
[ 371, 37 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.set_arch_param_grad
(self)
For each LayerChoice, calculate gradients for architecture weights, i.e., alpha
For each LayerChoice, calculate gradients for architecture weights, i.e., alpha
def set_arch_param_grad(self): """ For each LayerChoice, calculate gradients for architecture weights, i.e., alpha """ for mutable in self.undedup_mutables: mutable.registered_module.set_arch_param_grad(mutable)
[ "def", "set_arch_param_grad", "(", "self", ")", ":", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "mutable", ".", "registered_module", ".", "set_arch_param_grad", "(", "mutable", ")" ]
[ 373, 4 ]
[ 378, 66 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.get_architecture_parameters
(self)
Get all the architecture parameters. yield ----- PyTorch Parameter Return ap_path_alpha of the traversed mutable
Get all the architecture parameters.
def get_architecture_parameters(self): """ Get all the architecture parameters. yield ----- PyTorch Parameter Return ap_path_alpha of the traversed mutable """ for mutable in self.undedup_mutables: yield mutable.registered_module.get_ap_pa...
[ "def", "get_architecture_parameters", "(", "self", ")", ":", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "yield", "mutable", ".", "registered_module", ".", "get_ap_path_alpha", "(", ")" ]
[ 380, 4 ]
[ 390, 63 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.change_forward_mode
(self, mode)
Update forward mode of MixedOps, as training architecture weights and model weights use different forward modes.
Update forward mode of MixedOps, as training architecture weights and model weights use different forward modes.
def change_forward_mode(self, mode): """ Update forward mode of MixedOps, as training architecture weights and model weights use different forward modes. """ MixedOp.forward_mode = mode
[ "def", "change_forward_mode", "(", "self", ",", "mode", ")", ":", "MixedOp", ".", "forward_mode", "=", "mode" ]
[ 392, 4 ]
[ 397, 35 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.get_forward_mode
(self)
Get forward mode of MixedOp Returns ------- string the current forward mode of MixedOp
Get forward mode of MixedOp
def get_forward_mode(self): """ Get forward mode of MixedOp Returns ------- string the current forward mode of MixedOp """ return MixedOp.forward_mode
[ "def", "get_forward_mode", "(", "self", ")", ":", "return", "MixedOp", ".", "forward_mode" ]
[ 399, 4 ]
[ 408, 35 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.rescale_updated_arch_param
(self)
Rescale architecture weights in 'two' mode.
Rescale architecture weights in 'two' mode.
def rescale_updated_arch_param(self): """ Rescale architecture weights in 'two' mode. """ for mutable in self.undedup_mutables: mutable.registered_module.rescale_updated_arch_param()
[ "def", "rescale_updated_arch_param", "(", "self", ")", ":", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "mutable", ".", "registered_module", ".", "rescale_updated_arch_param", "(", ")" ]
[ 410, 4 ]
[ 415, 66 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.unused_modules_off
(self)
Remove unused modules for each mutables. The removed modules are kept in ```self._unused_modules``` for resume later.
Remove unused modules for each mutables. The removed modules are kept in ```self._unused_modules``` for resume later.
def unused_modules_off(self): """ Remove unused modules for each mutables. The removed modules are kept in ```self._unused_modules``` for resume later. """ self._unused_modules = [] for mutable in self.undedup_mutables: mixed_op = mutable.registered_module ...
[ "def", "unused_modules_off", "(", "self", ")", ":", "self", ".", "_unused_modules", "=", "[", "]", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "mixed_op", "=", "mutable", ".", "registered_module", "unused", "=", "{", "}", "if", "self", "....
[ 417, 4 ]
[ 434, 47 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.unused_modules_back
(self)
Resume the removed modules back.
Resume the removed modules back.
def unused_modules_back(self): """ Resume the removed modules back. """ if self._unused_modules is None: return for m, unused in zip(self.mutable_list, self._unused_modules): for i in unused: m[i] = unused[i] self._unused_modules = ...
[ "def", "unused_modules_back", "(", "self", ")", ":", "if", "self", ".", "_unused_modules", "is", "None", ":", "return", "for", "m", ",", "unused", "in", "zip", "(", "self", ".", "mutable_list", ",", "self", ".", "_unused_modules", ")", ":", "for", "i", ...
[ 436, 4 ]
[ 445, 35 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.arch_requires_grad
(self)
Make architecture weights require gradient
Make architecture weights require gradient
def arch_requires_grad(self): """ Make architecture weights require gradient """ for mutable in self.undedup_mutables: mutable.registered_module.to_requires_grad()
[ "def", "arch_requires_grad", "(", "self", ")", ":", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "mutable", ".", "registered_module", ".", "to_requires_grad", "(", ")" ]
[ 447, 4 ]
[ 452, 56 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.arch_disable_grad
(self)
Disable gradient of architecture weights, i.e., does not calcuate gradient for them.
Disable gradient of architecture weights, i.e., does not calcuate gradient for them.
def arch_disable_grad(self): """ Disable gradient of architecture weights, i.e., does not calcuate gradient for them. """ for mutable in self.undedup_mutables: mutable.registered_module.to_disable_grad()
[ "def", "arch_disable_grad", "(", "self", ")", ":", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "mutable", ".", "registered_module", ".", "to_disable_grad", "(", ")" ]
[ 454, 4 ]
[ 460, 55 ]
python
en
['en', 'error', 'th']
False
ProxylessNasMutator.sample_final
(self)
Generate the final chosen architecture. Returns ------- dict the choice of each mutable, i.e., LayerChoice
Generate the final chosen architecture.
def sample_final(self): """ Generate the final chosen architecture. Returns ------- dict the choice of each mutable, i.e., LayerChoice """ result = dict() for mutable in self.undedup_mutables: assert isinstance(mutable, LayerChoice...
[ "def", "sample_final", "(", "self", ")", ":", "result", "=", "dict", "(", ")", "for", "mutable", "in", "self", ".", "undedup_mutables", ":", "assert", "isinstance", "(", "mutable", ",", "LayerChoice", ")", "index", ",", "_", "=", "mutable", ".", "registe...
[ 462, 4 ]
[ 477, 21 ]
python
en
['en', 'error', 'th']
False
async_setup
(hass: HomeAssistant, config: dict)
Set up the WiLight with Config Flow component.
Set up the WiLight with Config Flow component.
async def async_setup(hass: HomeAssistant, config: dict): """Set up the WiLight with Config Flow component.""" hass.data[DOMAIN] = {} return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "dict", ")", ":", "hass", ".", "data", "[", "DOMAIN", "]", "=", "{", "}", "return", "True" ]
[ 15, 0 ]
[ 20, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass: HomeAssistant, entry: ConfigEntry)
Set up a wilight config entry.
Set up a wilight config entry.
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up a wilight config entry.""" parent = WiLightParent(hass, entry) if not await parent.async_setup(): raise ConfigEntryNotReady hass.data[DOMAIN][entry.entry_id] = parent # Set up all platforms for this device/en...
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "parent", "=", "WiLightParent", "(", "hass", ",", "entry", ")", "if", "not", "await", "parent", ".", "async_setup", "(", ")", ":", "raise", ...
[ 23, 0 ]
[ 39, 15 ]
python
en
['en', 'en', 'en']
True
async_unload_entry
(hass: HomeAssistant, entry: ConfigEntry)
Unload WiLight config entry.
Unload WiLight config entry.
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload WiLight config entry.""" # Unload entities for this entry/device. await asyncio.gather( *( hass.config_entries.async_forward_entry_unload(entry, component) for component in PLATFORMS ) ...
[ "async", "def", "async_unload_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "# Unload entities for this entry/device.", "await", "asyncio", ".", "gather", "(", "*", "(", "hass", ".", "config_entries", ".", "async_forward_entr...
[ 42, 0 ]
[ 58, 15 ]
python
en
['da', 'en', 'en']
True
WiLightDevice.__init__
(self, api_device, index, item_name)
Initialize the device.
Initialize the device.
def __init__(self, api_device, index, item_name): """Initialize the device.""" # WiLight specific attributes for every component type self._device_id = api_device.device_id self._sw_version = api_device.swversion self._client = api_device.client self._model = api_device.m...
[ "def", "__init__", "(", "self", ",", "api_device", ",", "index", ",", "item_name", ")", ":", "# WiLight specific attributes for every component type", "self", ".", "_device_id", "=", "api_device", ".", "device_id", "self", ".", "_sw_version", "=", "api_device", ".",...
[ 67, 4 ]
[ 77, 25 ]
python
en
['en', 'en', 'en']
True
WiLightDevice.should_poll
(self)
No polling needed.
No polling needed.
def should_poll(self): """No polling needed.""" return False
[ "def", "should_poll", "(", "self", ")", ":", "return", "False" ]
[ 80, 4 ]
[ 82, 20 ]
python
en
['en', 'en', 'en']
True
WiLightDevice.name
(self)
Return a name for this WiLight item.
Return a name for this WiLight item.
def name(self): """Return a name for this WiLight item.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 85, 4 ]
[ 87, 25 ]
python
en
['en', 'en', 'en']
True
WiLightDevice.unique_id
(self)
Return the unique ID for this WiLight item.
Return the unique ID for this WiLight item.
def unique_id(self): """Return the unique ID for this WiLight item.""" return self._unique_id
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_unique_id" ]
[ 90, 4 ]
[ 92, 30 ]
python
en
['en', 'la', 'en']
True
WiLightDevice.device_info
(self)
Return the device info.
Return the device info.
def device_info(self): """Return the device info.""" return { "name": self._name, "identifiers": {(DOMAIN, self._unique_id)}, "model": self._model, "manufacturer": "WiLight", "sw_version": self._sw_version, "via_device": (DOMAIN, se...
[ "def", "device_info", "(", "self", ")", ":", "return", "{", "\"name\"", ":", "self", ".", "_name", ",", "\"identifiers\"", ":", "{", "(", "DOMAIN", ",", "self", ".", "_unique_id", ")", "}", ",", "\"model\"", ":", "self", ".", "_model", ",", "\"manufact...
[ 95, 4 ]
[ 104, 9 ]
python
en
['en', 'en', 'en']
True
WiLightDevice.available
(self)
Return True if entity is available.
Return True if entity is available.
def available(self): """Return True if entity is available.""" return bool(self._client.is_connected)
[ "def", "available", "(", "self", ")", ":", "return", "bool", "(", "self", ".", "_client", ".", "is_connected", ")" ]
[ 107, 4 ]
[ 109, 46 ]
python
en
['en', 'en', 'en']
True
WiLightDevice.handle_event_callback
(self, states)
Propagate changes through ha.
Propagate changes through ha.
def handle_event_callback(self, states): """Propagate changes through ha.""" self._status = states self.async_write_ha_state()
[ "def", "handle_event_callback", "(", "self", ",", "states", ")", ":", "self", ".", "_status", "=", "states", "self", ".", "async_write_ha_state", "(", ")" ]
[ 112, 4 ]
[ 115, 35 ]
python
en
['en', 'gd', 'en']
True
WiLightDevice.async_update
(self)
Synchronize state with api_device.
Synchronize state with api_device.
async def async_update(self): """Synchronize state with api_device.""" await self._client.status(self._index)
[ "async", "def", "async_update", "(", "self", ")", ":", "await", "self", ".", "_client", ".", "status", "(", "self", ".", "_index", ")" ]
[ 117, 4 ]
[ 119, 46 ]
python
en
['en', 'en', 'en']
True
WiLightDevice.async_added_to_hass
(self)
Register update callback.
Register update callback.
async def async_added_to_hass(self): """Register update callback.""" self._client.register_status_callback(self.handle_event_callback, self._index) await self._client.status(self._index)
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "self", ".", "_client", ".", "register_status_callback", "(", "self", ".", "handle_event_callback", ",", "self", ".", "_index", ")", "await", "self", ".", "_client", ".", "status", "(", "self", "....
[ 121, 4 ]
[ 124, 46 ]
python
en
['fr', 'no', 'en']
False