Search is not available for this dataset
identifier
stringlengths 1
155
| parameters
stringlengths 2
6.09k
| docstring
stringlengths 11
63.4k
| docstring_summary
stringlengths 0
63.4k
| function
stringlengths 29
99.8k
| function_tokens
sequence | start_point
sequence | end_point
sequence | language
stringclasses 1
value | docstring_language
stringlengths 2
7
| docstring_language_predictions
stringlengths 18
23
| is_langid_reliable
stringclasses 2
values |
---|---|---|---|---|---|---|---|---|---|---|---|
MQTTRoomSensor.update | (self) | Update the state for absent devices. | Update the state for absent devices. | def update(self):
"""Update the state for absent devices."""
if (
self._updated
and self._consider_home
and dt.utcnow() - self._updated > self._consider_home
):
self._state = STATE_NOT_HOME | [
"def",
"update",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"_updated",
"and",
"self",
".",
"_consider_home",
"and",
"dt",
".",
"utcnow",
"(",
")",
"-",
"self",
".",
"_updated",
">",
"self",
".",
"_consider_home",
")",
":",
"self",
".",
"_state",
"=",
"STATE_NOT_HOME"
] | [
141,
4
] | [
148,
40
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Alpha Vantage sensor. | Set up the Alpha Vantage sensor. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Alpha Vantage sensor."""
api_key = config[CONF_API_KEY]
symbols = config.get(CONF_SYMBOLS, [])
conversions = config.get(CONF_FOREIGN_EXCHANGE, [])
if not symbols and not conversions:
msg = "No symbols or currencies configured."
hass.components.persistent_notification.create(msg, "Sensor alpha_vantage")
_LOGGER.warning(msg)
return
timeseries = TimeSeries(key=api_key)
dev = []
for symbol in symbols:
try:
_LOGGER.debug("Configuring timeseries for symbols: %s", symbol[CONF_SYMBOL])
timeseries.get_intraday(symbol[CONF_SYMBOL])
except ValueError:
_LOGGER.error("API Key is not valid or symbol '%s' not known", symbol)
dev.append(AlphaVantageSensor(timeseries, symbol))
forex = ForeignExchange(key=api_key)
for conversion in conversions:
from_cur = conversion.get(CONF_FROM)
to_cur = conversion.get(CONF_TO)
try:
_LOGGER.debug("Configuring forex %s - %s", from_cur, to_cur)
forex.get_currency_exchange_rate(from_currency=from_cur, to_currency=to_cur)
except ValueError as error:
_LOGGER.error(
"API Key is not valid or currencies '%s'/'%s' not known",
from_cur,
to_cur,
)
_LOGGER.debug(str(error))
dev.append(AlphaVantageForeignExchange(forex, conversion))
add_entities(dev, True)
_LOGGER.debug("Setup completed") | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"api_key",
"=",
"config",
"[",
"CONF_API_KEY",
"]",
"symbols",
"=",
"config",
".",
"get",
"(",
"CONF_SYMBOLS",
",",
"[",
"]",
")",
"conversions",
"=",
"config",
".",
"get",
"(",
"CONF_FOREIGN_EXCHANGE",
",",
"[",
"]",
")",
"if",
"not",
"symbols",
"and",
"not",
"conversions",
":",
"msg",
"=",
"\"No symbols or currencies configured.\"",
"hass",
".",
"components",
".",
"persistent_notification",
".",
"create",
"(",
"msg",
",",
"\"Sensor alpha_vantage\"",
")",
"_LOGGER",
".",
"warning",
"(",
"msg",
")",
"return",
"timeseries",
"=",
"TimeSeries",
"(",
"key",
"=",
"api_key",
")",
"dev",
"=",
"[",
"]",
"for",
"symbol",
"in",
"symbols",
":",
"try",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Configuring timeseries for symbols: %s\"",
",",
"symbol",
"[",
"CONF_SYMBOL",
"]",
")",
"timeseries",
".",
"get_intraday",
"(",
"symbol",
"[",
"CONF_SYMBOL",
"]",
")",
"except",
"ValueError",
":",
"_LOGGER",
".",
"error",
"(",
"\"API Key is not valid or symbol '%s' not known\"",
",",
"symbol",
")",
"dev",
".",
"append",
"(",
"AlphaVantageSensor",
"(",
"timeseries",
",",
"symbol",
")",
")",
"forex",
"=",
"ForeignExchange",
"(",
"key",
"=",
"api_key",
")",
"for",
"conversion",
"in",
"conversions",
":",
"from_cur",
"=",
"conversion",
".",
"get",
"(",
"CONF_FROM",
")",
"to_cur",
"=",
"conversion",
".",
"get",
"(",
"CONF_TO",
")",
"try",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Configuring forex %s - %s\"",
",",
"from_cur",
",",
"to_cur",
")",
"forex",
".",
"get_currency_exchange_rate",
"(",
"from_currency",
"=",
"from_cur",
",",
"to_currency",
"=",
"to_cur",
")",
"except",
"ValueError",
"as",
"error",
":",
"_LOGGER",
".",
"error",
"(",
"\"API Key is not valid or currencies '%s'/'%s' not known\"",
",",
"from_cur",
",",
"to_cur",
",",
")",
"_LOGGER",
".",
"debug",
"(",
"str",
"(",
"error",
")",
")",
"dev",
".",
"append",
"(",
"AlphaVantageForeignExchange",
"(",
"forex",
",",
"conversion",
")",
")",
"add_entities",
"(",
"dev",
",",
"True",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Setup completed\"",
")"
] | [
64,
0
] | [
104,
36
] | python | en | ['en', 'ca', 'en'] | True |
AlphaVantageSensor.__init__ | (self, timeseries, symbol) | Initialize the sensor. | Initialize the sensor. | def __init__(self, timeseries, symbol):
"""Initialize the sensor."""
self._symbol = symbol[CONF_SYMBOL]
self._name = symbol.get(CONF_NAME, self._symbol)
self._timeseries = timeseries
self.values = None
self._unit_of_measurement = symbol.get(CONF_CURRENCY, self._symbol)
self._icon = ICONS.get(symbol.get(CONF_CURRENCY, "USD")) | [
"def",
"__init__",
"(",
"self",
",",
"timeseries",
",",
"symbol",
")",
":",
"self",
".",
"_symbol",
"=",
"symbol",
"[",
"CONF_SYMBOL",
"]",
"self",
".",
"_name",
"=",
"symbol",
".",
"get",
"(",
"CONF_NAME",
",",
"self",
".",
"_symbol",
")",
"self",
".",
"_timeseries",
"=",
"timeseries",
"self",
".",
"values",
"=",
"None",
"self",
".",
"_unit_of_measurement",
"=",
"symbol",
".",
"get",
"(",
"CONF_CURRENCY",
",",
"self",
".",
"_symbol",
")",
"self",
".",
"_icon",
"=",
"ICONS",
".",
"get",
"(",
"symbol",
".",
"get",
"(",
"CONF_CURRENCY",
",",
"\"USD\"",
")",
")"
] | [
110,
4
] | [
117,
64
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageSensor.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"
] | [
120,
4
] | [
122,
25
] | python | en | ['en', 'mi', 'en'] | True |
AlphaVantageSensor.unit_of_measurement | (self) | Return the unit of measurement of this entity, if any. | Return the unit of measurement of this entity, if any. | def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
125,
4
] | [
127,
40
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self.values["1. open"] | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"values",
"[",
"\"1. open\"",
"]"
] | [
130,
4
] | [
132,
37
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self.values is not None:
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_CLOSE: self.values["4. close"],
ATTR_HIGH: self.values["2. high"],
ATTR_LOW: self.values["3. low"],
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"values",
"is",
"not",
"None",
":",
"return",
"{",
"ATTR_ATTRIBUTION",
":",
"ATTRIBUTION",
",",
"ATTR_CLOSE",
":",
"self",
".",
"values",
"[",
"\"4. close\"",
"]",
",",
"ATTR_HIGH",
":",
"self",
".",
"values",
"[",
"\"2. high\"",
"]",
",",
"ATTR_LOW",
":",
"self",
".",
"values",
"[",
"\"3. low\"",
"]",
",",
"}"
] | [
135,
4
] | [
143,
13
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageSensor.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
146,
4
] | [
148,
25
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageSensor.update | (self) | Get the latest data and updates the states. | Get the latest data and updates the states. | def update(self):
"""Get the latest data and updates the states."""
_LOGGER.debug("Requesting new data for symbol %s", self._symbol)
all_values, _ = self._timeseries.get_intraday(self._symbol)
self.values = next(iter(all_values.values()))
_LOGGER.debug("Received new values for symbol %s", self._symbol) | [
"def",
"update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Requesting new data for symbol %s\"",
",",
"self",
".",
"_symbol",
")",
"all_values",
",",
"_",
"=",
"self",
".",
"_timeseries",
".",
"get_intraday",
"(",
"self",
".",
"_symbol",
")",
"self",
".",
"values",
"=",
"next",
"(",
"iter",
"(",
"all_values",
".",
"values",
"(",
")",
")",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Received new values for symbol %s\"",
",",
"self",
".",
"_symbol",
")"
] | [
150,
4
] | [
155,
72
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageForeignExchange.__init__ | (self, foreign_exchange, config) | Initialize the sensor. | Initialize the sensor. | def __init__(self, foreign_exchange, config):
"""Initialize the sensor."""
self._foreign_exchange = foreign_exchange
self._from_currency = config[CONF_FROM]
self._to_currency = config[CONF_TO]
if CONF_NAME in config:
self._name = config.get(CONF_NAME)
else:
self._name = f"{self._to_currency}/{self._from_currency}"
self._unit_of_measurement = self._to_currency
self._icon = ICONS.get(self._from_currency, "USD")
self.values = None | [
"def",
"__init__",
"(",
"self",
",",
"foreign_exchange",
",",
"config",
")",
":",
"self",
".",
"_foreign_exchange",
"=",
"foreign_exchange",
"self",
".",
"_from_currency",
"=",
"config",
"[",
"CONF_FROM",
"]",
"self",
".",
"_to_currency",
"=",
"config",
"[",
"CONF_TO",
"]",
"if",
"CONF_NAME",
"in",
"config",
":",
"self",
".",
"_name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"else",
":",
"self",
".",
"_name",
"=",
"f\"{self._to_currency}/{self._from_currency}\"",
"self",
".",
"_unit_of_measurement",
"=",
"self",
".",
"_to_currency",
"self",
".",
"_icon",
"=",
"ICONS",
".",
"get",
"(",
"self",
".",
"_from_currency",
",",
"\"USD\"",
")",
"self",
".",
"values",
"=",
"None"
] | [
161,
4
] | [
172,
26
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageForeignExchange.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"
] | [
175,
4
] | [
177,
25
] | python | en | ['en', 'mi', 'en'] | True |
AlphaVantageForeignExchange.unit_of_measurement | (self) | Return the unit of measurement of this entity, if any. | Return the unit of measurement of this entity, if any. | def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
180,
4
] | [
182,
40
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageForeignExchange.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return round(float(self.values["5. Exchange Rate"]), 4) | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"round",
"(",
"float",
"(",
"self",
".",
"values",
"[",
"\"5. Exchange Rate\"",
"]",
")",
",",
"4",
")"
] | [
185,
4
] | [
187,
63
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageForeignExchange.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
190,
4
] | [
192,
25
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageForeignExchange.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self.values is not None:
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
CONF_FROM: self._from_currency,
CONF_TO: self._to_currency,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"values",
"is",
"not",
"None",
":",
"return",
"{",
"ATTR_ATTRIBUTION",
":",
"ATTRIBUTION",
",",
"CONF_FROM",
":",
"self",
".",
"_from_currency",
",",
"CONF_TO",
":",
"self",
".",
"_to_currency",
",",
"}"
] | [
195,
4
] | [
202,
13
] | python | en | ['en', 'en', 'en'] | True |
AlphaVantageForeignExchange.update | (self) | Get the latest data and updates the states. | Get the latest data and updates the states. | def update(self):
"""Get the latest data and updates the states."""
_LOGGER.debug(
"Requesting new data for forex %s - %s",
self._from_currency,
self._to_currency,
)
self.values, _ = self._foreign_exchange.get_currency_exchange_rate(
from_currency=self._from_currency, to_currency=self._to_currency
)
_LOGGER.debug(
"Received new data for forex %s - %s",
self._from_currency,
self._to_currency,
) | [
"def",
"update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Requesting new data for forex %s - %s\"",
",",
"self",
".",
"_from_currency",
",",
"self",
".",
"_to_currency",
",",
")",
"self",
".",
"values",
",",
"_",
"=",
"self",
".",
"_foreign_exchange",
".",
"get_currency_exchange_rate",
"(",
"from_currency",
"=",
"self",
".",
"_from_currency",
",",
"to_currency",
"=",
"self",
".",
"_to_currency",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Received new data for forex %s - %s\"",
",",
"self",
".",
"_from_currency",
",",
"self",
".",
"_to_currency",
",",
")"
] | [
204,
4
] | [
218,
9
] | python | en | ['en', 'en', 'en'] | True |
create_lat_lons_for_NZTMgrid | (extent_w=1.2e6, extent_e=1.4e6, extent_n=5.13e6, extent_s=4.82e6, resolution=250) | create grids of latitude and longitude corresponding to grid centres of data in nztm grid
| create grids of latitude and longitude corresponding to grid centres of data in nztm grid
| def create_lat_lons_for_NZTMgrid(extent_w=1.2e6, extent_e=1.4e6, extent_n=5.13e6, extent_s=4.82e6, resolution=250):
"""create grids of latitude and longitude corresponding to grid centres of data in nztm grid
"""
# create coordinates
x_centres = np.arange(extent_w + resolution / 2, extent_e, resolution)
y_centres = np.arange(extent_s + resolution / 2, extent_n, resolution)
y_array, x_array = np.meshgrid(y_centres, x_centres, indexing='ij')
lat_array, lon_array = nztm_to_wgs84(y_array, x_array)
return lat_array, lon_array | [
"def",
"create_lat_lons_for_NZTMgrid",
"(",
"extent_w",
"=",
"1.2e6",
",",
"extent_e",
"=",
"1.4e6",
",",
"extent_n",
"=",
"5.13e6",
",",
"extent_s",
"=",
"4.82e6",
",",
"resolution",
"=",
"250",
")",
":",
"# create coordinates",
"x_centres",
"=",
"np",
".",
"arange",
"(",
"extent_w",
"+",
"resolution",
"/",
"2",
",",
"extent_e",
",",
"resolution",
")",
"y_centres",
"=",
"np",
".",
"arange",
"(",
"extent_s",
"+",
"resolution",
"/",
"2",
",",
"extent_n",
",",
"resolution",
")",
"y_array",
",",
"x_array",
"=",
"np",
".",
"meshgrid",
"(",
"y_centres",
",",
"x_centres",
",",
"indexing",
"=",
"'ij'",
")",
"lat_array",
",",
"lon_array",
"=",
"nztm_to_wgs84",
"(",
"y_array",
",",
"x_array",
")",
"return",
"lat_array",
",",
"lon_array"
] | [
111,
0
] | [
119,
31
] | python | en | ['en', 'en', 'en'] | True |
write_nztm_grids_to_netcdf | (fname, list_of_data_arrays, var_names, datetime_list, northings, eastings, lat_array,
lon_array, elevation, no_time=False) |
Write a netCDF file containing fractional snow covered area data
:param fname: string, full pathname of file to be created
:param list_of_data_arrays: list, list containing data arrays to be saved [[time, northings, eastings],[time, northings, eastings]]
:param var_names: list of strings corresponding to names of data arrays
:param datetime_list: list of datetime objects corresponding to data
:param northings: vector containing northings associated with data grid
:param eastings: vector containing eastings associated with data grid
:param lat_array: array containing longitudes of data grid
:param lon_array: array containing latitudes of data grid
:param elevation: array containing elevation of data grid
:return:
|
Write a netCDF file containing fractional snow covered area data
:param fname: string, full pathname of file to be created
:param list_of_data_arrays: list, list containing data arrays to be saved [[time, northings, eastings],[time, northings, eastings]]
:param var_names: list of strings corresponding to names of data arrays
:param datetime_list: list of datetime objects corresponding to data
:param northings: vector containing northings associated with data grid
:param eastings: vector containing eastings associated with data grid
:param lat_array: array containing longitudes of data grid
:param lon_array: array containing latitudes of data grid
:param elevation: array containing elevation of data grid | def write_nztm_grids_to_netcdf(fname, list_of_data_arrays, var_names, datetime_list, northings, eastings, lat_array,
lon_array, elevation, no_time=False):
"""
Write a netCDF file containing fractional snow covered area data
:param fname: string, full pathname of file to be created
:param list_of_data_arrays: list, list containing data arrays to be saved [[time, northings, eastings],[time, northings, eastings]]
:param var_names: list of strings corresponding to names of data arrays
:param datetime_list: list of datetime objects corresponding to data
:param northings: vector containing northings associated with data grid
:param eastings: vector containing eastings associated with data grid
:param lat_array: array containing longitudes of data grid
:param lon_array: array containing latitudes of data grid
:param elevation: array containing elevation of data grid
:return:
"""
ds = nc.Dataset(fname, 'w')
# add common attributes
ds.institution = "Bodeker Scientific"
ds.title = ''
ds.source = ''
ds.history = ''
ds.references = ''
ds.author = ''
ds.email = ''
ds.created = strftime("%Y-%m-%d %H:%M:%S", gmtime())
if no_time == False:
ds.featureType = "timeSeries"
else:
ds.comment = 'timestamp {}'.format(datetime_list.strftime('%Y%m%d%H%M'))
ds.Conventions = "CF-1.6"
if no_time == False:
ds.createDimension('time', )
t = ds.createVariable('time', 'f8', ('time',))
t.long_name = "time"
t.units = 'days since 1900-01-01 00:00:00'
t[:] = nc.date2num(datetime_list, units=t.units)
ds.createDimension('northing', len(northings))
ds.createDimension('easting', len(eastings))
ds.createDimension('latitude', len(northings))
ds.createDimension('longitude', len(eastings))
# add northing and easting dimensions as well as lat/lon variables
t = ds.createVariable('northing', 'f8', ('northing',))
t.axis = 'Y'
t.long_name = "northing in NZTM"
t.units = 'metres'
t[:] = northings
t = ds.createVariable('easting', 'f8', ('easting',))
t.axis = 'X'
t.long_name = "easting in NZTM"
t.units = 'metres'
t[:] = eastings
t = ds.createVariable('lat', 'f8', ('northing', 'easting',))
t.long_name = "latitude"
t.standard_name = "latitude"
t.units = "degrees north"
t[:] = lat_array
t = ds.createVariable('lon', 'f8', ('northing', 'easting',))
t.long_name = "longitude"
t.standard_name = "longitude"
t.units = "degrees east"
t[:] = lon_array
elevation_var = ds.createVariable('elevation', 'f8', ('northing', 'easting',), fill_value=-9999.)
elevation_var.long_name = "elevation (meters)"
elevation_var.standard_name = "surface_altitude"
elevation_var.units = "meters"
elevation_var[:] = elevation
if 'precipitation_amount' in var_names:
precip_var = create_ncvar_precipitation(ds, no_time=no_time)
precip_var[:] = list_of_data_arrays[var_names.index('precipitation_amount')]
if 'air_temperature' in var_names:
temp_var = create_ncvar_temperaure(ds, no_time=no_time)
temp_var[:] = list_of_data_arrays[var_names.index('air_temperature')]
if 'surface_downwelling_shortwave_flux' in var_names:
temp_var = create_ncvar_shortwave(ds, no_time=no_time)
temp_var[:] = list_of_data_arrays[var_names.index('surface_downwelling_shortwave_flux')]
if 'fsca' in var_names:
fsca_var = create_ncvar_fsca(ds)
fsca_var[:] = list_of_data_arrays[var_names.index('fsca')]
if 'swe' in var_names:
swe_var = create_ncvar_swe(ds)
swe_var[:] = list_of_data_arrays[var_names.index('swe')]
ds.close() | [
"def",
"write_nztm_grids_to_netcdf",
"(",
"fname",
",",
"list_of_data_arrays",
",",
"var_names",
",",
"datetime_list",
",",
"northings",
",",
"eastings",
",",
"lat_array",
",",
"lon_array",
",",
"elevation",
",",
"no_time",
"=",
"False",
")",
":",
"ds",
"=",
"nc",
".",
"Dataset",
"(",
"fname",
",",
"'w'",
")",
"# add common attributes",
"ds",
".",
"institution",
"=",
"\"Bodeker Scientific\"",
"ds",
".",
"title",
"=",
"''",
"ds",
".",
"source",
"=",
"''",
"ds",
".",
"history",
"=",
"''",
"ds",
".",
"references",
"=",
"''",
"ds",
".",
"author",
"=",
"''",
"ds",
".",
"email",
"=",
"''",
"ds",
".",
"created",
"=",
"strftime",
"(",
"\"%Y-%m-%d %H:%M:%S\"",
",",
"gmtime",
"(",
")",
")",
"if",
"no_time",
"==",
"False",
":",
"ds",
".",
"featureType",
"=",
"\"timeSeries\"",
"else",
":",
"ds",
".",
"comment",
"=",
"'timestamp {}'",
".",
"format",
"(",
"datetime_list",
".",
"strftime",
"(",
"'%Y%m%d%H%M'",
")",
")",
"ds",
".",
"Conventions",
"=",
"\"CF-1.6\"",
"if",
"no_time",
"==",
"False",
":",
"ds",
".",
"createDimension",
"(",
"'time'",
",",
")",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'time'",
",",
"'f8'",
",",
"(",
"'time'",
",",
")",
")",
"t",
".",
"long_name",
"=",
"\"time\"",
"t",
".",
"units",
"=",
"'days since 1900-01-01 00:00:00'",
"t",
"[",
":",
"]",
"=",
"nc",
".",
"date2num",
"(",
"datetime_list",
",",
"units",
"=",
"t",
".",
"units",
")",
"ds",
".",
"createDimension",
"(",
"'northing'",
",",
"len",
"(",
"northings",
")",
")",
"ds",
".",
"createDimension",
"(",
"'easting'",
",",
"len",
"(",
"eastings",
")",
")",
"ds",
".",
"createDimension",
"(",
"'latitude'",
",",
"len",
"(",
"northings",
")",
")",
"ds",
".",
"createDimension",
"(",
"'longitude'",
",",
"len",
"(",
"eastings",
")",
")",
"# add northing and easting dimensions as well as lat/lon variables",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'northing'",
",",
"'f8'",
",",
"(",
"'northing'",
",",
")",
")",
"t",
".",
"axis",
"=",
"'Y'",
"t",
".",
"long_name",
"=",
"\"northing in NZTM\"",
"t",
".",
"units",
"=",
"'metres'",
"t",
"[",
":",
"]",
"=",
"northings",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'easting'",
",",
"'f8'",
",",
"(",
"'easting'",
",",
")",
")",
"t",
".",
"axis",
"=",
"'X'",
"t",
".",
"long_name",
"=",
"\"easting in NZTM\"",
"t",
".",
"units",
"=",
"'metres'",
"t",
"[",
":",
"]",
"=",
"eastings",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'lat'",
",",
"'f8'",
",",
"(",
"'northing'",
",",
"'easting'",
",",
")",
")",
"t",
".",
"long_name",
"=",
"\"latitude\"",
"t",
".",
"standard_name",
"=",
"\"latitude\"",
"t",
".",
"units",
"=",
"\"degrees north\"",
"t",
"[",
":",
"]",
"=",
"lat_array",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'lon'",
",",
"'f8'",
",",
"(",
"'northing'",
",",
"'easting'",
",",
")",
")",
"t",
".",
"long_name",
"=",
"\"longitude\"",
"t",
".",
"standard_name",
"=",
"\"longitude\"",
"t",
".",
"units",
"=",
"\"degrees east\"",
"t",
"[",
":",
"]",
"=",
"lon_array",
"elevation_var",
"=",
"ds",
".",
"createVariable",
"(",
"'elevation'",
",",
"'f8'",
",",
"(",
"'northing'",
",",
"'easting'",
",",
")",
",",
"fill_value",
"=",
"-",
"9999.",
")",
"elevation_var",
".",
"long_name",
"=",
"\"elevation (meters)\"",
"elevation_var",
".",
"standard_name",
"=",
"\"surface_altitude\"",
"elevation_var",
".",
"units",
"=",
"\"meters\"",
"elevation_var",
"[",
":",
"]",
"=",
"elevation",
"if",
"'precipitation_amount'",
"in",
"var_names",
":",
"precip_var",
"=",
"create_ncvar_precipitation",
"(",
"ds",
",",
"no_time",
"=",
"no_time",
")",
"precip_var",
"[",
":",
"]",
"=",
"list_of_data_arrays",
"[",
"var_names",
".",
"index",
"(",
"'precipitation_amount'",
")",
"]",
"if",
"'air_temperature'",
"in",
"var_names",
":",
"temp_var",
"=",
"create_ncvar_temperaure",
"(",
"ds",
",",
"no_time",
"=",
"no_time",
")",
"temp_var",
"[",
":",
"]",
"=",
"list_of_data_arrays",
"[",
"var_names",
".",
"index",
"(",
"'air_temperature'",
")",
"]",
"if",
"'surface_downwelling_shortwave_flux'",
"in",
"var_names",
":",
"temp_var",
"=",
"create_ncvar_shortwave",
"(",
"ds",
",",
"no_time",
"=",
"no_time",
")",
"temp_var",
"[",
":",
"]",
"=",
"list_of_data_arrays",
"[",
"var_names",
".",
"index",
"(",
"'surface_downwelling_shortwave_flux'",
")",
"]",
"if",
"'fsca'",
"in",
"var_names",
":",
"fsca_var",
"=",
"create_ncvar_fsca",
"(",
"ds",
")",
"fsca_var",
"[",
":",
"]",
"=",
"list_of_data_arrays",
"[",
"var_names",
".",
"index",
"(",
"'fsca'",
")",
"]",
"if",
"'swe'",
"in",
"var_names",
":",
"swe_var",
"=",
"create_ncvar_swe",
"(",
"ds",
")",
"swe_var",
"[",
":",
"]",
"=",
"list_of_data_arrays",
"[",
"var_names",
".",
"index",
"(",
"'swe'",
")",
"]",
"ds",
".",
"close",
"(",
")"
] | [
122,
0
] | [
219,
14
] | python | en | ['en', 'error', 'th'] | False |
setup_nztm_grid_netcdf | (fname, list_of_data_arrays, var_names, datetime_list, northings, eastings, lat_array,
lon_array, elevation, no_time=False) |
Write a netCDF file containing fractional snow covered area data
:param fname: string, full pathname of file to be created
:param list_of_data_arrays: list, list containing data arrays to be saved [[time, northings, eastings],[time, northings, eastings]]
:param var_names: list of strings corresponding to names of data arrays
:param datetime_list: list of datetime objects corresponding to data
:param northings: vector containing northings associated with data grid
:param eastings: vector containing eastings associated with data grid
:param lat_array: array containing longitudes of data grid
:param lon_array: array containing latitudes of data grid
:param elevation: array containing elevation of data grid
:return:
|
Write a netCDF file containing fractional snow covered area data
:param fname: string, full pathname of file to be created
:param list_of_data_arrays: list, list containing data arrays to be saved [[time, northings, eastings],[time, northings, eastings]]
:param var_names: list of strings corresponding to names of data arrays
:param datetime_list: list of datetime objects corresponding to data
:param northings: vector containing northings associated with data grid
:param eastings: vector containing eastings associated with data grid
:param lat_array: array containing longitudes of data grid
:param lon_array: array containing latitudes of data grid
:param elevation: array containing elevation of data grid | def setup_nztm_grid_netcdf(fname, list_of_data_arrays, var_names, datetime_list, northings, eastings, lat_array,
lon_array, elevation, no_time=False):
"""
Write a netCDF file containing fractional snow covered area data
:param fname: string, full pathname of file to be created
:param list_of_data_arrays: list, list containing data arrays to be saved [[time, northings, eastings],[time, northings, eastings]]
:param var_names: list of strings corresponding to names of data arrays
:param datetime_list: list of datetime objects corresponding to data
:param northings: vector containing northings associated with data grid
:param eastings: vector containing eastings associated with data grid
:param lat_array: array containing longitudes of data grid
:param lon_array: array containing latitudes of data grid
:param elevation: array containing elevation of data grid
:return:
"""
ds = nc.Dataset(fname, 'w')
# add common attributes
ds.institution = "Bodeker Scientific"
ds.title = ''
ds.source = ''
ds.history = ''
ds.references = ''
ds.author = ''
ds.email = ''
ds.created = strftime("%Y-%m-%d %H:%M:%S", gmtime())
if no_time == False:
ds.featureType = "timeSeries"
else:
ds.comment = 'timestamp {}'.format(datetime_list.strftime('%Y%m%d%H%M'))
ds.Conventions = "CF-1.6"
if no_time == False:
ds.createDimension('time', )
t = ds.createVariable('time', 'f8', ('time',))
t.long_name = "time"
t.units = 'days since 1900-01-01 00:00:00'
t[:] = nc.date2num(datetime_list, units=t.units)
ds.createDimension('northing', len(northings))
ds.createDimension('easting', len(eastings))
ds.createDimension('latitude', len(northings))
ds.createDimension('longitude', len(eastings))
# add northing and easting dimensions as well as lat/lon variables
t = ds.createVariable('northing', 'f8', ('northing',))
t.axis = 'Y'
t.long_name = "northing in NZTM"
t.units = 'metres'
t[:] = northings
t = ds.createVariable('easting', 'f8', ('easting',))
t.axis = 'X'
t.long_name = "easting in NZTM"
t.units = 'metres'
t[:] = eastings
t = ds.createVariable('lat', 'f8', ('northing', 'easting',))
t.long_name = "latitude"
t.standard_name = "latitude"
t.units = "degrees north"
t[:] = lat_array
t = ds.createVariable('lon', 'f8', ('northing', 'easting',))
t.long_name = "longitude"
t.standard_name = "longitude"
t.units = "degrees east"
t[:] = lon_array
elevation_var = ds.createVariable('elevation', 'f8', ('northing', 'easting',), fill_value=-9999.)
elevation_var.long_name = "elevation (meters)"
elevation_var.standard_name = "surface_altitude"
elevation_var.units = "meters"
elevation_var[:] = elevation
if 'precipitation_amount' in var_names:
precip_var = create_ncvar_precipitation(ds, no_time=no_time)
if 'air_temperature' in var_names:
temp_var = create_ncvar_temperaure(ds, no_time=no_time)
if 'surface_downwelling_shortwave_flux' in var_names:
temp_var = create_ncvar_shortwave(ds, no_time=no_time)
if 'fsca' in var_names:
fsca_var = create_ncvar_fsca(ds)
if 'swe' in var_names:
swe_var = create_ncvar_swe(ds)
if 'acc' in var_names:
acc_var = create_ncvar_acc(ds)
if 'melt' in var_names:
melt_var = create_ncvar_melt(ds)
return ds | [
"def",
"setup_nztm_grid_netcdf",
"(",
"fname",
",",
"list_of_data_arrays",
",",
"var_names",
",",
"datetime_list",
",",
"northings",
",",
"eastings",
",",
"lat_array",
",",
"lon_array",
",",
"elevation",
",",
"no_time",
"=",
"False",
")",
":",
"ds",
"=",
"nc",
".",
"Dataset",
"(",
"fname",
",",
"'w'",
")",
"# add common attributes",
"ds",
".",
"institution",
"=",
"\"Bodeker Scientific\"",
"ds",
".",
"title",
"=",
"''",
"ds",
".",
"source",
"=",
"''",
"ds",
".",
"history",
"=",
"''",
"ds",
".",
"references",
"=",
"''",
"ds",
".",
"author",
"=",
"''",
"ds",
".",
"email",
"=",
"''",
"ds",
".",
"created",
"=",
"strftime",
"(",
"\"%Y-%m-%d %H:%M:%S\"",
",",
"gmtime",
"(",
")",
")",
"if",
"no_time",
"==",
"False",
":",
"ds",
".",
"featureType",
"=",
"\"timeSeries\"",
"else",
":",
"ds",
".",
"comment",
"=",
"'timestamp {}'",
".",
"format",
"(",
"datetime_list",
".",
"strftime",
"(",
"'%Y%m%d%H%M'",
")",
")",
"ds",
".",
"Conventions",
"=",
"\"CF-1.6\"",
"if",
"no_time",
"==",
"False",
":",
"ds",
".",
"createDimension",
"(",
"'time'",
",",
")",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'time'",
",",
"'f8'",
",",
"(",
"'time'",
",",
")",
")",
"t",
".",
"long_name",
"=",
"\"time\"",
"t",
".",
"units",
"=",
"'days since 1900-01-01 00:00:00'",
"t",
"[",
":",
"]",
"=",
"nc",
".",
"date2num",
"(",
"datetime_list",
",",
"units",
"=",
"t",
".",
"units",
")",
"ds",
".",
"createDimension",
"(",
"'northing'",
",",
"len",
"(",
"northings",
")",
")",
"ds",
".",
"createDimension",
"(",
"'easting'",
",",
"len",
"(",
"eastings",
")",
")",
"ds",
".",
"createDimension",
"(",
"'latitude'",
",",
"len",
"(",
"northings",
")",
")",
"ds",
".",
"createDimension",
"(",
"'longitude'",
",",
"len",
"(",
"eastings",
")",
")",
"# add northing and easting dimensions as well as lat/lon variables",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'northing'",
",",
"'f8'",
",",
"(",
"'northing'",
",",
")",
")",
"t",
".",
"axis",
"=",
"'Y'",
"t",
".",
"long_name",
"=",
"\"northing in NZTM\"",
"t",
".",
"units",
"=",
"'metres'",
"t",
"[",
":",
"]",
"=",
"northings",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'easting'",
",",
"'f8'",
",",
"(",
"'easting'",
",",
")",
")",
"t",
".",
"axis",
"=",
"'X'",
"t",
".",
"long_name",
"=",
"\"easting in NZTM\"",
"t",
".",
"units",
"=",
"'metres'",
"t",
"[",
":",
"]",
"=",
"eastings",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'lat'",
",",
"'f8'",
",",
"(",
"'northing'",
",",
"'easting'",
",",
")",
")",
"t",
".",
"long_name",
"=",
"\"latitude\"",
"t",
".",
"standard_name",
"=",
"\"latitude\"",
"t",
".",
"units",
"=",
"\"degrees north\"",
"t",
"[",
":",
"]",
"=",
"lat_array",
"t",
"=",
"ds",
".",
"createVariable",
"(",
"'lon'",
",",
"'f8'",
",",
"(",
"'northing'",
",",
"'easting'",
",",
")",
")",
"t",
".",
"long_name",
"=",
"\"longitude\"",
"t",
".",
"standard_name",
"=",
"\"longitude\"",
"t",
".",
"units",
"=",
"\"degrees east\"",
"t",
"[",
":",
"]",
"=",
"lon_array",
"elevation_var",
"=",
"ds",
".",
"createVariable",
"(",
"'elevation'",
",",
"'f8'",
",",
"(",
"'northing'",
",",
"'easting'",
",",
")",
",",
"fill_value",
"=",
"-",
"9999.",
")",
"elevation_var",
".",
"long_name",
"=",
"\"elevation (meters)\"",
"elevation_var",
".",
"standard_name",
"=",
"\"surface_altitude\"",
"elevation_var",
".",
"units",
"=",
"\"meters\"",
"elevation_var",
"[",
":",
"]",
"=",
"elevation",
"if",
"'precipitation_amount'",
"in",
"var_names",
":",
"precip_var",
"=",
"create_ncvar_precipitation",
"(",
"ds",
",",
"no_time",
"=",
"no_time",
")",
"if",
"'air_temperature'",
"in",
"var_names",
":",
"temp_var",
"=",
"create_ncvar_temperaure",
"(",
"ds",
",",
"no_time",
"=",
"no_time",
")",
"if",
"'surface_downwelling_shortwave_flux'",
"in",
"var_names",
":",
"temp_var",
"=",
"create_ncvar_shortwave",
"(",
"ds",
",",
"no_time",
"=",
"no_time",
")",
"if",
"'fsca'",
"in",
"var_names",
":",
"fsca_var",
"=",
"create_ncvar_fsca",
"(",
"ds",
")",
"if",
"'swe'",
"in",
"var_names",
":",
"swe_var",
"=",
"create_ncvar_swe",
"(",
"ds",
")",
"if",
"'acc'",
"in",
"var_names",
":",
"acc_var",
"=",
"create_ncvar_acc",
"(",
"ds",
")",
"if",
"'melt'",
"in",
"var_names",
":",
"melt_var",
"=",
"create_ncvar_melt",
"(",
"ds",
")",
"return",
"ds"
] | [
222,
0
] | [
320,
13
] | python | en | ['en', 'error', 'th'] | False |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Blinkt Light platform. | Set up the Blinkt Light platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Blinkt Light platform."""
# pylint: disable=no-member
blinkt = importlib.import_module("blinkt")
# ensure that the lights are off when exiting
blinkt.set_clear_on_exit()
name = config[CONF_NAME]
add_entities(
[BlinktLight(blinkt, name, index) for index in range(blinkt.NUM_PIXELS)]
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"# pylint: disable=no-member",
"blinkt",
"=",
"importlib",
".",
"import_module",
"(",
"\"blinkt\"",
")",
"# ensure that the lights are off when exiting",
"blinkt",
".",
"set_clear_on_exit",
"(",
")",
"name",
"=",
"config",
"[",
"CONF_NAME",
"]",
"add_entities",
"(",
"[",
"BlinktLight",
"(",
"blinkt",
",",
"name",
",",
"index",
")",
"for",
"index",
"in",
"range",
"(",
"blinkt",
".",
"NUM_PIXELS",
")",
"]",
")"
] | [
26,
0
] | [
38,
5
] | python | en | ['en', 'da', 'en'] | True |
BlinktLight.__init__ | (self, blinkt, name, index) | Initialize a Blinkt Light.
Default brightness and white color.
| Initialize a Blinkt Light. | def __init__(self, blinkt, name, index):
"""Initialize a Blinkt Light.
Default brightness and white color.
"""
self._blinkt = blinkt
self._name = f"{name}_{index}"
self._index = index
self._is_on = False
self._brightness = 255
self._hs_color = [0, 0] | [
"def",
"__init__",
"(",
"self",
",",
"blinkt",
",",
"name",
",",
"index",
")",
":",
"self",
".",
"_blinkt",
"=",
"blinkt",
"self",
".",
"_name",
"=",
"f\"{name}_{index}\"",
"self",
".",
"_index",
"=",
"index",
"self",
".",
"_is_on",
"=",
"False",
"self",
".",
"_brightness",
"=",
"255",
"self",
".",
"_hs_color",
"=",
"[",
"0",
",",
"0",
"]"
] | [
44,
4
] | [
54,
31
] | python | en | ['en', 'lb', 'it'] | False |
BlinktLight.name | (self) | Return the display name of this light. | Return the display name of this light. | def name(self):
"""Return the display name of this light."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
57,
4
] | [
59,
25
] | python | en | ['en', 'en', 'en'] | True |
BlinktLight.brightness | (self) | Read back the brightness of the light.
Returns integer in the range of 1-255.
| Read back the brightness of the light. | def brightness(self):
"""Read back the brightness of the light.
Returns integer in the range of 1-255.
"""
return self._brightness | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_brightness"
] | [
62,
4
] | [
67,
31
] | python | en | ['en', 'en', 'en'] | True |
BlinktLight.hs_color | (self) | Read back the color of the light. | Read back the color of the light. | def hs_color(self):
"""Read back the color of the light."""
return self._hs_color | [
"def",
"hs_color",
"(",
"self",
")",
":",
"return",
"self",
".",
"_hs_color"
] | [
70,
4
] | [
72,
29
] | python | en | ['en', 'en', 'en'] | True |
BlinktLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORT_BLINKT | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_BLINKT"
] | [
75,
4
] | [
77,
29
] | python | en | ['da', 'en', 'en'] | True |
BlinktLight.is_on | (self) | Return true if light is on. | Return true if light is on. | def is_on(self):
"""Return true if light is on."""
return self._is_on | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_is_on"
] | [
80,
4
] | [
82,
26
] | python | en | ['en', 'et', 'en'] | True |
BlinktLight.should_poll | (self) | Return if we should poll this device. | Return if we should poll this device. | def should_poll(self):
"""Return if we should poll this device."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
85,
4
] | [
87,
20
] | python | en | ['en', 'en', 'en'] | True |
BlinktLight.assumed_state | (self) | Return True if unable to access real state of the entity. | Return True if unable to access real state of the entity. | def assumed_state(self) -> bool:
"""Return True if unable to access real state of the entity."""
return True | [
"def",
"assumed_state",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"True"
] | [
90,
4
] | [
92,
19
] | python | en | ['en', 'en', 'en'] | True |
BlinktLight.turn_on | (self, **kwargs) | Instruct the light to turn on and set correct brightness & color. | Instruct the light to turn on and set correct brightness & color. | def turn_on(self, **kwargs):
"""Instruct the light to turn on and set correct brightness & color."""
if ATTR_HS_COLOR in kwargs:
self._hs_color = kwargs[ATTR_HS_COLOR]
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
percent_bright = self._brightness / 255
rgb_color = color_util.color_hs_to_RGB(*self._hs_color)
self._blinkt.set_pixel(
self._index, rgb_color[0], rgb_color[1], rgb_color[2], percent_bright
)
self._blinkt.show()
self._is_on = True
self.schedule_update_ha_state() | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"ATTR_HS_COLOR",
"in",
"kwargs",
":",
"self",
".",
"_hs_color",
"=",
"kwargs",
"[",
"ATTR_HS_COLOR",
"]",
"if",
"ATTR_BRIGHTNESS",
"in",
"kwargs",
":",
"self",
".",
"_brightness",
"=",
"kwargs",
"[",
"ATTR_BRIGHTNESS",
"]",
"percent_bright",
"=",
"self",
".",
"_brightness",
"/",
"255",
"rgb_color",
"=",
"color_util",
".",
"color_hs_to_RGB",
"(",
"*",
"self",
".",
"_hs_color",
")",
"self",
".",
"_blinkt",
".",
"set_pixel",
"(",
"self",
".",
"_index",
",",
"rgb_color",
"[",
"0",
"]",
",",
"rgb_color",
"[",
"1",
"]",
",",
"rgb_color",
"[",
"2",
"]",
",",
"percent_bright",
")",
"self",
".",
"_blinkt",
".",
"show",
"(",
")",
"self",
".",
"_is_on",
"=",
"True",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
94,
4
] | [
110,
39
] | python | en | ['en', 'en', 'en'] | True |
BlinktLight.turn_off | (self, **kwargs) | Instruct the light to turn off. | Instruct the light to turn off. | def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
self._blinkt.set_pixel(self._index, 0, 0, 0, 0)
self._blinkt.show()
self._is_on = False
self.schedule_update_ha_state() | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_blinkt",
".",
"set_pixel",
"(",
"self",
".",
"_index",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"self",
".",
"_blinkt",
".",
"show",
"(",
")",
"self",
".",
"_is_on",
"=",
"False",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
112,
4
] | [
117,
39
] | python | en | ['en', 'en', 'en'] | True |
test_min_sensor | (hass) | Test the min sensor. | Test the min sensor. | async def test_min_sensor(hass):
"""Test the min sensor."""
config = {
"sensor": {
"platform": "min_max",
"name": "test_min",
"type": "min",
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
hass.states.async_set(entity_id, value)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_min")
assert str(float(MIN_VALUE)) == state.state
assert entity_ids[2] == state.attributes.get("min_entity_id")
assert MAX_VALUE == state.attributes.get("max_value")
assert entity_ids[1] == state.attributes.get("max_entity_id")
assert MEAN == state.attributes.get("mean")
assert MEDIAN == state.attributes.get("median") | [
"async",
"def",
"test_min_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test_min\"",
",",
"\"type\"",
":",
"\"min\"",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"for",
"entity_id",
",",
"value",
"in",
"dict",
"(",
"zip",
"(",
"entity_ids",
",",
"VALUES",
")",
")",
".",
"items",
"(",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_min\"",
")",
"assert",
"str",
"(",
"float",
"(",
"MIN_VALUE",
")",
")",
"==",
"state",
".",
"state",
"assert",
"entity_ids",
"[",
"2",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"assert",
"MAX_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"assert",
"MEAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"mean\"",
")",
"assert",
"MEDIAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"median\"",
")"
] | [
29,
0
] | [
56,
51
] | python | en | ['en', 'sq', 'en'] | True |
test_max_sensor | (hass) | Test the max sensor. | Test the max sensor. | async def test_max_sensor(hass):
"""Test the max sensor."""
config = {
"sensor": {
"platform": "min_max",
"name": "test_max",
"type": "max",
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
hass.states.async_set(entity_id, value)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_max")
assert str(float(MAX_VALUE)) == state.state
assert entity_ids[2] == state.attributes.get("min_entity_id")
assert MIN_VALUE == state.attributes.get("min_value")
assert entity_ids[1] == state.attributes.get("max_entity_id")
assert MEAN == state.attributes.get("mean")
assert MEDIAN == state.attributes.get("median") | [
"async",
"def",
"test_max_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test_max\"",
",",
"\"type\"",
":",
"\"max\"",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"for",
"entity_id",
",",
"value",
"in",
"dict",
"(",
"zip",
"(",
"entity_ids",
",",
"VALUES",
")",
")",
".",
"items",
"(",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_max\"",
")",
"assert",
"str",
"(",
"float",
"(",
"MAX_VALUE",
")",
")",
"==",
"state",
".",
"state",
"assert",
"entity_ids",
"[",
"2",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"assert",
"MIN_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"assert",
"MEAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"mean\"",
")",
"assert",
"MEDIAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"median\"",
")"
] | [
59,
0
] | [
86,
51
] | python | en | ['en', 'ca', 'en'] | True |
test_mean_sensor | (hass) | Test the mean sensor. | Test the mean sensor. | async def test_mean_sensor(hass):
"""Test the mean sensor."""
config = {
"sensor": {
"platform": "min_max",
"name": "test_mean",
"type": "mean",
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
hass.states.async_set(entity_id, value)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_mean")
assert str(float(MEAN)) == state.state
assert MIN_VALUE == state.attributes.get("min_value")
assert entity_ids[2] == state.attributes.get("min_entity_id")
assert MAX_VALUE == state.attributes.get("max_value")
assert entity_ids[1] == state.attributes.get("max_entity_id")
assert MEDIAN == state.attributes.get("median") | [
"async",
"def",
"test_mean_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test_mean\"",
",",
"\"type\"",
":",
"\"mean\"",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"for",
"entity_id",
",",
"value",
"in",
"dict",
"(",
"zip",
"(",
"entity_ids",
",",
"VALUES",
")",
")",
".",
"items",
"(",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_mean\"",
")",
"assert",
"str",
"(",
"float",
"(",
"MEAN",
")",
")",
"==",
"state",
".",
"state",
"assert",
"MIN_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"assert",
"entity_ids",
"[",
"2",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"assert",
"MAX_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"assert",
"MEDIAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"median\"",
")"
] | [
89,
0
] | [
116,
51
] | python | en | ['en', 'da', 'en'] | True |
test_mean_1_digit_sensor | (hass) | Test the mean with 1-digit precision sensor. | Test the mean with 1-digit precision sensor. | async def test_mean_1_digit_sensor(hass):
"""Test the mean with 1-digit precision sensor."""
config = {
"sensor": {
"platform": "min_max",
"name": "test_mean",
"type": "mean",
"round_digits": 1,
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
hass.states.async_set(entity_id, value)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_mean")
assert str(float(MEAN_1_DIGIT)) == state.state
assert MIN_VALUE == state.attributes.get("min_value")
assert entity_ids[2] == state.attributes.get("min_entity_id")
assert MAX_VALUE == state.attributes.get("max_value")
assert entity_ids[1] == state.attributes.get("max_entity_id")
assert MEDIAN == state.attributes.get("median") | [
"async",
"def",
"test_mean_1_digit_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test_mean\"",
",",
"\"type\"",
":",
"\"mean\"",
",",
"\"round_digits\"",
":",
"1",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"for",
"entity_id",
",",
"value",
"in",
"dict",
"(",
"zip",
"(",
"entity_ids",
",",
"VALUES",
")",
")",
".",
"items",
"(",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_mean\"",
")",
"assert",
"str",
"(",
"float",
"(",
"MEAN_1_DIGIT",
")",
")",
"==",
"state",
".",
"state",
"assert",
"MIN_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"assert",
"entity_ids",
"[",
"2",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"assert",
"MAX_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"assert",
"MEDIAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"median\"",
")"
] | [
119,
0
] | [
147,
51
] | python | en | ['en', 'en', 'en'] | True |
test_mean_4_digit_sensor | (hass) | Test the mean with 1-digit precision sensor. | Test the mean with 1-digit precision sensor. | async def test_mean_4_digit_sensor(hass):
"""Test the mean with 1-digit precision sensor."""
config = {
"sensor": {
"platform": "min_max",
"name": "test_mean",
"type": "mean",
"round_digits": 4,
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
hass.states.async_set(entity_id, value)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_mean")
assert str(float(MEAN_4_DIGITS)) == state.state
assert MIN_VALUE == state.attributes.get("min_value")
assert entity_ids[2] == state.attributes.get("min_entity_id")
assert MAX_VALUE == state.attributes.get("max_value")
assert entity_ids[1] == state.attributes.get("max_entity_id")
assert MEDIAN == state.attributes.get("median") | [
"async",
"def",
"test_mean_4_digit_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test_mean\"",
",",
"\"type\"",
":",
"\"mean\"",
",",
"\"round_digits\"",
":",
"4",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"for",
"entity_id",
",",
"value",
"in",
"dict",
"(",
"zip",
"(",
"entity_ids",
",",
"VALUES",
")",
")",
".",
"items",
"(",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_mean\"",
")",
"assert",
"str",
"(",
"float",
"(",
"MEAN_4_DIGITS",
")",
")",
"==",
"state",
".",
"state",
"assert",
"MIN_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"assert",
"entity_ids",
"[",
"2",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"assert",
"MAX_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"assert",
"MEDIAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"median\"",
")"
] | [
150,
0
] | [
178,
51
] | python | en | ['en', 'en', 'en'] | True |
test_median_sensor | (hass) | Test the median sensor. | Test the median sensor. | async def test_median_sensor(hass):
"""Test the median sensor."""
config = {
"sensor": {
"platform": "min_max",
"name": "test_median",
"type": "median",
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
hass.states.async_set(entity_id, value)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_median")
assert str(float(MEDIAN)) == state.state
assert MIN_VALUE == state.attributes.get("min_value")
assert entity_ids[2] == state.attributes.get("min_entity_id")
assert MAX_VALUE == state.attributes.get("max_value")
assert entity_ids[1] == state.attributes.get("max_entity_id")
assert MEAN == state.attributes.get("mean") | [
"async",
"def",
"test_median_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test_median\"",
",",
"\"type\"",
":",
"\"median\"",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"for",
"entity_id",
",",
"value",
"in",
"dict",
"(",
"zip",
"(",
"entity_ids",
",",
"VALUES",
")",
")",
".",
"items",
"(",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_median\"",
")",
"assert",
"str",
"(",
"float",
"(",
"MEDIAN",
")",
")",
"==",
"state",
".",
"state",
"assert",
"MIN_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"assert",
"entity_ids",
"[",
"2",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"assert",
"MAX_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"assert",
"MEAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"mean\"",
")"
] | [
181,
0
] | [
208,
47
] | python | en | ['en', 'da', 'en'] | True |
test_not_enough_sensor_value | (hass) | Test that there is nothing done if not enough values available. | Test that there is nothing done if not enough values available. | async def test_not_enough_sensor_value(hass):
"""Test that there is nothing done if not enough values available."""
config = {
"sensor": {
"platform": "min_max",
"name": "test_max",
"type": "max",
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
hass.states.async_set(entity_ids[0], STATE_UNKNOWN)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_max")
assert STATE_UNKNOWN == state.state
assert state.attributes.get("min_entity_id") is None
assert state.attributes.get("min_value") is None
assert state.attributes.get("max_entity_id") is None
assert state.attributes.get("max_value") is None
assert state.attributes.get("median") is None
hass.states.async_set(entity_ids[1], VALUES[1])
await hass.async_block_till_done()
state = hass.states.get("sensor.test_max")
assert STATE_UNKNOWN != state.state
assert entity_ids[1] == state.attributes.get("min_entity_id")
assert VALUES[1] == state.attributes.get("min_value")
assert entity_ids[1] == state.attributes.get("max_entity_id")
assert VALUES[1] == state.attributes.get("max_value")
hass.states.async_set(entity_ids[2], STATE_UNKNOWN)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_max")
assert STATE_UNKNOWN != state.state
assert entity_ids[1] == state.attributes.get("min_entity_id")
assert VALUES[1] == state.attributes.get("min_value")
assert entity_ids[1] == state.attributes.get("max_entity_id")
assert VALUES[1] == state.attributes.get("max_value")
hass.states.async_set(entity_ids[1], STATE_UNAVAILABLE)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_max")
assert STATE_UNKNOWN == state.state
assert state.attributes.get("min_entity_id") is None
assert state.attributes.get("min_value") is None
assert state.attributes.get("max_entity_id") is None
assert state.attributes.get("max_value") is None | [
"async",
"def",
"test_not_enough_sensor_value",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test_max\"",
",",
"\"type\"",
":",
"\"max\"",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_ids",
"[",
"0",
"]",
",",
"STATE_UNKNOWN",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_max\"",
")",
"assert",
"STATE_UNKNOWN",
"==",
"state",
".",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"median\"",
")",
"is",
"None",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_ids",
"[",
"1",
"]",
",",
"VALUES",
"[",
"1",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_max\"",
")",
"assert",
"STATE_UNKNOWN",
"!=",
"state",
".",
"state",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"assert",
"VALUES",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"assert",
"VALUES",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_ids",
"[",
"2",
"]",
",",
"STATE_UNKNOWN",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_max\"",
")",
"assert",
"STATE_UNKNOWN",
"!=",
"state",
".",
"state",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"assert",
"VALUES",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"assert",
"entity_ids",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"assert",
"VALUES",
"[",
"1",
"]",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_ids",
"[",
"1",
"]",
",",
"STATE_UNAVAILABLE",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_max\"",
")",
"assert",
"STATE_UNKNOWN",
"==",
"state",
".",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_entity_id\"",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_entity_id\"",
")",
"is",
"None",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"is",
"None"
] | [
211,
0
] | [
266,
52
] | python | en | ['en', 'en', 'en'] | True |
test_different_unit_of_measurement | (hass) | Test for different unit of measurement. | Test for different unit of measurement. | async def test_different_unit_of_measurement(hass):
"""Test for different unit of measurement."""
config = {
"sensor": {
"platform": "min_max",
"name": "test",
"type": "mean",
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
hass.states.async_set(
entity_ids[0], VALUES[0], {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
)
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert str(float(VALUES[0])) == state.state
assert state.attributes.get("unit_of_measurement") == TEMP_CELSIUS
hass.states.async_set(
entity_ids[1], VALUES[1], {ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT}
)
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert STATE_UNKNOWN == state.state
assert state.attributes.get("unit_of_measurement") == "ERR"
hass.states.async_set(
entity_ids[2], VALUES[2], {ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE}
)
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert STATE_UNKNOWN == state.state
assert state.attributes.get("unit_of_measurement") == "ERR" | [
"async",
"def",
"test_different_unit_of_measurement",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test\"",
",",
"\"type\"",
":",
"\"mean\"",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_ids",
"[",
"0",
"]",
",",
"VALUES",
"[",
"0",
"]",
",",
"{",
"ATTR_UNIT_OF_MEASUREMENT",
":",
"TEMP_CELSIUS",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test\"",
")",
"assert",
"str",
"(",
"float",
"(",
"VALUES",
"[",
"0",
"]",
")",
")",
"==",
"state",
".",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"unit_of_measurement\"",
")",
"==",
"TEMP_CELSIUS",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_ids",
"[",
"1",
"]",
",",
"VALUES",
"[",
"1",
"]",
",",
"{",
"ATTR_UNIT_OF_MEASUREMENT",
":",
"TEMP_FAHRENHEIT",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test\"",
")",
"assert",
"STATE_UNKNOWN",
"==",
"state",
".",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"unit_of_measurement\"",
")",
"==",
"\"ERR\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_ids",
"[",
"2",
"]",
",",
"VALUES",
"[",
"2",
"]",
",",
"{",
"ATTR_UNIT_OF_MEASUREMENT",
":",
"PERCENTAGE",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test\"",
")",
"assert",
"STATE_UNKNOWN",
"==",
"state",
".",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"unit_of_measurement\"",
")",
"==",
"\"ERR\""
] | [
269,
0
] | [
313,
63
] | python | en | ['en', 'en', 'en'] | True |
test_last_sensor | (hass) | Test the last sensor. | Test the last sensor. | async def test_last_sensor(hass):
"""Test the last sensor."""
config = {
"sensor": {
"platform": "min_max",
"name": "test_last",
"type": "last",
"entity_ids": ["sensor.test_1", "sensor.test_2", "sensor.test_3"],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
entity_ids = config["sensor"]["entity_ids"]
for entity_id, value in dict(zip(entity_ids, VALUES)).items():
hass.states.async_set(entity_id, value)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_last")
assert str(float(value)) == state.state
assert entity_id == state.attributes.get("last_entity_id")
assert MIN_VALUE == state.attributes.get("min_value")
assert MAX_VALUE == state.attributes.get("max_value")
assert MEAN == state.attributes.get("mean")
assert MEDIAN == state.attributes.get("median") | [
"async",
"def",
"test_last_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test_last\"",
",",
"\"type\"",
":",
"\"last\"",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
",",
"\"sensor.test_3\"",
"]",
",",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entity_ids",
"=",
"config",
"[",
"\"sensor\"",
"]",
"[",
"\"entity_ids\"",
"]",
"for",
"entity_id",
",",
"value",
"in",
"dict",
"(",
"zip",
"(",
"entity_ids",
",",
"VALUES",
")",
")",
".",
"items",
"(",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test_last\"",
")",
"assert",
"str",
"(",
"float",
"(",
"value",
")",
")",
"==",
"state",
".",
"state",
"assert",
"entity_id",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"last_entity_id\"",
")",
"assert",
"MIN_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"min_value\"",
")",
"assert",
"MAX_VALUE",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"max_value\"",
")",
"assert",
"MEAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"mean\"",
")",
"assert",
"MEDIAN",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"median\"",
")"
] | [
316,
0
] | [
342,
51
] | python | en | ['en', 'et', 'en'] | True |
test_reload | (hass) | Verify we can reload filter sensors. | Verify we can reload filter sensors. | async def test_reload(hass):
"""Verify we can reload filter sensors."""
hass.states.async_set("sensor.test_1", 12345)
hass.states.async_set("sensor.test_2", 45678)
await async_setup_component(
hass,
"sensor",
{
"sensor": {
"platform": "min_max",
"name": "test",
"type": "mean",
"entity_ids": ["sensor.test_1", "sensor.test_2"],
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 3
assert hass.states.get("sensor.test")
yaml_path = path.join(
_get_fixtures_base_path(),
"fixtures",
"min_max/configuration.yaml",
)
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
await hass.services.async_call(
DOMAIN,
SERVICE_RELOAD,
{},
blocking=True,
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 3
assert hass.states.get("sensor.test") is None
assert hass.states.get("sensor.second_test") | [
"async",
"def",
"test_reload",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test_1\"",
",",
"12345",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.test_2\"",
",",
"45678",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"min_max\"",
",",
"\"name\"",
":",
"\"test\"",
",",
"\"type\"",
":",
"\"mean\"",
",",
"\"entity_ids\"",
":",
"[",
"\"sensor.test_1\"",
",",
"\"sensor.test_2\"",
"]",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"3",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test\"",
")",
"yaml_path",
"=",
"path",
".",
"join",
"(",
"_get_fixtures_base_path",
"(",
")",
",",
"\"fixtures\"",
",",
"\"min_max/configuration.yaml\"",
",",
")",
"with",
"patch",
".",
"object",
"(",
"hass_config",
",",
"\"YAML_CONFIG_FILE\"",
",",
"yaml_path",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_RELOAD",
",",
"{",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"3",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test\"",
")",
"is",
"None",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.second_test\"",
")"
] | [
345,
0
] | [
385,
48
] | python | en | ['en', 'da', 'en'] | True |
test_water_heater | (
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) | Test the creation of Atag water heater. | Test the creation of Atag water heater. | async def test_water_heater(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the creation of Atag water heater."""
with patch("pyatag.entities.DHW.status"):
entry = await init_integration(hass, aioclient_mock)
registry = await hass.helpers.entity_registry.async_get_registry()
assert registry.async_is_registered(WATER_HEATER_ID)
entry = registry.async_get(WATER_HEATER_ID)
assert entry.unique_id == f"{UID}-{WATER_HEATER}" | [
"async",
"def",
"test_water_heater",
"(",
"hass",
":",
"HomeAssistant",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"pyatag.entities.DHW.status\"",
")",
":",
"entry",
"=",
"await",
"init_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"assert",
"registry",
".",
"async_is_registered",
"(",
"WATER_HEATER_ID",
")",
"entry",
"=",
"registry",
".",
"async_get",
"(",
"WATER_HEATER_ID",
")",
"assert",
"entry",
".",
"unique_id",
"==",
"f\"{UID}-{WATER_HEATER}\""
] | [
14,
0
] | [
24,
57
] | python | en | ['en', 'en', 'en'] | True |
test_setting_target_temperature | (
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) | Test setting the water heater device. | Test setting the water heater device. | async def test_setting_target_temperature(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test setting the water heater device."""
await init_integration(hass, aioclient_mock)
with patch("pyatag.entities.DHW.set_temp") as mock_set_temp:
await hass.services.async_call(
WATER_HEATER,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: WATER_HEATER_ID, ATTR_TEMPERATURE: 50},
blocking=True,
)
await hass.async_block_till_done()
mock_set_temp.assert_called_once_with(50) | [
"async",
"def",
"test_setting_target_temperature",
"(",
"hass",
":",
"HomeAssistant",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"init_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"with",
"patch",
"(",
"\"pyatag.entities.DHW.set_temp\"",
")",
"as",
"mock_set_temp",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"WATER_HEATER",
",",
"SERVICE_SET_TEMPERATURE",
",",
"{",
"ATTR_ENTITY_ID",
":",
"WATER_HEATER_ID",
",",
"ATTR_TEMPERATURE",
":",
"50",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"mock_set_temp",
".",
"assert_called_once_with",
"(",
"50",
")"
] | [
27,
0
] | [
40,
49
] | python | en | ['en', 'en', 'en'] | True |
browse_media | (zone_id, roon_server, media_content_type=None, media_content_id=None) | Implement the websocket media browsing helper. | Implement the websocket media browsing helper. | def browse_media(zone_id, roon_server, media_content_type=None, media_content_id=None):
"""Implement the websocket media browsing helper."""
try:
_LOGGER.debug("browse_media: %s: %s", media_content_type, media_content_id)
if media_content_type in [None, "library"]:
return library_payload(roon_server, zone_id, media_content_id)
except UnknownMediaType as err:
raise BrowseError(
f"Media not found: {media_content_type} / {media_content_id}"
) from err | [
"def",
"browse_media",
"(",
"zone_id",
",",
"roon_server",
",",
"media_content_type",
"=",
"None",
",",
"media_content_id",
"=",
"None",
")",
":",
"try",
":",
"_LOGGER",
".",
"debug",
"(",
"\"browse_media: %s: %s\"",
",",
"media_content_type",
",",
"media_content_id",
")",
"if",
"media_content_type",
"in",
"[",
"None",
",",
"\"library\"",
"]",
":",
"return",
"library_payload",
"(",
"roon_server",
",",
"zone_id",
",",
"media_content_id",
")",
"except",
"UnknownMediaType",
"as",
"err",
":",
"raise",
"BrowseError",
"(",
"f\"Media not found: {media_content_type} / {media_content_id}\"",
")",
"from",
"err"
] | [
40,
0
] | [
50,
18
] | python | en | ['en', 'af', 'en'] | True |
item_payload | (roon_server, item, list_image_id) | Create response payload for a single media item. | Create response payload for a single media item. | def item_payload(roon_server, item, list_image_id):
"""Create response payload for a single media item."""
title = item["title"]
subtitle = item.get("subtitle")
if subtitle is None:
display_title = title
else:
display_title = f"{title} ({subtitle})"
image_id = item.get("image_key") or list_image_id
image = None
if image_id:
image = roon_server.roonapi.get_image(image_id)
media_content_id = item["item_key"]
media_content_type = "library"
hint = item.get("hint")
if hint == "list":
media_class = MEDIA_CLASS_DIRECTORY
can_expand = True
elif hint == "action_list":
media_class = MEDIA_CLASS_PLAYLIST
can_expand = False
elif hint == "action":
media_content_type = "track"
media_class = MEDIA_CLASS_TRACK
can_expand = False
else:
# Roon API says to treat unknown as a list
media_class = MEDIA_CLASS_DIRECTORY
can_expand = True
_LOGGER.warning("Unknown hint %s - %s", title, hint)
payload = {
"title": display_title,
"media_class": media_class,
"media_content_id": media_content_id,
"media_content_type": media_content_type,
"can_play": True,
"can_expand": can_expand,
"thumbnail": image,
}
return BrowseMedia(**payload) | [
"def",
"item_payload",
"(",
"roon_server",
",",
"item",
",",
"list_image_id",
")",
":",
"title",
"=",
"item",
"[",
"\"title\"",
"]",
"subtitle",
"=",
"item",
".",
"get",
"(",
"\"subtitle\"",
")",
"if",
"subtitle",
"is",
"None",
":",
"display_title",
"=",
"title",
"else",
":",
"display_title",
"=",
"f\"{title} ({subtitle})\"",
"image_id",
"=",
"item",
".",
"get",
"(",
"\"image_key\"",
")",
"or",
"list_image_id",
"image",
"=",
"None",
"if",
"image_id",
":",
"image",
"=",
"roon_server",
".",
"roonapi",
".",
"get_image",
"(",
"image_id",
")",
"media_content_id",
"=",
"item",
"[",
"\"item_key\"",
"]",
"media_content_type",
"=",
"\"library\"",
"hint",
"=",
"item",
".",
"get",
"(",
"\"hint\"",
")",
"if",
"hint",
"==",
"\"list\"",
":",
"media_class",
"=",
"MEDIA_CLASS_DIRECTORY",
"can_expand",
"=",
"True",
"elif",
"hint",
"==",
"\"action_list\"",
":",
"media_class",
"=",
"MEDIA_CLASS_PLAYLIST",
"can_expand",
"=",
"False",
"elif",
"hint",
"==",
"\"action\"",
":",
"media_content_type",
"=",
"\"track\"",
"media_class",
"=",
"MEDIA_CLASS_TRACK",
"can_expand",
"=",
"False",
"else",
":",
"# Roon API says to treat unknown as a list",
"media_class",
"=",
"MEDIA_CLASS_DIRECTORY",
"can_expand",
"=",
"True",
"_LOGGER",
".",
"warning",
"(",
"\"Unknown hint %s - %s\"",
",",
"title",
",",
"hint",
")",
"payload",
"=",
"{",
"\"title\"",
":",
"display_title",
",",
"\"media_class\"",
":",
"media_class",
",",
"\"media_content_id\"",
":",
"media_content_id",
",",
"\"media_content_type\"",
":",
"media_content_type",
",",
"\"can_play\"",
":",
"True",
",",
"\"can_expand\"",
":",
"can_expand",
",",
"\"thumbnail\"",
":",
"image",
",",
"}",
"return",
"BrowseMedia",
"(",
"*",
"*",
"payload",
")"
] | [
53,
0
] | [
99,
33
] | python | en | ['en', 'en', 'en'] | True |
library_payload | (roon_server, zone_id, media_content_id) | Create response payload for the library. | Create response payload for the library. | def library_payload(roon_server, zone_id, media_content_id):
"""Create response payload for the library."""
opts = {
"hierarchy": "browse",
"zone_or_output_id": zone_id,
"count": ITEM_LIMIT,
}
# Roon starts browsing for a zone where it left off - so start from the top unless otherwise specified
if media_content_id is None or media_content_id == "Explore":
opts["pop_all"] = True
content_id = "Explore"
else:
opts["item_key"] = media_content_id
content_id = media_content_id
result_header = roon_server.roonapi.browse_browse(opts)
_LOGGER.debug("Result header %s", result_header)
header = result_header["list"]
title = header.get("title")
subtitle = header.get("subtitle")
if subtitle is None:
list_title = title
else:
list_title = f"{title} ({subtitle})"
total_count = header["count"]
library_image_id = header.get("image_key")
library_info = BrowseMedia(
title=list_title,
media_content_id=content_id,
media_content_type="library",
media_class=MEDIA_CLASS_DIRECTORY,
can_play=False,
can_expand=True,
children=[],
)
result_detail = roon_server.roonapi.browse_load(opts)
_LOGGER.debug("Result detail %s", result_detail)
items = result_detail["items"]
count = len(items)
if count < total_count:
_LOGGER.debug(
"Exceeded limit of %d, loaded %d/%d", ITEM_LIMIT, count, total_count
)
for item in items:
if item.get("title") in EXCLUDE_ITEMS:
continue
entry = item_payload(roon_server, item, library_image_id)
library_info.children.append(entry)
return library_info | [
"def",
"library_payload",
"(",
"roon_server",
",",
"zone_id",
",",
"media_content_id",
")",
":",
"opts",
"=",
"{",
"\"hierarchy\"",
":",
"\"browse\"",
",",
"\"zone_or_output_id\"",
":",
"zone_id",
",",
"\"count\"",
":",
"ITEM_LIMIT",
",",
"}",
"# Roon starts browsing for a zone where it left off - so start from the top unless otherwise specified",
"if",
"media_content_id",
"is",
"None",
"or",
"media_content_id",
"==",
"\"Explore\"",
":",
"opts",
"[",
"\"pop_all\"",
"]",
"=",
"True",
"content_id",
"=",
"\"Explore\"",
"else",
":",
"opts",
"[",
"\"item_key\"",
"]",
"=",
"media_content_id",
"content_id",
"=",
"media_content_id",
"result_header",
"=",
"roon_server",
".",
"roonapi",
".",
"browse_browse",
"(",
"opts",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Result header %s\"",
",",
"result_header",
")",
"header",
"=",
"result_header",
"[",
"\"list\"",
"]",
"title",
"=",
"header",
".",
"get",
"(",
"\"title\"",
")",
"subtitle",
"=",
"header",
".",
"get",
"(",
"\"subtitle\"",
")",
"if",
"subtitle",
"is",
"None",
":",
"list_title",
"=",
"title",
"else",
":",
"list_title",
"=",
"f\"{title} ({subtitle})\"",
"total_count",
"=",
"header",
"[",
"\"count\"",
"]",
"library_image_id",
"=",
"header",
".",
"get",
"(",
"\"image_key\"",
")",
"library_info",
"=",
"BrowseMedia",
"(",
"title",
"=",
"list_title",
",",
"media_content_id",
"=",
"content_id",
",",
"media_content_type",
"=",
"\"library\"",
",",
"media_class",
"=",
"MEDIA_CLASS_DIRECTORY",
",",
"can_play",
"=",
"False",
",",
"can_expand",
"=",
"True",
",",
"children",
"=",
"[",
"]",
",",
")",
"result_detail",
"=",
"roon_server",
".",
"roonapi",
".",
"browse_load",
"(",
"opts",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Result detail %s\"",
",",
"result_detail",
")",
"items",
"=",
"result_detail",
"[",
"\"items\"",
"]",
"count",
"=",
"len",
"(",
"items",
")",
"if",
"count",
"<",
"total_count",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Exceeded limit of %d, loaded %d/%d\"",
",",
"ITEM_LIMIT",
",",
"count",
",",
"total_count",
")",
"for",
"item",
"in",
"items",
":",
"if",
"item",
".",
"get",
"(",
"\"title\"",
")",
"in",
"EXCLUDE_ITEMS",
":",
"continue",
"entry",
"=",
"item_payload",
"(",
"roon_server",
",",
"item",
",",
"library_image_id",
")",
"library_info",
".",
"children",
".",
"append",
"(",
"entry",
")",
"return",
"library_info"
] | [
102,
0
] | [
162,
23
] | python | en | ['en', 'en', 'en'] | True |
BaseModel.init_weights | (self, module) | Initialize the weights.
| Initialize the weights.
| def init_weights(self, module):
""" Initialize the weights.
"""
if isinstance(module, (nn.Linear, nn.Embedding)):
# Slightly different from the TF version which uses truncated_normal for initialization
# cf https://github.com/pytorch/pytorch/pull/5617
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
elif isinstance(module, BertLayerNorm):
module.bias.data.zero_()
module.weight.data.fill_(1.0)
if isinstance(module, nn.Linear) and module.bias is not None:
module.bias.data.zero_() | [
"def",
"init_weights",
"(",
"self",
",",
"module",
")",
":",
"if",
"isinstance",
"(",
"module",
",",
"(",
"nn",
".",
"Linear",
",",
"nn",
".",
"Embedding",
")",
")",
":",
"# Slightly different from the TF version which uses truncated_normal for initialization",
"# cf https://github.com/pytorch/pytorch/pull/5617",
"module",
".",
"weight",
".",
"data",
".",
"normal_",
"(",
"mean",
"=",
"0.0",
",",
"std",
"=",
"self",
".",
"config",
".",
"initializer_range",
")",
"elif",
"isinstance",
"(",
"module",
",",
"BertLayerNorm",
")",
":",
"module",
".",
"bias",
".",
"data",
".",
"zero_",
"(",
")",
"module",
".",
"weight",
".",
"data",
".",
"fill_",
"(",
"1.0",
")",
"if",
"isinstance",
"(",
"module",
",",
"nn",
".",
"Linear",
")",
"and",
"module",
".",
"bias",
"is",
"not",
"None",
":",
"module",
".",
"bias",
".",
"data",
".",
"zero_",
"(",
")"
] | [
13,
4
] | [
24,
36
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the mysensors platform for switches. | Set up the mysensors platform for switches. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the mysensors platform for switches."""
device_class_map = {
"S_DOOR": MySensorsSwitch,
"S_MOTION": MySensorsSwitch,
"S_SMOKE": MySensorsSwitch,
"S_LIGHT": MySensorsSwitch,
"S_LOCK": MySensorsSwitch,
"S_IR": MySensorsIRSwitch,
"S_BINARY": MySensorsSwitch,
"S_SPRINKLER": MySensorsSwitch,
"S_WATER_LEAK": MySensorsSwitch,
"S_SOUND": MySensorsSwitch,
"S_VIBRATION": MySensorsSwitch,
"S_MOISTURE": MySensorsSwitch,
"S_WATER_QUALITY": MySensorsSwitch,
}
mysensors.setup_mysensors_platform(
hass,
DOMAIN,
discovery_info,
device_class_map,
async_add_entities=async_add_entities,
)
async def async_send_ir_code_service(service):
"""Set IR code as device state attribute."""
entity_ids = service.data.get(ATTR_ENTITY_ID)
ir_code = service.data.get(ATTR_IR_CODE)
devices = mysensors.get_mysensors_devices(hass, DOMAIN)
if entity_ids:
_devices = [
device
for device in devices.values()
if isinstance(device, MySensorsIRSwitch)
and device.entity_id in entity_ids
]
else:
_devices = [
device
for device in devices.values()
if isinstance(device, MySensorsIRSwitch)
]
kwargs = {ATTR_IR_CODE: ir_code}
for device in _devices:
await device.async_turn_on(**kwargs)
hass.services.async_register(
MYSENSORS_DOMAIN,
SERVICE_SEND_IR_CODE,
async_send_ir_code_service,
schema=SEND_IR_CODE_SERVICE_SCHEMA,
) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"device_class_map",
"=",
"{",
"\"S_DOOR\"",
":",
"MySensorsSwitch",
",",
"\"S_MOTION\"",
":",
"MySensorsSwitch",
",",
"\"S_SMOKE\"",
":",
"MySensorsSwitch",
",",
"\"S_LIGHT\"",
":",
"MySensorsSwitch",
",",
"\"S_LOCK\"",
":",
"MySensorsSwitch",
",",
"\"S_IR\"",
":",
"MySensorsIRSwitch",
",",
"\"S_BINARY\"",
":",
"MySensorsSwitch",
",",
"\"S_SPRINKLER\"",
":",
"MySensorsSwitch",
",",
"\"S_WATER_LEAK\"",
":",
"MySensorsSwitch",
",",
"\"S_SOUND\"",
":",
"MySensorsSwitch",
",",
"\"S_VIBRATION\"",
":",
"MySensorsSwitch",
",",
"\"S_MOISTURE\"",
":",
"MySensorsSwitch",
",",
"\"S_WATER_QUALITY\"",
":",
"MySensorsSwitch",
",",
"}",
"mysensors",
".",
"setup_mysensors_platform",
"(",
"hass",
",",
"DOMAIN",
",",
"discovery_info",
",",
"device_class_map",
",",
"async_add_entities",
"=",
"async_add_entities",
",",
")",
"async",
"def",
"async_send_ir_code_service",
"(",
"service",
")",
":",
"\"\"\"Set IR code as device state attribute.\"\"\"",
"entity_ids",
"=",
"service",
".",
"data",
".",
"get",
"(",
"ATTR_ENTITY_ID",
")",
"ir_code",
"=",
"service",
".",
"data",
".",
"get",
"(",
"ATTR_IR_CODE",
")",
"devices",
"=",
"mysensors",
".",
"get_mysensors_devices",
"(",
"hass",
",",
"DOMAIN",
")",
"if",
"entity_ids",
":",
"_devices",
"=",
"[",
"device",
"for",
"device",
"in",
"devices",
".",
"values",
"(",
")",
"if",
"isinstance",
"(",
"device",
",",
"MySensorsIRSwitch",
")",
"and",
"device",
".",
"entity_id",
"in",
"entity_ids",
"]",
"else",
":",
"_devices",
"=",
"[",
"device",
"for",
"device",
"in",
"devices",
".",
"values",
"(",
")",
"if",
"isinstance",
"(",
"device",
",",
"MySensorsIRSwitch",
")",
"]",
"kwargs",
"=",
"{",
"ATTR_IR_CODE",
":",
"ir_code",
"}",
"for",
"device",
"in",
"_devices",
":",
"await",
"device",
".",
"async_turn_on",
"(",
"*",
"*",
"kwargs",
")",
"hass",
".",
"services",
".",
"async_register",
"(",
"MYSENSORS_DOMAIN",
",",
"SERVICE_SEND_IR_CODE",
",",
"async_send_ir_code_service",
",",
"schema",
"=",
"SEND_IR_CODE_SERVICE_SCHEMA",
",",
")"
] | [
17,
0
] | [
71,
5
] | python | en | ['en', 'en', 'en'] | True |
MySensorsSwitch.assumed_state | (self) | Return True if unable to access real state of entity. | Return True if unable to access real state of entity. | def assumed_state(self):
"""Return True if unable to access real state of entity."""
return self.gateway.optimistic | [
"def",
"assumed_state",
"(",
"self",
")",
":",
"return",
"self",
".",
"gateway",
".",
"optimistic"
] | [
78,
4
] | [
80,
38
] | python | en | ['en', 'en', 'en'] | True |
MySensorsSwitch.current_power_w | (self) | Return the current power usage in W. | Return the current power usage in W. | def current_power_w(self):
"""Return the current power usage in W."""
set_req = self.gateway.const.SetReq
return self._values.get(set_req.V_WATT) | [
"def",
"current_power_w",
"(",
"self",
")",
":",
"set_req",
"=",
"self",
".",
"gateway",
".",
"const",
".",
"SetReq",
"return",
"self",
".",
"_values",
".",
"get",
"(",
"set_req",
".",
"V_WATT",
")"
] | [
83,
4
] | [
86,
47
] | python | en | ['en', 'en', 'en'] | True |
MySensorsSwitch.is_on | (self) | Return True if switch is on. | Return True if switch is on. | def is_on(self):
"""Return True if switch is on."""
return self._values.get(self.value_type) == STATE_ON | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_values",
".",
"get",
"(",
"self",
".",
"value_type",
")",
"==",
"STATE_ON"
] | [
89,
4
] | [
91,
60
] | python | en | ['en', 'fy', 'en'] | True |
MySensorsSwitch.async_turn_on | (self, **kwargs) | Turn the switch on. | Turn the switch on. | async def async_turn_on(self, **kwargs):
"""Turn the switch on."""
self.gateway.set_child_value(
self.node_id, self.child_id, self.value_type, 1, ack=1
)
if self.gateway.optimistic:
# Optimistically assume that switch has changed state
self._values[self.value_type] = STATE_ON
self.async_write_ha_state() | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"gateway",
".",
"set_child_value",
"(",
"self",
".",
"node_id",
",",
"self",
".",
"child_id",
",",
"self",
".",
"value_type",
",",
"1",
",",
"ack",
"=",
"1",
")",
"if",
"self",
".",
"gateway",
".",
"optimistic",
":",
"# Optimistically assume that switch has changed state",
"self",
".",
"_values",
"[",
"self",
".",
"value_type",
"]",
"=",
"STATE_ON",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
93,
4
] | [
101,
39
] | python | en | ['en', 'en', 'en'] | True |
MySensorsSwitch.async_turn_off | (self, **kwargs) | Turn the switch off. | Turn the switch off. | async def async_turn_off(self, **kwargs):
"""Turn the switch off."""
self.gateway.set_child_value(
self.node_id, self.child_id, self.value_type, 0, ack=1
)
if self.gateway.optimistic:
# Optimistically assume that switch has changed state
self._values[self.value_type] = STATE_OFF
self.async_write_ha_state() | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"gateway",
".",
"set_child_value",
"(",
"self",
".",
"node_id",
",",
"self",
".",
"child_id",
",",
"self",
".",
"value_type",
",",
"0",
",",
"ack",
"=",
"1",
")",
"if",
"self",
".",
"gateway",
".",
"optimistic",
":",
"# Optimistically assume that switch has changed state",
"self",
".",
"_values",
"[",
"self",
".",
"value_type",
"]",
"=",
"STATE_OFF",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
103,
4
] | [
111,
39
] | python | en | ['en', 'en', 'en'] | True |
MySensorsIRSwitch.__init__ | (self, *args) | Set up instance attributes. | Set up instance attributes. | def __init__(self, *args):
"""Set up instance attributes."""
super().__init__(*args)
self._ir_code = None | [
"def",
"__init__",
"(",
"self",
",",
"*",
"args",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"*",
"args",
")",
"self",
".",
"_ir_code",
"=",
"None"
] | [
117,
4
] | [
120,
28
] | python | en | ['en', 'en', 'en'] | True |
MySensorsIRSwitch.is_on | (self) | Return True if switch is on. | Return True if switch is on. | def is_on(self):
"""Return True if switch is on."""
set_req = self.gateway.const.SetReq
return self._values.get(set_req.V_LIGHT) == STATE_ON | [
"def",
"is_on",
"(",
"self",
")",
":",
"set_req",
"=",
"self",
".",
"gateway",
".",
"const",
".",
"SetReq",
"return",
"self",
".",
"_values",
".",
"get",
"(",
"set_req",
".",
"V_LIGHT",
")",
"==",
"STATE_ON"
] | [
123,
4
] | [
126,
60
] | python | en | ['en', 'fy', 'en'] | True |
MySensorsIRSwitch.async_turn_on | (self, **kwargs) | Turn the IR switch on. | Turn the IR switch on. | async def async_turn_on(self, **kwargs):
"""Turn the IR switch on."""
set_req = self.gateway.const.SetReq
if ATTR_IR_CODE in kwargs:
self._ir_code = kwargs[ATTR_IR_CODE]
self.gateway.set_child_value(
self.node_id, self.child_id, self.value_type, self._ir_code
)
self.gateway.set_child_value(
self.node_id, self.child_id, set_req.V_LIGHT, 1, ack=1
)
if self.gateway.optimistic:
# Optimistically assume that switch has changed state
self._values[self.value_type] = self._ir_code
self._values[set_req.V_LIGHT] = STATE_ON
self.async_write_ha_state()
# Turn off switch after switch was turned on
await self.async_turn_off() | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"set_req",
"=",
"self",
".",
"gateway",
".",
"const",
".",
"SetReq",
"if",
"ATTR_IR_CODE",
"in",
"kwargs",
":",
"self",
".",
"_ir_code",
"=",
"kwargs",
"[",
"ATTR_IR_CODE",
"]",
"self",
".",
"gateway",
".",
"set_child_value",
"(",
"self",
".",
"node_id",
",",
"self",
".",
"child_id",
",",
"self",
".",
"value_type",
",",
"self",
".",
"_ir_code",
")",
"self",
".",
"gateway",
".",
"set_child_value",
"(",
"self",
".",
"node_id",
",",
"self",
".",
"child_id",
",",
"set_req",
".",
"V_LIGHT",
",",
"1",
",",
"ack",
"=",
"1",
")",
"if",
"self",
".",
"gateway",
".",
"optimistic",
":",
"# Optimistically assume that switch has changed state",
"self",
".",
"_values",
"[",
"self",
".",
"value_type",
"]",
"=",
"self",
".",
"_ir_code",
"self",
".",
"_values",
"[",
"set_req",
".",
"V_LIGHT",
"]",
"=",
"STATE_ON",
"self",
".",
"async_write_ha_state",
"(",
")",
"# Turn off switch after switch was turned on",
"await",
"self",
".",
"async_turn_off",
"(",
")"
] | [
128,
4
] | [
145,
39
] | python | en | ['en', 'zh', 'en'] | True |
MySensorsIRSwitch.async_turn_off | (self, **kwargs) | Turn the IR switch off. | Turn the IR switch off. | async def async_turn_off(self, **kwargs):
"""Turn the IR switch off."""
set_req = self.gateway.const.SetReq
self.gateway.set_child_value(
self.node_id, self.child_id, set_req.V_LIGHT, 0, ack=1
)
if self.gateway.optimistic:
# Optimistically assume that switch has changed state
self._values[set_req.V_LIGHT] = STATE_OFF
self.async_write_ha_state() | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"set_req",
"=",
"self",
".",
"gateway",
".",
"const",
".",
"SetReq",
"self",
".",
"gateway",
".",
"set_child_value",
"(",
"self",
".",
"node_id",
",",
"self",
".",
"child_id",
",",
"set_req",
".",
"V_LIGHT",
",",
"0",
",",
"ack",
"=",
"1",
")",
"if",
"self",
".",
"gateway",
".",
"optimistic",
":",
"# Optimistically assume that switch has changed state",
"self",
".",
"_values",
"[",
"set_req",
".",
"V_LIGHT",
"]",
"=",
"STATE_OFF",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
147,
4
] | [
156,
39
] | python | en | ['en', 'zh', 'en'] | True |
MySensorsIRSwitch.async_update | (self) | Update the controller with the latest value from a sensor. | Update the controller with the latest value from a sensor. | async def async_update(self):
"""Update the controller with the latest value from a sensor."""
await super().async_update()
self._ir_code = self._values.get(self.value_type) | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_update",
"(",
")",
"self",
".",
"_ir_code",
"=",
"self",
".",
"_values",
".",
"get",
"(",
"self",
".",
"value_type",
")"
] | [
158,
4
] | [
161,
57
] | python | en | ['en', 'en', 'en'] | True |
async_get_actions | (hass: HomeAssistant, device_id: str) | List device actions for Alarm control panel devices. | List device actions for Alarm control panel devices. | async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]:
"""List device actions for Alarm control panel devices."""
registry = await entity_registry.async_get_registry(hass)
actions = []
# Get all the integrations entities for this device
for entry in entity_registry.async_entries_for_device(registry, device_id):
if entry.domain != DOMAIN:
continue
state = hass.states.get(entry.entity_id)
# We need a state or else we can't populate the HVAC and preset modes.
if state is None:
continue
supported_features = state.attributes[ATTR_SUPPORTED_FEATURES]
# Add actions for each entity that belongs to this integration
if supported_features & SUPPORT_ALARM_ARM_AWAY:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "arm_away",
}
)
if supported_features & SUPPORT_ALARM_ARM_HOME:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "arm_home",
}
)
if supported_features & SUPPORT_ALARM_ARM_NIGHT:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "arm_night",
}
)
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "disarm",
}
)
if supported_features & SUPPORT_ALARM_TRIGGER:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "trigger",
}
)
return actions | [
"async",
"def",
"async_get_actions",
"(",
"hass",
":",
"HomeAssistant",
",",
"device_id",
":",
"str",
")",
"->",
"List",
"[",
"dict",
"]",
":",
"registry",
"=",
"await",
"entity_registry",
".",
"async_get_registry",
"(",
"hass",
")",
"actions",
"=",
"[",
"]",
"# Get all the integrations entities for this device",
"for",
"entry",
"in",
"entity_registry",
".",
"async_entries_for_device",
"(",
"registry",
",",
"device_id",
")",
":",
"if",
"entry",
".",
"domain",
"!=",
"DOMAIN",
":",
"continue",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entry",
".",
"entity_id",
")",
"# We need a state or else we can't populate the HVAC and preset modes.",
"if",
"state",
"is",
"None",
":",
"continue",
"supported_features",
"=",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"# Add actions for each entity that belongs to this integration",
"if",
"supported_features",
"&",
"SUPPORT_ALARM_ARM_AWAY",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"arm_away\"",
",",
"}",
")",
"if",
"supported_features",
"&",
"SUPPORT_ALARM_ARM_HOME",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"arm_home\"",
",",
"}",
")",
"if",
"supported_features",
"&",
"SUPPORT_ALARM_ARM_NIGHT",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"arm_night\"",
",",
"}",
")",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"disarm\"",
",",
"}",
")",
"if",
"supported_features",
"&",
"SUPPORT_ALARM_TRIGGER",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"trigger\"",
",",
"}",
")",
"return",
"actions"
] | [
43,
0
] | [
107,
18
] | python | en | ['fr', 'en', 'en'] | True |
async_call_action_from_config | (
hass: HomeAssistant, config: dict, variables: dict, context: Optional[Context]
) | Execute a device action. | Execute a device action. | async def async_call_action_from_config(
hass: HomeAssistant, config: dict, variables: dict, context: Optional[Context]
) -> None:
"""Execute a device action."""
config = ACTION_SCHEMA(config)
service_data = {ATTR_ENTITY_ID: config[CONF_ENTITY_ID]}
if CONF_CODE in config:
service_data[ATTR_CODE] = config[CONF_CODE]
if config[CONF_TYPE] == "arm_away":
service = SERVICE_ALARM_ARM_AWAY
elif config[CONF_TYPE] == "arm_home":
service = SERVICE_ALARM_ARM_HOME
elif config[CONF_TYPE] == "arm_night":
service = SERVICE_ALARM_ARM_NIGHT
elif config[CONF_TYPE] == "disarm":
service = SERVICE_ALARM_DISARM
elif config[CONF_TYPE] == "trigger":
service = SERVICE_ALARM_TRIGGER
await hass.services.async_call(
DOMAIN, service, service_data, blocking=True, context=context
) | [
"async",
"def",
"async_call_action_from_config",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
",",
"variables",
":",
"dict",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
")",
"->",
"None",
":",
"config",
"=",
"ACTION_SCHEMA",
"(",
"config",
")",
"service_data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"config",
"[",
"CONF_ENTITY_ID",
"]",
"}",
"if",
"CONF_CODE",
"in",
"config",
":",
"service_data",
"[",
"ATTR_CODE",
"]",
"=",
"config",
"[",
"CONF_CODE",
"]",
"if",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"arm_away\"",
":",
"service",
"=",
"SERVICE_ALARM_ARM_AWAY",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"arm_home\"",
":",
"service",
"=",
"SERVICE_ALARM_ARM_HOME",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"arm_night\"",
":",
"service",
"=",
"SERVICE_ALARM_ARM_NIGHT",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"disarm\"",
":",
"service",
"=",
"SERVICE_ALARM_DISARM",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"trigger\"",
":",
"service",
"=",
"SERVICE_ALARM_TRIGGER",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"service",
",",
"service_data",
",",
"blocking",
"=",
"True",
",",
"context",
"=",
"context",
")"
] | [
110,
0
] | [
133,
5
] | python | en | ['ro', 'en', 'en'] | True |
async_get_action_capabilities | (hass, config) | List action capabilities. | List action capabilities. | async def async_get_action_capabilities(hass, config):
"""List action capabilities."""
state = hass.states.get(config[CONF_ENTITY_ID])
code_required = state.attributes.get(ATTR_CODE_ARM_REQUIRED) if state else False
if config[CONF_TYPE] == "trigger" or (
config[CONF_TYPE] != "disarm" and not code_required
):
return {}
return {"extra_fields": vol.Schema({vol.Optional(CONF_CODE): str})} | [
"async",
"def",
"async_get_action_capabilities",
"(",
"hass",
",",
"config",
")",
":",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"config",
"[",
"CONF_ENTITY_ID",
"]",
")",
"code_required",
"=",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_CODE_ARM_REQUIRED",
")",
"if",
"state",
"else",
"False",
"if",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"trigger\"",
"or",
"(",
"config",
"[",
"CONF_TYPE",
"]",
"!=",
"\"disarm\"",
"and",
"not",
"code_required",
")",
":",
"return",
"{",
"}",
"return",
"{",
"\"extra_fields\"",
":",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Optional",
"(",
"CONF_CODE",
")",
":",
"str",
"}",
")",
"}"
] | [
136,
0
] | [
146,
71
] | python | en | ['ro', 'ga', 'en'] | False |
convert | (value: float, unit_1: str, unit_2: str) | Convert one unit of measurement to another. | Convert one unit of measurement to another. | def convert(value: float, unit_1: str, unit_2: str) -> float:
"""Convert one unit of measurement to another."""
if unit_1 not in VALID_UNITS:
raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(unit_1, LENGTH))
if unit_2 not in VALID_UNITS:
raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(unit_2, LENGTH))
if not isinstance(value, Number):
raise TypeError(f"{value} is not of numeric type")
if unit_1 == unit_2 or unit_1 not in VALID_UNITS:
return value
meters: float = TO_METERS[unit_1](value)
return METERS_TO[unit_2](meters) | [
"def",
"convert",
"(",
"value",
":",
"float",
",",
"unit_1",
":",
"str",
",",
"unit_2",
":",
"str",
")",
"->",
"float",
":",
"if",
"unit_1",
"not",
"in",
"VALID_UNITS",
":",
"raise",
"ValueError",
"(",
"UNIT_NOT_RECOGNIZED_TEMPLATE",
".",
"format",
"(",
"unit_1",
",",
"LENGTH",
")",
")",
"if",
"unit_2",
"not",
"in",
"VALID_UNITS",
":",
"raise",
"ValueError",
"(",
"UNIT_NOT_RECOGNIZED_TEMPLATE",
".",
"format",
"(",
"unit_2",
",",
"LENGTH",
")",
")",
"if",
"not",
"isinstance",
"(",
"value",
",",
"Number",
")",
":",
"raise",
"TypeError",
"(",
"f\"{value} is not of numeric type\"",
")",
"if",
"unit_1",
"==",
"unit_2",
"or",
"unit_1",
"not",
"in",
"VALID_UNITS",
":",
"return",
"value",
"meters",
":",
"float",
"=",
"TO_METERS",
"[",
"unit_1",
"]",
"(",
"value",
")",
"return",
"METERS_TO",
"[",
"unit_2",
"]",
"(",
"meters",
")"
] | [
51,
0
] | [
66,
36
] | python | en | ['en', 'en', 'en'] | True |
glue_convert_examples_to_features | (
examples: Union[List[InputExample], "tf.data.Dataset"],
tokenizer: PreTrainedTokenizer,
max_length: Optional[int] = None,
task=None,
label_list=None,
output_mode=None,
) |
Loads a data file into a list of ``InputFeatures``
Args:
examples: List of ``InputExamples`` or ``tf.data.Dataset`` containing the examples.
tokenizer: Instance of a tokenizer that will tokenize the examples
max_length: Maximum example length. Defaults to the tokenizer's max_len
task: GLUE task
label_list: List of labels. Can be obtained from the processor using the ``processor.get_labels()`` method
output_mode: String indicating the output mode. Either ``regression`` or ``classification``
Returns:
If the ``examples`` input is a ``tf.data.Dataset``, will return a ``tf.data.Dataset`` containing the
task-specific features. If the input is a list of ``InputExamples``, will return a list of task-specific
``InputFeatures`` which can be fed to the model.
|
Loads a data file into a list of ``InputFeatures`` | def glue_convert_examples_to_features(
examples: Union[List[InputExample], "tf.data.Dataset"],
tokenizer: PreTrainedTokenizer,
max_length: Optional[int] = None,
task=None,
label_list=None,
output_mode=None,
):
"""
Loads a data file into a list of ``InputFeatures``
Args:
examples: List of ``InputExamples`` or ``tf.data.Dataset`` containing the examples.
tokenizer: Instance of a tokenizer that will tokenize the examples
max_length: Maximum example length. Defaults to the tokenizer's max_len
task: GLUE task
label_list: List of labels. Can be obtained from the processor using the ``processor.get_labels()`` method
output_mode: String indicating the output mode. Either ``regression`` or ``classification``
Returns:
If the ``examples`` input is a ``tf.data.Dataset``, will return a ``tf.data.Dataset`` containing the
task-specific features. If the input is a list of ``InputExamples``, will return a list of task-specific
``InputFeatures`` which can be fed to the model.
"""
warnings.warn(DEPRECATION_WARNING.format("function"), FutureWarning)
if is_tf_available() and isinstance(examples, tf.data.Dataset):
if task is None:
raise ValueError("When calling glue_convert_examples_to_features from TF, the task parameter is required.")
return _tf_glue_convert_examples_to_features(examples, tokenizer, max_length=max_length, task=task)
return _glue_convert_examples_to_features(
examples, tokenizer, max_length=max_length, task=task, label_list=label_list, output_mode=output_mode
) | [
"def",
"glue_convert_examples_to_features",
"(",
"examples",
":",
"Union",
"[",
"List",
"[",
"InputExample",
"]",
",",
"\"tf.data.Dataset\"",
"]",
",",
"tokenizer",
":",
"PreTrainedTokenizer",
",",
"max_length",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
",",
"task",
"=",
"None",
",",
"label_list",
"=",
"None",
",",
"output_mode",
"=",
"None",
",",
")",
":",
"warnings",
".",
"warn",
"(",
"DEPRECATION_WARNING",
".",
"format",
"(",
"\"function\"",
")",
",",
"FutureWarning",
")",
"if",
"is_tf_available",
"(",
")",
"and",
"isinstance",
"(",
"examples",
",",
"tf",
".",
"data",
".",
"Dataset",
")",
":",
"if",
"task",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"When calling glue_convert_examples_to_features from TF, the task parameter is required.\"",
")",
"return",
"_tf_glue_convert_examples_to_features",
"(",
"examples",
",",
"tokenizer",
",",
"max_length",
"=",
"max_length",
",",
"task",
"=",
"task",
")",
"return",
"_glue_convert_examples_to_features",
"(",
"examples",
",",
"tokenizer",
",",
"max_length",
"=",
"max_length",
",",
"task",
"=",
"task",
",",
"label_list",
"=",
"label_list",
",",
"output_mode",
"=",
"output_mode",
")"
] | [
41,
0
] | [
73,
5
] | python | en | ['en', 'error', 'th'] | False |
MrpcProcessor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["sentence1"].numpy().decode("utf-8"),
tensor_dict["sentence2"].numpy().decode("utf-8"),
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"sentence1\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"tensor_dict",
"[",
"\"sentence2\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
176,
4
] | [
183,
9
] | python | en | ['en', 'en', 'en'] | True |
MrpcProcessor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
logger.info("LOOKING AT {}".format(os.path.join(data_dir, "train.tsv")))
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"logger",
".",
"info",
"(",
"\"LOOKING AT {}\"",
".",
"format",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
")",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
185,
4
] | [
188,
98
] | python | en | ['en', 'en', 'en'] | True |
MrpcProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev.tsv\"",
")",
")",
",",
"\"dev\"",
")"
] | [
190,
4
] | [
192,
94
] | python | en | ['en', 'en', 'en'] | True |
MrpcProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test.tsv")), "test") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test.tsv\"",
")",
")",
",",
"\"test\"",
")"
] | [
194,
4
] | [
196,
96
] | python | en | ['en', 'en', 'en'] | True |
MrpcProcessor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return ["0", "1"] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"\"0\"",
",",
"\"1\"",
"]"
] | [
198,
4
] | [
200,
25
] | python | en | ['en', 'en', 'en'] | True |
MrpcProcessor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, i)
text_a = line[3]
text_b = line[4]
label = None if set_type == "test" else line[0]
examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"i",
")",
"text_a",
"=",
"line",
"[",
"3",
"]",
"text_b",
"=",
"line",
"[",
"4",
"]",
"label",
"=",
"None",
"if",
"set_type",
"==",
"\"test\"",
"else",
"line",
"[",
"0",
"]",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"text_b",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
202,
4
] | [
213,
23
] | python | en | ['en', 'en', 'en'] | True |
MnliProcessor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["premise"].numpy().decode("utf-8"),
tensor_dict["hypothesis"].numpy().decode("utf-8"),
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"premise\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"tensor_dict",
"[",
"\"hypothesis\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
223,
4
] | [
230,
9
] | python | en | ['en', 'en', 'en'] | True |
MnliProcessor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
232,
4
] | [
234,
98
] | python | en | ['en', 'en', 'en'] | True |
MnliProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev_matched.tsv")), "dev_matched") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev_matched.tsv\"",
")",
")",
",",
"\"dev_matched\"",
")"
] | [
236,
4
] | [
238,
110
] | python | en | ['en', 'en', 'en'] | True |
MnliProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test_matched.tsv")), "test_matched") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test_matched.tsv\"",
")",
")",
",",
"\"test_matched\"",
")"
] | [
240,
4
] | [
242,
112
] | python | en | ['en', 'en', 'en'] | True |
MnliProcessor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return ["contradiction", "entailment", "neutral"] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"\"contradiction\"",
",",
"\"entailment\"",
",",
"\"neutral\"",
"]"
] | [
244,
4
] | [
246,
57
] | python | en | ['en', 'en', 'en'] | True |
MnliProcessor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, line[0])
text_a = line[8]
text_b = line[9]
label = None if set_type.startswith("test") else line[-1]
examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"line",
"[",
"0",
"]",
")",
"text_a",
"=",
"line",
"[",
"8",
"]",
"text_b",
"=",
"line",
"[",
"9",
"]",
"label",
"=",
"None",
"if",
"set_type",
".",
"startswith",
"(",
"\"test\"",
")",
"else",
"line",
"[",
"-",
"1",
"]",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"text_b",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
248,
4
] | [
259,
23
] | python | en | ['en', 'en', 'en'] | True |
MnliMismatchedProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev_mismatched.tsv")), "dev_mismatched") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev_mismatched.tsv\"",
")",
")",
",",
"\"dev_mismatched\"",
")"
] | [
269,
4
] | [
271,
116
] | python | en | ['en', 'en', 'en'] | True |
MnliMismatchedProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test_mismatched.tsv")), "test_mismatched") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test_mismatched.tsv\"",
")",
")",
",",
"\"test_mismatched\"",
")"
] | [
273,
4
] | [
275,
118
] | python | en | ['en', 'en', 'en'] | True |
ColaProcessor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["sentence"].numpy().decode("utf-8"),
None,
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"sentence\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"None",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
285,
4
] | [
292,
9
] | python | en | ['en', 'en', 'en'] | True |
ColaProcessor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
294,
4
] | [
296,
98
] | python | en | ['en', 'en', 'en'] | True |
ColaProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev.tsv\"",
")",
")",
",",
"\"dev\"",
")"
] | [
298,
4
] | [
300,
94
] | python | en | ['en', 'en', 'en'] | True |
ColaProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test.tsv")), "test") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test.tsv\"",
")",
")",
",",
"\"test\"",
")"
] | [
302,
4
] | [
304,
96
] | python | en | ['en', 'en', 'en'] | True |
ColaProcessor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return ["0", "1"] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"\"0\"",
",",
"\"1\"",
"]"
] | [
306,
4
] | [
308,
25
] | python | en | ['en', 'en', 'en'] | True |
ColaProcessor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
test_mode = set_type == "test"
if test_mode:
lines = lines[1:]
text_index = 1 if test_mode else 3
examples = []
for (i, line) in enumerate(lines):
guid = "%s-%s" % (set_type, i)
text_a = line[text_index]
label = None if test_mode else line[1]
examples.append(InputExample(guid=guid, text_a=text_a, text_b=None, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"test_mode",
"=",
"set_type",
"==",
"\"test\"",
"if",
"test_mode",
":",
"lines",
"=",
"lines",
"[",
"1",
":",
"]",
"text_index",
"=",
"1",
"if",
"test_mode",
"else",
"3",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"i",
")",
"text_a",
"=",
"line",
"[",
"text_index",
"]",
"label",
"=",
"None",
"if",
"test_mode",
"else",
"line",
"[",
"1",
"]",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"None",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
310,
4
] | [
322,
23
] | python | en | ['en', 'en', 'en'] | True |
Sst2Processor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["sentence"].numpy().decode("utf-8"),
None,
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"sentence\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"None",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
332,
4
] | [
339,
9
] | python | en | ['en', 'en', 'en'] | True |
Sst2Processor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
341,
4
] | [
343,
98
] | python | en | ['en', 'en', 'en'] | True |
Sst2Processor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev.tsv\"",
")",
")",
",",
"\"dev\"",
")"
] | [
345,
4
] | [
347,
94
] | python | en | ['en', 'en', 'en'] | True |
Sst2Processor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test.tsv")), "test") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test.tsv\"",
")",
")",
",",
"\"test\"",
")"
] | [
349,
4
] | [
351,
96
] | python | en | ['en', 'en', 'en'] | True |
Sst2Processor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return ["0", "1"] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"\"0\"",
",",
"\"1\"",
"]"
] | [
353,
4
] | [
355,
25
] | python | en | ['en', 'en', 'en'] | True |
Sst2Processor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
examples = []
text_index = 1 if set_type == "test" else 0
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, i)
text_a = line[text_index]
label = None if set_type == "test" else line[1]
examples.append(InputExample(guid=guid, text_a=text_a, text_b=None, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"examples",
"=",
"[",
"]",
"text_index",
"=",
"1",
"if",
"set_type",
"==",
"\"test\"",
"else",
"0",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"i",
")",
"text_a",
"=",
"line",
"[",
"text_index",
"]",
"label",
"=",
"None",
"if",
"set_type",
"==",
"\"test\"",
"else",
"line",
"[",
"1",
"]",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"None",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
357,
4
] | [
368,
23
] | python | en | ['en', 'en', 'en'] | True |
StsbProcessor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["sentence1"].numpy().decode("utf-8"),
tensor_dict["sentence2"].numpy().decode("utf-8"),
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"sentence1\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"tensor_dict",
"[",
"\"sentence2\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
378,
4
] | [
385,
9
] | python | en | ['en', 'en', 'en'] | True |
StsbProcessor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
387,
4
] | [
389,
98
] | python | en | ['en', 'en', 'en'] | True |
StsbProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev.tsv\"",
")",
")",
",",
"\"dev\"",
")"
] | [
391,
4
] | [
393,
94
] | python | en | ['en', 'en', 'en'] | True |
StsbProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test.tsv")), "test") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test.tsv\"",
")",
")",
",",
"\"test\"",
")"
] | [
395,
4
] | [
397,
96
] | python | en | ['en', 'en', 'en'] | True |
StsbProcessor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return [None] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"None",
"]"
] | [
399,
4
] | [
401,
21
] | python | en | ['en', 'en', 'en'] | True |
StsbProcessor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, line[0])
text_a = line[7]
text_b = line[8]
label = None if set_type == "test" else line[-1]
examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"line",
"[",
"0",
"]",
")",
"text_a",
"=",
"line",
"[",
"7",
"]",
"text_b",
"=",
"line",
"[",
"8",
"]",
"label",
"=",
"None",
"if",
"set_type",
"==",
"\"test\"",
"else",
"line",
"[",
"-",
"1",
"]",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"text_b",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
403,
4
] | [
414,
23
] | python | en | ['en', 'en', 'en'] | True |
QqpProcessor.get_example_from_tensor_dict | (self, tensor_dict) | See base class. | See base class. | def get_example_from_tensor_dict(self, tensor_dict):
"""See base class."""
return InputExample(
tensor_dict["idx"].numpy(),
tensor_dict["question1"].numpy().decode("utf-8"),
tensor_dict["question2"].numpy().decode("utf-8"),
str(tensor_dict["label"].numpy()),
) | [
"def",
"get_example_from_tensor_dict",
"(",
"self",
",",
"tensor_dict",
")",
":",
"return",
"InputExample",
"(",
"tensor_dict",
"[",
"\"idx\"",
"]",
".",
"numpy",
"(",
")",
",",
"tensor_dict",
"[",
"\"question1\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"tensor_dict",
"[",
"\"question2\"",
"]",
".",
"numpy",
"(",
")",
".",
"decode",
"(",
"\"utf-8\"",
")",
",",
"str",
"(",
"tensor_dict",
"[",
"\"label\"",
"]",
".",
"numpy",
"(",
")",
")",
",",
")"
] | [
424,
4
] | [
431,
9
] | python | en | ['en', 'en', 'en'] | True |
QqpProcessor.get_train_examples | (self, data_dir) | See base class. | See base class. | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | [
433,
4
] | [
435,
98
] | python | en | ['en', 'en', 'en'] | True |
QqpProcessor.get_dev_examples | (self, data_dir) | See base class. | See base class. | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev.tsv\"",
")",
")",
",",
"\"dev\"",
")"
] | [
437,
4
] | [
439,
94
] | python | en | ['en', 'en', 'en'] | True |
QqpProcessor.get_test_examples | (self, data_dir) | See base class. | See base class. | def get_test_examples(self, data_dir):
"""See base class."""
return self._create_examples(self._read_tsv(os.path.join(data_dir, "test.tsv")), "test") | [
"def",
"get_test_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"test.tsv\"",
")",
")",
",",
"\"test\"",
")"
] | [
441,
4
] | [
443,
96
] | python | en | ['en', 'en', 'en'] | True |
QqpProcessor.get_labels | (self) | See base class. | See base class. | def get_labels(self):
"""See base class."""
return ["0", "1"] | [
"def",
"get_labels",
"(",
"self",
")",
":",
"return",
"[",
"\"0\"",
",",
"\"1\"",
"]"
] | [
445,
4
] | [
447,
25
] | python | en | ['en', 'en', 'en'] | True |
QqpProcessor._create_examples | (self, lines, set_type) | Creates examples for the training, dev and test sets. | Creates examples for the training, dev and test sets. | def _create_examples(self, lines, set_type):
"""Creates examples for the training, dev and test sets."""
test_mode = set_type == "test"
q1_index = 1 if test_mode else 3
q2_index = 2 if test_mode else 4
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, line[0])
try:
text_a = line[q1_index]
text_b = line[q2_index]
label = None if test_mode else line[5]
except IndexError:
continue
examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
return examples | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"test_mode",
"=",
"set_type",
"==",
"\"test\"",
"q1_index",
"=",
"1",
"if",
"test_mode",
"else",
"3",
"q2_index",
"=",
"2",
"if",
"test_mode",
"else",
"4",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"",
"%",
"(",
"set_type",
",",
"line",
"[",
"0",
"]",
")",
"try",
":",
"text_a",
"=",
"line",
"[",
"q1_index",
"]",
"text_b",
"=",
"line",
"[",
"q2_index",
"]",
"label",
"=",
"None",
"if",
"test_mode",
"else",
"line",
"[",
"5",
"]",
"except",
"IndexError",
":",
"continue",
"examples",
".",
"append",
"(",
"InputExample",
"(",
"guid",
"=",
"guid",
",",
"text_a",
"=",
"text_a",
",",
"text_b",
"=",
"text_b",
",",
"label",
"=",
"label",
")",
")",
"return",
"examples"
] | [
449,
4
] | [
466,
23
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.