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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
OpenWeatherMapWeather.pressure | (self) | Return the pressure. | Return the pressure. | def pressure(self):
"""Return the pressure."""
return self._weather_coordinator.data[ATTR_API_PRESSURE] | [
"def",
"pressure",
"(",
"self",
")",
":",
"return",
"self",
".",
"_weather_coordinator",
".",
"data",
"[",
"ATTR_API_PRESSURE",
"]"
] | [
82,
4
] | [
84,
64
] | python | en | ['en', 'ig', 'en'] | True |
OpenWeatherMapWeather.humidity | (self) | Return the humidity. | Return the humidity. | def humidity(self):
"""Return the humidity."""
return self._weather_coordinator.data[ATTR_API_HUMIDITY] | [
"def",
"humidity",
"(",
"self",
")",
":",
"return",
"self",
".",
"_weather_coordinator",
".",
"data",
"[",
"ATTR_API_HUMIDITY",
"]"
] | [
87,
4
] | [
89,
64
] | python | en | ['en', 'sw', 'en'] | True |
OpenWeatherMapWeather.wind_speed | (self) | Return the wind speed. | Return the wind speed. | def wind_speed(self):
"""Return the wind speed."""
wind_speed = self._weather_coordinator.data[ATTR_API_WIND_SPEED]
if self.hass.config.units.name == "imperial":
return round(wind_speed * 2.24, 2)
return round(wind_speed * 3.6, 2) | [
"def",
"wind_speed",
"(",
"self",
")",
":",
"wind_speed",
"=",
"self",
".",
"_weather_coordinator",
".",
"data",
"[",
"ATTR_API_WIND_SPEED",
"]",
"if",
"self",
".",
"hass",
".",
"config",
".",
"units",
".",
"name",
"==",
"\"imperial\"",
":",
"return",
"rou... | [
92,
4
] | [
97,
41
] | python | en | ['en', 'zh', 'en'] | True |
OpenWeatherMapWeather.wind_bearing | (self) | Return the wind bearing. | Return the wind bearing. | def wind_bearing(self):
"""Return the wind bearing."""
return self._weather_coordinator.data[ATTR_API_WIND_BEARING] | [
"def",
"wind_bearing",
"(",
"self",
")",
":",
"return",
"self",
".",
"_weather_coordinator",
".",
"data",
"[",
"ATTR_API_WIND_BEARING",
"]"
] | [
100,
4
] | [
102,
68
] | python | en | ['en', 'ig', 'en'] | True |
OpenWeatherMapWeather.forecast | (self) | Return the forecast array. | Return the forecast array. | def forecast(self):
"""Return the forecast array."""
return self._weather_coordinator.data[ATTR_API_FORECAST] | [
"def",
"forecast",
"(",
"self",
")",
":",
"return",
"self",
".",
"_weather_coordinator",
".",
"data",
"[",
"ATTR_API_FORECAST",
"]"
] | [
105,
4
] | [
107,
64
] | python | en | ['en', 'ga', 'en'] | True |
OpenWeatherMapWeather.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self):
"""Return True if entity is available."""
return self._weather_coordinator.last_update_success | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_weather_coordinator",
".",
"last_update_success"
] | [
110,
4
] | [
112,
60
] | python | en | ['en', 'en', 'en'] | True |
OpenWeatherMapWeather.async_added_to_hass | (self) | Connect to dispatcher listening for entity data notifications. | Connect to dispatcher listening for entity data notifications. | async def async_added_to_hass(self):
"""Connect to dispatcher listening for entity data notifications."""
self.async_on_remove(
self._weather_coordinator.async_add_listener(self.async_write_ha_state)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"async_on_remove",
"(",
"self",
".",
"_weather_coordinator",
".",
"async_add_listener",
"(",
"self",
".",
"async_write_ha_state",
")",
")"
] | [
114,
4
] | [
118,
9
] | python | en | ['en', 'en', 'en'] | True |
OpenWeatherMapWeather.async_update | (self) | Get the latest data from OWM and updates the states. | Get the latest data from OWM and updates the states. | async def async_update(self):
"""Get the latest data from OWM and updates the states."""
await self._weather_coordinator.async_request_refresh() | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"await",
"self",
".",
"_weather_coordinator",
".",
"async_request_refresh",
"(",
")"
] | [
120,
4
] | [
122,
63
] | python | en | ['en', 'en', 'en'] | True |
OmniLogicUpdateCoordinator.__init__ | (
self,
hass: HomeAssistant,
api: str,
name: str,
polling_interval: int,
) | Initialize the global Omnilogic data updater. | Initialize the global Omnilogic data updater. | def __init__(
self,
hass: HomeAssistant,
api: str,
name: str,
polling_interval: int,
):
"""Initialize the global Omnilogic data updater."""
self.api = api
super().__init__(
hass=hass,
logger=_LOGGER,
name=name,
... | [
"def",
"__init__",
"(",
"self",
",",
"hass",
":",
"HomeAssistant",
",",
"api",
":",
"str",
",",
"name",
":",
"str",
",",
"polling_interval",
":",
"int",
",",
")",
":",
"self",
".",
"api",
"=",
"api",
"super",
"(",
")",
".",
"__init__",
"(",
"hass",... | [
29,
4
] | [
44,
9
] | python | en | ['en', 'en', 'en'] | True |
OmniLogicUpdateCoordinator._async_update_data | (self) | Fetch data from OmniLogic. | Fetch data from OmniLogic. | async def _async_update_data(self):
"""Fetch data from OmniLogic."""
try:
data = await self.api.get_telemetry_data()
except OmniLogicException as error:
raise UpdateFailed(f"Error updating from OmniLogic: {error}") from error
parsed_data = {}
def get_it... | [
"async",
"def",
"_async_update_data",
"(",
"self",
")",
":",
"try",
":",
"data",
"=",
"await",
"self",
".",
"api",
".",
"get_telemetry_data",
"(",
")",
"except",
"OmniLogicException",
"as",
"error",
":",
"raise",
"UpdateFailed",
"(",
"f\"Error updating from Omni... | [
46,
4
] | [
75,
26
] | python | en | ['en', 'en', 'en'] | True |
OmniLogicEntity.__init__ | (
self,
coordinator: OmniLogicUpdateCoordinator,
kind: str,
name: str,
item_id: tuple,
icon: str,
) | Initialize the OmniLogic Entity. | Initialize the OmniLogic Entity. | def __init__(
self,
coordinator: OmniLogicUpdateCoordinator,
kind: str,
name: str,
item_id: tuple,
icon: str,
):
"""Initialize the OmniLogic Entity."""
super().__init__(coordinator)
bow_id = None
entity_data = coordinator.data[item_id]... | [
"def",
"__init__",
"(",
"self",
",",
"coordinator",
":",
"OmniLogicUpdateCoordinator",
",",
"kind",
":",
"str",
",",
"name",
":",
"str",
",",
"item_id",
":",
"tuple",
",",
"icon",
":",
"str",
",",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"c... | [
81,
4
] | [
125,
75
] | python | en | ['en', 'zu', 'en'] | True |
OmniLogicEntity.unique_id | (self) | Return a unique, Home Assistant friendly identifier for this entity. | Return a unique, Home Assistant friendly identifier for this entity. | def unique_id(self) -> str:
"""Return a unique, Home Assistant friendly identifier for this entity."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_unique_id"
] | [
128,
4
] | [
130,
30
] | python | en | ['en', 'en', 'en'] | True |
OmniLogicEntity.name | (self) | Return the name of the entity. | Return the name of the entity. | def name(self) -> str:
"""Return the name of the entity."""
return self._name | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_name"
] | [
133,
4
] | [
135,
25
] | python | en | ['en', 'en', 'en'] | True |
OmniLogicEntity.icon | (self) | Return the icon for the entity. | Return the icon for the entity. | def icon(self):
"""Return the icon for the entity."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
138,
4
] | [
140,
25
] | python | en | ['en', 'en', 'en'] | True |
OmniLogicEntity.device_state_attributes | (self) | Return the attributes. | Return the attributes. | def device_state_attributes(self):
"""Return the attributes."""
return self._attrs | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_attrs"
] | [
143,
4
] | [
145,
26
] | python | en | ['en', 'la', 'en'] | True |
OmniLogicEntity.device_info | (self) | Define the device as back yard/MSP System. | Define the device as back yard/MSP System. | def device_info(self):
"""Define the device as back yard/MSP System."""
return {
ATTR_IDENTIFIERS: {(DOMAIN, self._msp_system_id)},
ATTR_NAME: self._backyard_name,
ATTR_MANUFACTURER: "Hayward",
ATTR_MODEL: "OmniLogic",
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_IDENTIFIERS",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"_msp_system_id",
")",
"}",
",",
"ATTR_NAME",
":",
"self",
".",
"_backyard_name",
",",
"ATTR_MANUFACTURER",
":",
"\"Hayward\"",
",",
... | [
148,
4
] | [
156,
9
] | python | en | ['en', 'en', 'en'] | True |
get_device | (hass, host, port, username, password) | Create a Axis device. | Create a Axis device. | async def get_device(hass, host, port, username, password):
"""Create a Axis device."""
device = axis.AxisDevice(
Configuration(host, port=port, username=username, password=password)
)
try:
with async_timeout.timeout(15):
await device.vapix.initialize()
return devi... | [
"async",
"def",
"get_device",
"(",
"hass",
",",
"host",
",",
"port",
",",
"username",
",",
"password",
")",
":",
"device",
"=",
"axis",
".",
"AxisDevice",
"(",
"Configuration",
"(",
"host",
",",
"port",
"=",
"port",
",",
"username",
"=",
"username",
",... | [
267,
0
] | [
293,
45
] | python | en | ['pt', 'en', 'en'] | True |
AxisNetworkDevice.__init__ | (self, hass, config_entry) | Initialize the device. | Initialize the device. | def __init__(self, hass, config_entry):
"""Initialize the device."""
self.hass = hass
self.config_entry = config_entry
self.available = True
self.api = None
self.fw_version = None
self.product_type = None
self.listeners = [] | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"config_entry",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"config_entry",
"=",
"config_entry",
"self",
".",
"available",
"=",
"True",
"self",
".",
"api",
"=",
"None",
"self",
".",
"fw_ver... | [
47,
4
] | [
57,
27
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.host | (self) | Return the host of this device. | Return the host of this device. | def host(self):
"""Return the host of this device."""
return self.config_entry.data[CONF_HOST] | [
"def",
"host",
"(",
"self",
")",
":",
"return",
"self",
".",
"config_entry",
".",
"data",
"[",
"CONF_HOST",
"]"
] | [
60,
4
] | [
62,
48
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.model | (self) | Return the model of this device. | Return the model of this device. | def model(self):
"""Return the model of this device."""
return self.config_entry.data[CONF_MODEL] | [
"def",
"model",
"(",
"self",
")",
":",
"return",
"self",
".",
"config_entry",
".",
"data",
"[",
"CONF_MODEL",
"]"
] | [
65,
4
] | [
67,
49
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.name | (self) | Return the name of this device. | Return the name of this device. | def name(self):
"""Return the name of this device."""
return self.config_entry.data[CONF_NAME] | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"config_entry",
".",
"data",
"[",
"CONF_NAME",
"]"
] | [
70,
4
] | [
72,
48
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.serial | (self) | Return the serial number of this device. | Return the serial number of this device. | def serial(self):
"""Return the serial number of this device."""
return self.config_entry.unique_id | [
"def",
"serial",
"(",
"self",
")",
":",
"return",
"self",
".",
"config_entry",
".",
"unique_id"
] | [
75,
4
] | [
77,
42
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.option_events | (self) | Config entry option defining if platforms based on events should be created. | Config entry option defining if platforms based on events should be created. | def option_events(self):
"""Config entry option defining if platforms based on events should be created."""
return self.config_entry.options.get(CONF_EVENTS, DEFAULT_EVENTS) | [
"def",
"option_events",
"(",
"self",
")",
":",
"return",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_EVENTS",
",",
"DEFAULT_EVENTS",
")"
] | [
82,
4
] | [
84,
73
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.option_stream_profile | (self) | Config entry option defining what stream profile camera platform should use. | Config entry option defining what stream profile camera platform should use. | def option_stream_profile(self):
"""Config entry option defining what stream profile camera platform should use."""
return self.config_entry.options.get(
CONF_STREAM_PROFILE, DEFAULT_STREAM_PROFILE
) | [
"def",
"option_stream_profile",
"(",
"self",
")",
":",
"return",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_STREAM_PROFILE",
",",
"DEFAULT_STREAM_PROFILE",
")"
] | [
87,
4
] | [
91,
9
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.option_trigger_time | (self) | Config entry option defining minimum number of seconds to keep trigger high. | Config entry option defining minimum number of seconds to keep trigger high. | def option_trigger_time(self):
"""Config entry option defining minimum number of seconds to keep trigger high."""
return self.config_entry.options.get(CONF_TRIGGER_TIME, DEFAULT_TRIGGER_TIME) | [
"def",
"option_trigger_time",
"(",
"self",
")",
":",
"return",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_TRIGGER_TIME",
",",
"DEFAULT_TRIGGER_TIME",
")"
] | [
94,
4
] | [
96,
85
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.signal_reachable | (self) | Device specific event to signal a change in connection status. | Device specific event to signal a change in connection status. | def signal_reachable(self):
"""Device specific event to signal a change in connection status."""
return f"axis_reachable_{self.serial}" | [
"def",
"signal_reachable",
"(",
"self",
")",
":",
"return",
"f\"axis_reachable_{self.serial}\""
] | [
101,
4
] | [
103,
46
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.signal_new_event | (self) | Device specific event to signal new device event available. | Device specific event to signal new device event available. | def signal_new_event(self):
"""Device specific event to signal new device event available."""
return f"axis_new_event_{self.serial}" | [
"def",
"signal_new_event",
"(",
"self",
")",
":",
"return",
"f\"axis_new_event_{self.serial}\""
] | [
106,
4
] | [
108,
46
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.signal_new_address | (self) | Device specific event to signal a change in device address. | Device specific event to signal a change in device address. | def signal_new_address(self):
"""Device specific event to signal a change in device address."""
return f"axis_new_address_{self.serial}" | [
"def",
"signal_new_address",
"(",
"self",
")",
":",
"return",
"f\"axis_new_address_{self.serial}\""
] | [
111,
4
] | [
113,
48
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.async_connection_status_callback | (self, status) | Handle signals of device connection status.
This is called on every RTSP keep-alive message.
Only signal state change if state change is true.
| Handle signals of device connection status. | def async_connection_status_callback(self, status):
"""Handle signals of device connection status.
This is called on every RTSP keep-alive message.
Only signal state change if state change is true.
"""
if self.available != (status == SIGNAL_PLAYING):
self.available ... | [
"def",
"async_connection_status_callback",
"(",
"self",
",",
"status",
")",
":",
"if",
"self",
".",
"available",
"!=",
"(",
"status",
"==",
"SIGNAL_PLAYING",
")",
":",
"self",
".",
"available",
"=",
"not",
"self",
".",
"available",
"async_dispatcher_send",
"("... | [
118,
4
] | [
127,
73
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.async_event_callback | (self, action, event_id) | Call to configure events when initialized on event stream. | Call to configure events when initialized on event stream. | def async_event_callback(self, action, event_id):
"""Call to configure events when initialized on event stream."""
if action == OPERATION_INITIALIZED:
async_dispatcher_send(self.hass, self.signal_new_event, event_id) | [
"def",
"async_event_callback",
"(",
"self",
",",
"action",
",",
"event_id",
")",
":",
"if",
"action",
"==",
"OPERATION_INITIALIZED",
":",
"async_dispatcher_send",
"(",
"self",
".",
"hass",
",",
"self",
".",
"signal_new_event",
",",
"event_id",
")"
] | [
130,
4
] | [
133,
77
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.async_new_address_callback | (hass, entry) | Handle signals of device getting new address.
Called when config entry is updated.
This is a static method because a class method (bound method),
can not be used with weak references.
| Handle signals of device getting new address. | async def async_new_address_callback(hass, entry):
"""Handle signals of device getting new address.
Called when config entry is updated.
This is a static method because a class method (bound method),
can not be used with weak references.
"""
device = hass.data[AXIS_DOMAI... | [
"async",
"def",
"async_new_address_callback",
"(",
"hass",
",",
"entry",
")",
":",
"device",
"=",
"hass",
".",
"data",
"[",
"AXIS_DOMAIN",
"]",
"[",
"entry",
".",
"unique_id",
"]",
"device",
".",
"api",
".",
"config",
".",
"host",
"=",
"device",
".",
"... | [
136,
4
] | [
145,
62
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.async_update_device_registry | (self) | Update device registry. | Update device registry. | async def async_update_device_registry(self):
"""Update device registry."""
device_registry = await self.hass.helpers.device_registry.async_get_registry()
device_registry.async_get_or_create(
config_entry_id=self.config_entry.entry_id,
connections={(CONNECTION_NETWORK_MAC... | [
"async",
"def",
"async_update_device_registry",
"(",
"self",
")",
":",
"device_registry",
"=",
"await",
"self",
".",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"device_registry",
".",
"async_get_or_create",
"(",
"config_entr... | [
147,
4
] | [
158,
9
] | python | en | ['fr', 'fy', 'en'] | False |
AxisNetworkDevice.use_mqtt | (self, hass: HomeAssistant, component: str) | Set up to use MQTT. | Set up to use MQTT. | async def use_mqtt(self, hass: HomeAssistant, component: str) -> None:
"""Set up to use MQTT."""
try:
status = await self.api.vapix.mqtt.get_client_status()
except Unauthorized:
# This means the user has too low privileges
status = {}
if status.get("d... | [
"async",
"def",
"use_mqtt",
"(",
"self",
",",
"hass",
":",
"HomeAssistant",
",",
"component",
":",
"str",
")",
"->",
"None",
":",
"try",
":",
"status",
"=",
"await",
"self",
".",
"api",
".",
"vapix",
".",
"mqtt",
".",
"get_client_status",
"(",
")",
"... | [
160,
4
] | [
171,
13
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.mqtt_message | (self, message: Message) | Receive Axis MQTT message. | Receive Axis MQTT message. | def mqtt_message(self, message: Message) -> None:
"""Receive Axis MQTT message."""
self.disconnect_from_stream()
event = mqtt_json_to_event(message.payload)
self.api.event.process_event(event) | [
"def",
"mqtt_message",
"(",
"self",
",",
"message",
":",
"Message",
")",
"->",
"None",
":",
"self",
".",
"disconnect_from_stream",
"(",
")",
"event",
"=",
"mqtt_json_to_event",
"(",
"message",
".",
"payload",
")",
"self",
".",
"api",
".",
"event",
".",
"... | [
174,
4
] | [
179,
43
] | python | en | ['en', 'lb', 'en'] | True |
AxisNetworkDevice.async_setup | (self) | Set up the device. | Set up the device. | async def async_setup(self):
"""Set up the device."""
try:
self.api = await get_device(
self.hass,
host=self.config_entry.data[CONF_HOST],
port=self.config_entry.data[CONF_PORT],
username=self.config_entry.data[CONF_USERNAME],
... | [
"async",
"def",
"async_setup",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"api",
"=",
"await",
"get_device",
"(",
"self",
".",
"hass",
",",
"host",
"=",
"self",
".",
"config_entry",
".",
"data",
"[",
"CONF_HOST",
"]",
",",
"port",
"=",
"self",
... | [
183,
4
] | [
227,
19
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.disconnect_from_stream | (self) | Stop stream. | Stop stream. | def disconnect_from_stream(self):
"""Stop stream."""
if self.api.stream.state != STATE_STOPPED:
self.api.stream.connection_status_callback.remove(
self.async_connection_status_callback
)
self.api.stream.stop() | [
"def",
"disconnect_from_stream",
"(",
"self",
")",
":",
"if",
"self",
".",
"api",
".",
"stream",
".",
"state",
"!=",
"STATE_STOPPED",
":",
"self",
".",
"api",
".",
"stream",
".",
"connection_status_callback",
".",
"remove",
"(",
"self",
".",
"async_connectio... | [
230,
4
] | [
236,
34
] | python | en | ['en', 'sr', 'en'] | False |
AxisNetworkDevice.shutdown | (self, event) | Stop the event stream. | Stop the event stream. | async def shutdown(self, event):
"""Stop the event stream."""
self.disconnect_from_stream()
await self.api.vapix.close() | [
"async",
"def",
"shutdown",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"disconnect_from_stream",
"(",
")",
"await",
"self",
".",
"api",
".",
"vapix",
".",
"close",
"(",
")"
] | [
238,
4
] | [
241,
36
] | python | en | ['en', 'en', 'en'] | True |
AxisNetworkDevice.async_reset | (self) | Reset this device to default state. | Reset this device to default state. | async def async_reset(self):
"""Reset this device to default state."""
self.disconnect_from_stream()
await self.api.vapix.close()
unload_ok = all(
await asyncio.gather(
*[
self.hass.config_entries.async_forward_entry_unload(
... | [
"async",
"def",
"async_reset",
"(",
"self",
")",
":",
"self",
".",
"disconnect_from_stream",
"(",
")",
"await",
"self",
".",
"api",
".",
"vapix",
".",
"close",
"(",
")",
"unload_ok",
"=",
"all",
"(",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
... | [
243,
4
] | [
264,
19
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Panasonic Blu-ray platform. | Set up the Panasonic Blu-ray platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Panasonic Blu-ray platform."""
conf = discovery_info if discovery_info else config
# Register configured device with Home Assistant.
add_entities([PanasonicBluRay(conf[CONF_HOST], conf[CONF_NAME])]) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"conf",
"=",
"discovery_info",
"if",
"discovery_info",
"else",
"config",
"# Register configured device with Home Assistant.",
"add_entities",
"(",
"... | [
40,
0
] | [
45,
69
] | python | en | ['en', 'ny', 'en'] | True |
PanasonicBluRay.__init__ | (self, ip, name) | Initialize the Panasonic Blue-ray device. | Initialize the Panasonic Blue-ray device. | def __init__(self, ip, name):
"""Initialize the Panasonic Blue-ray device."""
self._device = PanasonicBD(ip)
self._name = name
self._state = STATE_OFF
self._position = 0
self._duration = 0
self._position_valid = 0 | [
"def",
"__init__",
"(",
"self",
",",
"ip",
",",
"name",
")",
":",
"self",
".",
"_device",
"=",
"PanasonicBD",
"(",
"ip",
")",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_state",
"=",
"STATE_OFF",
"self",
".",
"_position",
"=",
"0",
"self",
".... | [
51,
4
] | [
58,
32
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.icon | (self) | Return a disc player icon for the device. | Return a disc player icon for the device. | def icon(self):
"""Return a disc player icon for the device."""
return "mdi:disc-player" | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"\"mdi:disc-player\""
] | [
61,
4
] | [
63,
32
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.name | (self) | Return the display name of this device. | Return the display name of this device. | def name(self):
"""Return the display name of this device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
66,
4
] | [
68,
25
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.state | (self) | Return _state variable, containing the appropriate constant. | Return _state variable, containing the appropriate constant. | def state(self):
"""Return _state variable, containing the appropriate constant."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
71,
4
] | [
73,
26
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.supported_features | (self) | Flag media player features that are supported. | Flag media player features that are supported. | def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_PANASONIC_BD | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_PANASONIC_BD"
] | [
76,
4
] | [
78,
35
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.media_duration | (self) | Duration of current playing media in seconds. | Duration of current playing media in seconds. | def media_duration(self):
"""Duration of current playing media in seconds."""
return self._duration | [
"def",
"media_duration",
"(",
"self",
")",
":",
"return",
"self",
".",
"_duration"
] | [
81,
4
] | [
83,
29
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.media_position | (self) | Position of current playing media in seconds. | Position of current playing media in seconds. | def media_position(self):
"""Position of current playing media in seconds."""
return self._position | [
"def",
"media_position",
"(",
"self",
")",
":",
"return",
"self",
".",
"_position"
] | [
86,
4
] | [
88,
29
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.media_position_updated_at | (self) | When was the position of the current playing media valid. | When was the position of the current playing media valid. | def media_position_updated_at(self):
"""When was the position of the current playing media valid."""
return self._position_valid | [
"def",
"media_position_updated_at",
"(",
"self",
")",
":",
"return",
"self",
".",
"_position_valid"
] | [
91,
4
] | [
93,
35
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.update | (self) | Update the internal state by querying the device. | Update the internal state by querying the device. | def update(self):
"""Update the internal state by querying the device."""
# This can take 5+ seconds to complete
state = self._device.get_play_status()
if state[0] == "error":
self._state = None
elif state[0] in ["off", "standby"]:
# We map both of these ... | [
"def",
"update",
"(",
"self",
")",
":",
"# This can take 5+ seconds to complete",
"state",
"=",
"self",
".",
"_device",
".",
"get_play_status",
"(",
")",
"if",
"state",
"[",
"0",
"]",
"==",
"\"error\"",
":",
"self",
".",
"_state",
"=",
"None",
"elif",
"sta... | [
95,
4
] | [
118,
33
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.turn_off | (self) |
Instruct the device to turn standby.
Sending the "POWER" button will turn the device to standby - there
is no way to turn it completely off remotely. However this works in
our favour as it means the device is still accepting commands and we
can thus turn it back on when desired... |
Instruct the device to turn standby. | def turn_off(self):
"""
Instruct the device to turn standby.
Sending the "POWER" button will turn the device to standby - there
is no way to turn it completely off remotely. However this works in
our favour as it means the device is still accepting commands and we
can th... | [
"def",
"turn_off",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
"!=",
"STATE_OFF",
":",
"self",
".",
"_device",
".",
"send_key",
"(",
"\"POWER\"",
")",
"self",
".",
"_state",
"=",
"STATE_OFF"
] | [
120,
4
] | [
132,
31
] | python | en | ['en', 'error', 'th'] | False |
PanasonicBluRay.turn_on | (self) | Wake the device back up from standby. | Wake the device back up from standby. | def turn_on(self):
"""Wake the device back up from standby."""
if self._state == STATE_OFF:
self._device.send_key("POWER")
self._state = STATE_IDLE | [
"def",
"turn_on",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
"==",
"STATE_OFF",
":",
"self",
".",
"_device",
".",
"send_key",
"(",
"\"POWER\"",
")",
"self",
".",
"_state",
"=",
"STATE_IDLE"
] | [
134,
4
] | [
139,
32
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.media_play | (self) | Send play command. | Send play command. | def media_play(self):
"""Send play command."""
self._device.send_key("PLAYBACK") | [
"def",
"media_play",
"(",
"self",
")",
":",
"self",
".",
"_device",
".",
"send_key",
"(",
"\"PLAYBACK\"",
")"
] | [
141,
4
] | [
143,
41
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.media_pause | (self) | Send pause command. | Send pause command. | def media_pause(self):
"""Send pause command."""
self._device.send_key("PAUSE") | [
"def",
"media_pause",
"(",
"self",
")",
":",
"self",
".",
"_device",
".",
"send_key",
"(",
"\"PAUSE\"",
")"
] | [
145,
4
] | [
147,
38
] | python | en | ['en', 'en', 'en'] | True |
PanasonicBluRay.media_stop | (self) | Send stop command. | Send stop command. | def media_stop(self):
"""Send stop command."""
self._device.send_key("STOP") | [
"def",
"media_stop",
"(",
"self",
")",
":",
"self",
".",
"_device",
".",
"send_key",
"(",
"\"STOP\"",
")"
] | [
149,
4
] | [
151,
37
] | python | en | ['en', 'en', 'en'] | True |
convert_speed | (speed: int) | Convert speed from deCONZ to HASS.
Fallback to medium speed if unsupported by HASS fan platform.
| Convert speed from deCONZ to HASS. | def convert_speed(speed: int) -> str:
"""Convert speed from deCONZ to HASS.
Fallback to medium speed if unsupported by HASS fan platform.
"""
if speed in SPEEDS.values():
for hass_speed, deconz_speed in SPEEDS.items():
if speed == deconz_speed:
return hass_speed
... | [
"def",
"convert_speed",
"(",
"speed",
":",
"int",
")",
"->",
"str",
":",
"if",
"speed",
"in",
"SPEEDS",
".",
"values",
"(",
")",
":",
"for",
"hass_speed",
",",
"deconz_speed",
"in",
"SPEEDS",
".",
"items",
"(",
")",
":",
"if",
"speed",
"==",
"deconz_... | [
21,
0
] | [
30,
23
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up fans for deCONZ component.
Fans are based on the same device class as lights in deCONZ.
| Set up fans for deCONZ component. | async def async_setup_entry(hass, config_entry, async_add_entities) -> None:
"""Set up fans for deCONZ component.
Fans are based on the same device class as lights in deCONZ.
"""
gateway = get_gateway_from_config_entry(hass, config_entry)
gateway.entities[DOMAIN] = set()
@callback
def asyn... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
"->",
"None",
":",
"gateway",
"=",
"get_gateway_from_config_entry",
"(",
"hass",
",",
"config_entry",
")",
"gateway",
".",
"entities",
"[",
"DOMAIN",
"]",
"=",... | [
33,
0
] | [
60,
46
] | python | da | ['da', 'fr', 'en'] | False |
DeconzFan.__init__ | (self, device, gateway) | Set up fan. | Set up fan. | def __init__(self, device, gateway) -> None:
"""Set up fan."""
super().__init__(device, gateway)
self._default_on_speed = SPEEDS[SPEED_MEDIUM]
if self.speed != SPEED_OFF:
self._default_on_speed = self._device.speed
self._features = SUPPORT_SET_SPEED | [
"def",
"__init__",
"(",
"self",
",",
"device",
",",
"gateway",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"device",
",",
"gateway",
")",
"self",
".",
"_default_on_speed",
"=",
"SPEEDS",
"[",
"SPEED_MEDIUM",
"]",
"if",
"self",
".",... | [
68,
4
] | [
76,
42
] | python | en | ['en', 'fy', 'en'] | True |
DeconzFan.is_on | (self) | Return true if fan is on. | Return true if fan is on. | def is_on(self) -> bool:
"""Return true if fan is on."""
return self.speed != SPEED_OFF | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"speed",
"!=",
"SPEED_OFF"
] | [
79,
4
] | [
81,
38
] | python | en | ['en', 'fy', 'en'] | True |
DeconzFan.speed | (self) | Return the current speed. | Return the current speed. | def speed(self) -> int:
"""Return the current speed."""
return convert_speed(self._device.speed) | [
"def",
"speed",
"(",
"self",
")",
"->",
"int",
":",
"return",
"convert_speed",
"(",
"self",
".",
"_device",
".",
"speed",
")"
] | [
84,
4
] | [
86,
48
] | python | en | ['en', 'en', 'en'] | True |
DeconzFan.speed_list | (self) | Get the list of available speeds. | Get the list of available speeds. | def speed_list(self) -> list:
"""Get the list of available speeds."""
return list(SPEEDS) | [
"def",
"speed_list",
"(",
"self",
")",
"->",
"list",
":",
"return",
"list",
"(",
"SPEEDS",
")"
] | [
89,
4
] | [
91,
27
] | python | en | ['en', 'en', 'en'] | True |
DeconzFan.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self) -> int:
"""Flag supported features."""
return self._features | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_features"
] | [
94,
4
] | [
96,
29
] | python | en | ['da', 'en', 'en'] | True |
DeconzFan.async_update_callback | (self, force_update=False) | Store latest configured speed from the device. | Store latest configured speed from the device. | def async_update_callback(self, force_update=False) -> None:
"""Store latest configured speed from the device."""
if self.speed != SPEED_OFF and self._device.speed != self._default_on_speed:
self._default_on_speed = self._device.speed
super().async_update_callback(force_update) | [
"def",
"async_update_callback",
"(",
"self",
",",
"force_update",
"=",
"False",
")",
"->",
"None",
":",
"if",
"self",
".",
"speed",
"!=",
"SPEED_OFF",
"and",
"self",
".",
"_device",
".",
"speed",
"!=",
"self",
".",
"_default_on_speed",
":",
"self",
".",
... | [
99,
4
] | [
103,
51
] | python | en | ['en', 'en', 'en'] | True |
DeconzFan.async_set_speed | (self, speed: str) | Set the speed of the fan. | Set the speed of the fan. | async def async_set_speed(self, speed: str) -> None:
"""Set the speed of the fan."""
if speed not in SPEEDS:
raise ValueError(f"Unsupported speed {speed}")
data = {"speed": SPEEDS[speed]}
await self._device.async_set_state(data) | [
"async",
"def",
"async_set_speed",
"(",
"self",
",",
"speed",
":",
"str",
")",
"->",
"None",
":",
"if",
"speed",
"not",
"in",
"SPEEDS",
":",
"raise",
"ValueError",
"(",
"f\"Unsupported speed {speed}\"",
")",
"data",
"=",
"{",
"\"speed\"",
":",
"SPEEDS",
"[... | [
105,
4
] | [
112,
48
] | python | en | ['en', 'en', 'en'] | True |
DeconzFan.async_turn_on | (self, speed: str = None, **kwargs) | Turn on fan. | Turn on fan. | async def async_turn_on(self, speed: str = None, **kwargs) -> None:
"""Turn on fan."""
if not speed:
speed = convert_speed(self._default_on_speed)
await self.async_set_speed(speed) | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"speed",
":",
"str",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"if",
"not",
"speed",
":",
"speed",
"=",
"convert_speed",
"(",
"self",
".",
"_default_on_speed",
")",
"await",
"self",... | [
114,
4
] | [
118,
41
] | python | en | ['en', 'fy', 'en'] | True |
DeconzFan.async_turn_off | (self, **kwargs) | Turn off fan. | Turn off fan. | async def async_turn_off(self, **kwargs) -> None:
"""Turn off fan."""
await self.async_set_speed(SPEED_OFF) | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"await",
"self",
".",
"async_set_speed",
"(",
"SPEED_OFF",
")"
] | [
120,
4
] | [
122,
45
] | python | en | ['en', 'fy', 'en'] | True |
gen_send_stdout_url | (ip, port) | Generate send stdout url | Generate send stdout url | def gen_send_stdout_url(ip, port):
'''Generate send stdout url'''
return '{0}:{1}{2}{3}/{4}/{5}'.format(BASE_URL.format(ip), port, API_ROOT_URL, STDOUT_API, NNI_EXP_ID, NNI_TRIAL_JOB_ID) | [
"def",
"gen_send_stdout_url",
"(",
"ip",
",",
"port",
")",
":",
"return",
"'{0}:{1}{2}{3}/{4}/{5}'",
".",
"format",
"(",
"BASE_URL",
".",
"format",
"(",
"ip",
")",
",",
"port",
",",
"API_ROOT_URL",
",",
"STDOUT_API",
",",
"NNI_EXP_ID",
",",
"NNI_TRIAL_JOB_ID",... | [
6,
0
] | [
8,
124
] | python | co | ['en', 'co', 'it'] | False |
gen_send_version_url | (ip, port) | Generate send error url | Generate send error url | def gen_send_version_url(ip, port):
'''Generate send error url'''
return '{0}:{1}{2}{3}/{4}/{5}'.format(BASE_URL.format(ip), port, API_ROOT_URL, VERSION_API, NNI_EXP_ID, NNI_TRIAL_JOB_ID) | [
"def",
"gen_send_version_url",
"(",
"ip",
",",
"port",
")",
":",
"return",
"'{0}:{1}{2}{3}/{4}/{5}'",
".",
"format",
"(",
"BASE_URL",
".",
"format",
"(",
"ip",
")",
",",
"port",
",",
"API_ROOT_URL",
",",
"VERSION_API",
",",
"NNI_EXP_ID",
",",
"NNI_TRIAL_JOB_ID... | [
11,
0
] | [
13,
125
] | python | en | ['en', 'co', 'en'] | True |
gen_parameter_meta_url | (ip, port) | Generate send error url | Generate send error url | def gen_parameter_meta_url(ip, port):
'''Generate send error url'''
return '{0}:{1}{2}{3}'.format(BASE_URL.format(ip), port, API_ROOT_URL, PARAMETER_META_API) | [
"def",
"gen_parameter_meta_url",
"(",
"ip",
",",
"port",
")",
":",
"return",
"'{0}:{1}{2}{3}'",
".",
"format",
"(",
"BASE_URL",
".",
"format",
"(",
"ip",
")",
",",
"port",
",",
"API_ROOT_URL",
",",
"PARAMETER_META_API",
")"
] | [
16,
0
] | [
18,
94
] | python | en | ['en', 'co', 'en'] | True |
authenticate | (hass, host, security_code) | Authenticate with a Tradfri hub. | Authenticate with a Tradfri hub. | async def authenticate(hass, host, security_code):
"""Authenticate with a Tradfri hub."""
identity = uuid4().hex
api_factory = await APIFactory.init(host, psk_id=identity)
try:
with async_timeout.timeout(5):
key = await api_factory.generate_psk(security_code)
except RequestErr... | [
"async",
"def",
"authenticate",
"(",
"hass",
",",
"host",
",",
"security_code",
")",
":",
"identity",
"=",
"uuid4",
"(",
")",
".",
"hex",
"api_factory",
"=",
"await",
"APIFactory",
".",
"init",
"(",
"host",
",",
"psk_id",
"=",
"identity",
")",
"try",
"... | [
158,
0
] | [
175,
60
] | python | en | ['en', 'en', 'en'] | True |
get_gateway_info | (hass, host, identity, key) | Return info for the gateway. | Return info for the gateway. | async def get_gateway_info(hass, host, identity, key):
"""Return info for the gateway."""
try:
factory = await APIFactory.init(host, psk_id=identity, psk=key)
api = factory.request
gateway = Gateway()
gateway_info_result = await api(gateway.get_gateway_info())
await fa... | [
"async",
"def",
"get_gateway_info",
"(",
"hass",
",",
"host",
",",
"identity",
",",
"key",
")",
":",
"try",
":",
"factory",
"=",
"await",
"APIFactory",
".",
"init",
"(",
"host",
",",
"psk_id",
"=",
"identity",
",",
"psk",
"=",
"key",
")",
"api",
"=",... | [
178,
0
] | [
199,
5
] | python | en | ['en', 'no', 'en'] | True |
AuthError.__init__ | (self, code) | Initialize exception. | Initialize exception. | def __init__(self, code):
"""Initialize exception."""
super().__init__()
self.code = code | [
"def",
"__init__",
"(",
"self",
",",
"code",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"code",
"=",
"code"
] | [
24,
4
] | [
27,
24
] | python | en | ['es', 'en', 'en'] | False |
create_mnist_model | (hyper_params, input_shape=(H, W, 1), num_classes=NUM_CLASSES) |
Create simple convolutional model
|
Create simple convolutional model
| def create_mnist_model(hyper_params, input_shape=(H, W, 1), num_classes=NUM_CLASSES):
'''
Create simple convolutional model
'''
layers = [
Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D(pool_size=(2,... | [
"def",
"create_mnist_model",
"(",
"hyper_params",
",",
"input_shape",
"=",
"(",
"H",
",",
"W",
",",
"1",
")",
",",
"num_classes",
"=",
"NUM_CLASSES",
")",
":",
"layers",
"=",
"[",
"Conv2D",
"(",
"32",
",",
"kernel_size",
"=",
"(",
"3",
",",
"3",
")",... | [
38,
0
] | [
59,
16
] | python | en | ['en', 'error', 'th'] | False |
load_mnist_data | (args) |
Load MNIST dataset
|
Load MNIST dataset
| def load_mnist_data(args):
'''
Load MNIST dataset
'''
mnist_path = os.path.join(os.environ.get('NNI_OUTPUT_DIR'), 'mnist.npz')
(x_train, y_train), (x_test, y_test) = mnist.load_data(path=mnist_path)
os.remove(mnist_path)
x_train = (np.expand_dims(x_train, -1).astype(np.float) / 255.)[:args.... | [
"def",
"load_mnist_data",
"(",
"args",
")",
":",
"mnist_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'NNI_OUTPUT_DIR'",
")",
",",
"'mnist.npz'",
")",
"(",
"x_train",
",",
"y_train",
")",
",",
"(",
"x_test",
... | [
61,
0
] | [
77,
43
] | python | en | ['en', 'error', 'th'] | False |
train | (args, params) |
Train model
|
Train model
| def train(args, params):
'''
Train model
'''
x_train, y_train, x_test, y_test = load_mnist_data(args)
model = create_mnist_model(params)
model.fit(x_train, y_train, batch_size=args.batch_size, epochs=args.epochs, verbose=1,
validation_data=(x_test, y_test), callbacks=[SendMetrics(), Ten... | [
"def",
"train",
"(",
"args",
",",
"params",
")",
":",
"x_train",
",",
"y_train",
",",
"x_test",
",",
"y_test",
"=",
"load_mnist_data",
"(",
"args",
")",
"model",
"=",
"create_mnist_model",
"(",
"params",
")",
"model",
".",
"fit",
"(",
"x_train",
",",
"... | [
94,
0
] | [
106,
32
] | python | en | ['en', 'error', 'th'] | False |
generate_default_params | () |
Generate default hyper parameters
|
Generate default hyper parameters
| def generate_default_params():
'''
Generate default hyper parameters
'''
return {
'optimizer': 'Adam',
'learning_rate': 0.001
} | [
"def",
"generate_default_params",
"(",
")",
":",
"return",
"{",
"'optimizer'",
":",
"'Adam'",
",",
"'learning_rate'",
":",
"0.001",
"}"
] | [
108,
0
] | [
115,
5
] | python | en | ['en', 'error', 'th'] | False |
SendMetrics.on_epoch_end | (self, epoch, logs={}) |
Run on end of each epoch
|
Run on end of each epoch
| def on_epoch_end(self, epoch, logs={}):
'''
Run on end of each epoch
'''
LOG.debug(logs)
# TensorFlow 2.0 API reference claims the key is `val_acc`, but in fact it's `val_accuracy`
if 'val_acc' in logs:
nni.report_intermediate_result(logs['val_acc'])
e... | [
"def",
"on_epoch_end",
"(",
"self",
",",
"epoch",
",",
"logs",
"=",
"{",
"}",
")",
":",
"LOG",
".",
"debug",
"(",
"logs",
")",
"# TensorFlow 2.0 API reference claims the key is `val_acc`, but in fact it's `val_accuracy`",
"if",
"'val_acc'",
"in",
"logs",
":",
"nni",... | [
83,
4
] | [
92,
64
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.__init__ | (self, host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD, **kwargs) |
init redis client
:param host: redis host
:param port: redis port
:param password: redis password
|
init redis client
:param host: redis host
:param port: redis port
:param password: redis password
| def __init__(self, host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD, **kwargs):
"""
init redis client
:param host: redis host
:param port: redis port
:param password: redis password
"""
self.db = redis.StrictRedis(host=host, port=port, password=password, ... | [
"def",
"__init__",
"(",
"self",
",",
"host",
"=",
"REDIS_HOST",
",",
"port",
"=",
"REDIS_PORT",
",",
"password",
"=",
"REDIS_PASSWORD",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"db",
"=",
"redis",
".",
"StrictRedis",
"(",
"host",
"=",
"host",
... | [
20,
4
] | [
27,
109
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.add | (self, proxy: Proxy, score=PROXY_SCORE_INIT) |
add proxy and set it to init score
:param proxy: proxy, ip:port, like 8.8.8.8:88
:param score: int score
:return: result
|
add proxy and set it to init score
:param proxy: proxy, ip:port, like 8.8.8.8:88
:param score: int score
:return: result
| def add(self, proxy: Proxy, score=PROXY_SCORE_INIT) -> int:
"""
add proxy and set it to init score
:param proxy: proxy, ip:port, like 8.8.8.8:88
:param score: int score
:return: result
"""
if not is_valid_proxy(f'{proxy.host}:{proxy.port}'):
logger.inf... | [
"def",
"add",
"(",
"self",
",",
"proxy",
":",
"Proxy",
",",
"score",
"=",
"PROXY_SCORE_INIT",
")",
"->",
"int",
":",
"if",
"not",
"is_valid_proxy",
"(",
"f'{proxy.host}:{proxy.port}'",
")",
":",
"logger",
".",
"info",
"(",
"f'invalid proxy {proxy}, throw it'",
... | [
29,
4
] | [
42,
67
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.random | (self) |
get random proxy
firstly try to get proxy with max score
if not exists, try to get proxy by rank
if not exists, raise error
:return: proxy, like 8.8.8.8:8
|
get random proxy
firstly try to get proxy with max score
if not exists, try to get proxy by rank
if not exists, raise error
:return: proxy, like 8.8.8.8:8
| def random(self) -> Proxy:
"""
get random proxy
firstly try to get proxy with max score
if not exists, try to get proxy by rank
if not exists, raise error
:return: proxy, like 8.8.8.8:8
"""
# try to get proxy with max score
proxies = self.db.zrange... | [
"def",
"random",
"(",
"self",
")",
"->",
"Proxy",
":",
"# try to get proxy with max score",
"proxies",
"=",
"self",
".",
"db",
".",
"zrangebyscore",
"(",
"REDIS_KEY",
",",
"PROXY_SCORE_MAX",
",",
"PROXY_SCORE_MAX",
")",
"if",
"len",
"(",
"proxies",
")",
":",
... | [
44,
4
] | [
61,
32
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.decrease | (self, proxy: Proxy) |
decrease score of proxy, if small than PROXY_SCORE_MIN, delete it
:param proxy: proxy
:return: new score
|
decrease score of proxy, if small than PROXY_SCORE_MIN, delete it
:param proxy: proxy
:return: new score
| def decrease(self, proxy: Proxy) -> int:
"""
decrease score of proxy, if small than PROXY_SCORE_MIN, delete it
:param proxy: proxy
:return: new score
"""
score = self.db.zscore(REDIS_KEY, proxy.string())
# current score is larger than PROXY_SCORE_MIN
if sc... | [
"def",
"decrease",
"(",
"self",
",",
"proxy",
":",
"Proxy",
")",
"->",
"int",
":",
"score",
"=",
"self",
".",
"db",
".",
"zscore",
"(",
"REDIS_KEY",
",",
"proxy",
".",
"string",
"(",
")",
")",
"# current score is larger than PROXY_SCORE_MIN",
"if",
"score"... | [
63,
4
] | [
79,
58
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.exists | (self, proxy: Proxy) |
if proxy exists
:param proxy: proxy
:return: if exists, bool
|
if proxy exists
:param proxy: proxy
:return: if exists, bool
| def exists(self, proxy: Proxy) -> bool:
"""
if proxy exists
:param proxy: proxy
:return: if exists, bool
"""
return not self.db.zscore(REDIS_KEY, proxy.string()) is None | [
"def",
"exists",
"(",
"self",
",",
"proxy",
":",
"Proxy",
")",
"->",
"bool",
":",
"return",
"not",
"self",
".",
"db",
".",
"zscore",
"(",
"REDIS_KEY",
",",
"proxy",
".",
"string",
"(",
")",
")",
"is",
"None"
] | [
81,
4
] | [
87,
68
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.max | (self, proxy: Proxy) |
set proxy to max score
:param proxy: proxy
:return: new score
|
set proxy to max score
:param proxy: proxy
:return: new score
| def max(self, proxy: Proxy) -> int:
"""
set proxy to max score
:param proxy: proxy
:return: new score
"""
logger.info(f'{proxy.string()} is valid, set to {PROXY_SCORE_MAX}')
if IS_REDIS_VERSION_2:
return self.db.zadd(REDIS_KEY, PROXY_SCORE_MAX, proxy.s... | [
"def",
"max",
"(",
"self",
",",
"proxy",
":",
"Proxy",
")",
"->",
"int",
":",
"logger",
".",
"info",
"(",
"f'{proxy.string()} is valid, set to {PROXY_SCORE_MAX}'",
")",
"if",
"IS_REDIS_VERSION_2",
":",
"return",
"self",
".",
"db",
".",
"zadd",
"(",
"REDIS_KEY"... | [
89,
4
] | [
98,
73
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.count | (self) |
get count of proxies
:return: count, int
|
get count of proxies
:return: count, int
| def count(self) -> int:
"""
get count of proxies
:return: count, int
"""
return self.db.zcard(REDIS_KEY) | [
"def",
"count",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"db",
".",
"zcard",
"(",
"REDIS_KEY",
")"
] | [
100,
4
] | [
105,
39
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.all | (self) |
get all proxies
:return: list of proxies
|
get all proxies
:return: list of proxies
| def all(self) -> List[Proxy]:
"""
get all proxies
:return: list of proxies
"""
return convert_proxy_or_proxies(self.db.zrangebyscore(REDIS_KEY, PROXY_SCORE_MIN, PROXY_SCORE_MAX)) | [
"def",
"all",
"(",
"self",
")",
"->",
"List",
"[",
"Proxy",
"]",
":",
"return",
"convert_proxy_or_proxies",
"(",
"self",
".",
"db",
".",
"zrangebyscore",
"(",
"REDIS_KEY",
",",
"PROXY_SCORE_MIN",
",",
"PROXY_SCORE_MAX",
")",
")"
] | [
107,
4
] | [
112,
107
] | python | en | ['en', 'error', 'th'] | False |
RedisClient.batch | (self, start, end) |
get batch of proxies
:param start: start index
:param end: end index
:return: list of proxies
|
get batch of proxies
:param start: start index
:param end: end index
:return: list of proxies
| def batch(self, start, end) -> List[Proxy]:
"""
get batch of proxies
:param start: start index
:param end: end index
:return: list of proxies
"""
return convert_proxy_or_proxies(self.db.zrevrange(REDIS_KEY, start, end - 1)) | [
"def",
"batch",
"(",
"self",
",",
"start",
",",
"end",
")",
"->",
"List",
"[",
"Proxy",
"]",
":",
"return",
"convert_proxy_or_proxies",
"(",
"self",
".",
"db",
".",
"zrevrange",
"(",
"REDIS_KEY",
",",
"start",
",",
"end",
"-",
"1",
")",
")"
] | [
114,
4
] | [
121,
85
] | python | en | ['en', 'error', 'th'] | False |
CertexpiryConfigFlow.__init__ | (self) | Initialize the config flow. | Initialize the config flow. | def __init__(self) -> None:
"""Initialize the config flow."""
self._errors = {} | [
"def",
"__init__",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"_errors",
"=",
"{",
"}"
] | [
26,
4
] | [
28,
25
] | python | en | ['en', 'en', 'en'] | True |
CertexpiryConfigFlow._test_connection | (self, user_input=None) | Test connection to the server and try to get the certificate. | Test connection to the server and try to get the certificate. | async def _test_connection(self, user_input=None):
"""Test connection to the server and try to get the certificate."""
try:
await get_cert_expiry_timestamp(
self.hass,
user_input[CONF_HOST],
user_input.get(CONF_PORT, DEFAULT_PORT),
... | [
"async",
"def",
"_test_connection",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"try",
":",
"await",
"get_cert_expiry_timestamp",
"(",
"self",
".",
"hass",
",",
"user_input",
"[",
"CONF_HOST",
"]",
",",
"user_input",
".",
"get",
"(",
"CONF_PORT",
... | [
30,
4
] | [
47,
20
] | python | en | ['en', 'en', 'en'] | True |
CertexpiryConfigFlow.async_step_user | (self, user_input=None) | Step when user initializes a integration. | Step when user initializes a integration. | async def async_step_user(self, user_input=None):
"""Step when user initializes a integration."""
self._errors = {}
if user_input is not None:
host = user_input[CONF_HOST]
port = user_input.get(CONF_PORT, DEFAULT_PORT)
await self.async_set_unique_id(f"{host}:{... | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"self",
".",
"_errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"host",
"=",
"user_input",
"[",
"CONF_HOST",
"]",
"port",
"=",
"user_input",
... | [
49,
4
] | [
86,
9
] | python | en | ['en', 'en', 'en'] | True |
CertexpiryConfigFlow.async_step_import | (self, user_input=None) | Import a config entry.
Only host was required in the yaml file all other fields are optional
| Import a config entry. | async def async_step_import(self, user_input=None):
"""Import a config entry.
Only host was required in the yaml file all other fields are optional
"""
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",
")"
] | [
88,
4
] | [
93,
53
] | python | en | ['en', 'en', 'en'] | True |
__init__ | (
self,
vocab_file,
unk_token="<|endoftext|>",
bos_token="<|endoftext|>",
eos_token="<|endoftext|>",
**kwargs
) | Initialisation | Initialisation | def __init__(
self,
vocab_file,
unk_token="<|endoftext|>",
bos_token="<|endoftext|>",
eos_token="<|endoftext|>",
**kwargs
):
bos_token = AddedToken(bos_token, lstrip=False, rstrip=False) if isinstance(bos_token, str) else bos_token
... | [
"def",
"__init__",
"(",
"self",
",",
"vocab_file",
",",
"unk_token",
"=",
"\"<|endoftext|>\"",
",",
"bos_token",
"=",
"\"<|endoftext|>\"",
",",
"eos_token",
"=",
"\"<|endoftext|>\"",
",",
"*",
"*",
"kwargs",
")",
":",
"bos_token",
"=",
"AddedToken",
"(",
"bos_... | [
136,
4
] | [
149,
24
] | python | de | ['fr', 'zu', 'de'] | False |
vocab_size | (self) | Returns vocab size | Returns vocab size | def vocab_size(self):
"Returns vocab size" | [
"def",
"vocab_size",
"(",
"self",
")",
":"
] | [
152,
4
] | [
153,
28
] | python | de | ['de', 'fr', 'en'] | False |
get_vocab | (self) | Returns vocab as a dict | Returns vocab as a dict | def get_vocab(self):
"Returns vocab as a dict" | [
"def",
"get_vocab",
"(",
"self",
")",
":"
] | [
155,
4
] | [
156,
33
] | python | en | ['en', 'pt', 'en'] | True |
_tokenize | (self, text) | Returns a tokenized string. | Returns a tokenized string. | def _tokenize(self, text):
""" Returns a tokenized string. """ | [
"def",
"_tokenize",
"(",
"self",
",",
"text",
")",
":"
] | [
158,
4
] | [
159,
43
] | python | en | ['en', 'no', 'en'] | True |
_convert_token_to_id | (self, token) | Converts a token (str) in an id using the vocab. | Converts a token (str) in an id using the vocab. | def _convert_token_to_id(self, token):
""" Converts a token (str) in an id using the vocab. """ | [
"def",
"_convert_token_to_id",
"(",
"self",
",",
"token",
")",
":"
] | [
161,
4
] | [
162,
64
] | python | en | ['en', 'en', 'en'] | True |
_convert_id_to_token | (self, index) | Converts an index (integer) in a token (str) using the vocab. | Converts an index (integer) in a token (str) using the vocab. | def _convert_id_to_token(self, index):
"""Converts an index (integer) in a token (str) using the vocab.""" | [
"def",
"_convert_id_to_token",
"(",
"self",
",",
"index",
")",
":"
] | [
164,
4
] | [
165,
75
] | python | en | ['en', 'en', 'en'] | True |
convert_tokens_to_string | (self, tokens) | Converts a sequence of tokens (string) in a single string. | Converts a sequence of tokens (string) in a single string. | def convert_tokens_to_string(self, tokens):
""" Converts a sequence of tokens (string) in a single string. """ | [
"def",
"convert_tokens_to_string",
"(",
"self",
",",
"tokens",
")",
":"
] | [
167,
4
] | [
168,
74
] | python | en | ['en', 'en', 'en'] | True |
save_vocabulary | (self, save_directory) |
Save the vocabulary and special tokens file to a directory.
Args:
save_directory (:obj:`str`):
The directory in which to save the vocabulary.
Returns:
:obj:`Tuple(str)`: Paths to the files saved.
|
Save the vocabulary and special tokens file to a directory. | def save_vocabulary(self, save_directory):
"""
Save the vocabulary and special tokens file to a directory.
Args:
save_directory (:obj:`str`):
The directory in which to save the vocabulary.
Returns:
:obj:`Tuple(str)`: Paths to the files saved.
... | [
"def",
"save_vocabulary",
"(",
"self",
",",
"save_directory",
")",
":"
] | [
170,
4
] | [
180,
11
] | python | en | ['en', 'error', 'th'] | False |
build_inputs_with_special_tokens | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) |
Build model inputs from a sequence or a pair of sequence for sequence classification tasks
by concatenating and adding special tokens.
A {{cookiecutter.modelname}} sequence has the following format:
- single sequence: ``<s> X </s>``
- pair of sequences: ``<s> A </s></s> B </s>`... |
Build model inputs from a sequence or a pair of sequence for sequence classification tasks
by concatenating and adding special tokens.
A {{cookiecutter.modelname}} sequence has the following format: | def build_inputs_with_special_tokens(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Build model inputs from a sequence or a pair of sequence for sequence classification tasks
by concatenating and adding special tokens.
A {{cooki... | [
"def",
"build_inputs_with_special_tokens",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
")",
"->",
"List",
"[",
"int",
"]",
":",
"if",
"token_ids_1",
... | [
182,
4
] | [
206,
64
] | python | en | ['en', 'error', 'th'] | False |
get_special_tokens_mask | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
) |
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer ``prepare_for_model`` method.
Args:
token_ids_0 (:obj:`List[int]`):
List of IDs.
token_ids_1 (:obj:`List[int]`,... |
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer ``prepare_for_model`` method. | def get_special_tokens_mask(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
) -> List[int]:
"""
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tok... | [
"def",
"get_special_tokens_mask",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
",",
"already_has_special_tokens",
":",
"bool",
"=",
"False",
")",
"->",
... | [
208,
4
] | [
236,
87
] | python | en | ['en', 'error', 'th'] | False |
create_token_type_ids_from_sequences | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) |
Create a mask from the two sequences passed to be used in a sequence-pair classification task.
{{cookiecutter.modelname}} does not make use of token type ids, therefore a list of zeros is returned.
Args:
token_ids_0 (:obj:`List[int]`):
List of IDs.
token... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task.
{{cookiecutter.modelname}} does not make use of token type ids, therefore a list of zeros is returned. | def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task.
{{cookiecutter.modelname}} does not make use of token... | [
"def",
"create_token_type_ids_from_sequences",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
")",
"->",
"List",
"[",
"int",
"]",
":",
"sep",
"=",
"[",... | [
238,
4
] | [
259,
75
] | python | en | ['en', 'error', 'th'] | False |
create_token_type_ids_from_sequences | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) |
Create a mask from the two sequences passed to be used in a sequence-pair classification task.
{{cookiecutter.modelname}} does not make use of token type ids, therefore a list of zeros is returned.
Args:
token_ids_0 (:obj:`List[int]`):
List of IDs.
token... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task.
{{cookiecutter.modelname}} does not make use of token type ids, therefore a list of zeros is returned. | def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task.
{{cookiecutter.modelname}} does not make use of token... | [
"def",
"create_token_type_ids_from_sequences",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
")",
"->",
"List",
"[",
"int",
"]",
":",
"sep",
"=",
"[",... | [
314,
4
] | [
335,
75
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.