本文整理汇总了Python中homeassistant.util.slugify方法的典型用法代码示例。如果您正苦于以下问题:Python util.slugify方法的具体用法?Python util.slugify怎么用?Python util.slugify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类homeassistant.util
的用法示例。
在下文中一共展示了util.slugify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_scanner
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def setup_scanner(hass, config, see, discovery_info=None):
"""Set up the Volkswagen tracker."""
if discovery_info is None:
return
vin, _ = discovery_info
vw = hass.data[DATA_KEY]
vehicle = vw.vehicles[vin]
def see_vehicle(vehicle):
"""Handle the reporting of the vehicle position."""
host_name = vw.vehicle_name(vehicle)
dev_id = '{}'.format(slugify(host_name))
attrs = {}
if vehicle.model_image:
attrs['entity_picture'] = vehicle.model_image
_LOGGER.debug('Updating location of %s' % host_name)
see(dev_id=dev_id, host_name=host_name, gps=(vehicle.position['lat'], vehicle.position['lng']), attributes=attrs, icon='mdi:car')
dispatcher_connect(hass, SIGNAL_VEHICLE_SEEN, see_vehicle)
dispatcher_send(hass, SIGNAL_VEHICLE_SEEN, vehicle)
return True
示例2: async_setup_scanner
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def async_setup_scanner(hass, config, async_see, discovery_info=None):
"""Set up the Volkswagen tracker."""
if discovery_info is None:
return
vin, component, attr = discovery_info
data = hass.data[DATA_KEY]
instrument = data.instrument(vin, component, attr)
async def see_vehicle():
"""Handle the reporting of the vehicle position."""
host_name = data.vehicle_name(instrument.vehicle)
dev_id = '{}'.format(slugify(host_name))
_LOGGER.debug('Getting location of %s' % host_name)
await async_see(
dev_id=dev_id,
host_name=host_name,
source_type=SOURCE_TYPE_GPS,
gps=instrument.state,
icon="mdi:car",
)
async_dispatcher_connect(hass, SIGNAL_STATE_UPDATED, see_vehicle)
return True
示例3: device_info
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def device_info(self):
"""Return device information about Opensprinkler Controller."""
controller = self.hass.data[DOMAIN][self._entry.entry_id]["controller"]
model = controller.hardware_version_name or "Unknown"
if controller.hardware_type_name:
model += f" - ({controller.hardware_type_name})"
firmware = controller.firmware_version_name or "Unknown"
firmware += f" ({ controller.firmware_minor_version })"
return {
"identifiers": {(DOMAIN, slugify(self._entry.unique_id))},
"name": self._name,
"manufacturer": "OpenSprinkler",
"model": model,
"sw_version": firmware,
}
示例4: __init__
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def __init__(self, device, host, config):
"""Initialize sensor."""
self._device = device
self._host = host
self._name = config[0]
self._child = config[1]
self._attr = config[2]
self._unit_of_measurement = config[3]
self._state = None
self.entity_id = ENTITY_ID_FORMAT.format(
"{}_{}".format(COOKER_DOMAIN, slugify(self._name))
)
示例5: __init__
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def __init__(self, hass, config, see, interval, home_place_name, api):
"""Initialize Life360Scanner."""
self._hass = hass
self._see = see
self._show_as_state = config[CONF_SHOW_AS_STATE]
self._home_place_name = home_place_name
self._max_gps_accuracy = config.get(CONF_MAX_GPS_ACCURACY)
self._max_update_wait = config.get(CONF_MAX_UPDATE_WAIT)
prefix = config.get(CONF_PREFIX)
self._prefix = '' if not prefix else prefix + '_'
self._members = config.get(CONF_MEMBERS)
self._driving_speed = config.get(CONF_DRIVING_SPEED)
self._time_as = config[CONF_TIME_AS]
self._api = api
self._errs = {}
self._error_threshold = config[CONF_ERROR_THRESHOLD]
self._warning_threshold = config.get(
CONF_WARNING_THRESHOLD, self._error_threshold)
self._max_errs = self._error_threshold + 2
self._dev_data = {}
if self._time_as in [TZ_DEVICE_UTC, TZ_DEVICE_LOCAL]:
from timezonefinderL import TimezoneFinder
self._tf = TimezoneFinder()
self._seen_members = set()
if self._members is not None:
_LOGGER.debug(
'Including: %s',
', '.join([
self._prefix
+ slugify(name.replace(',', '_').replace('-', '_'))
for name in self._members]))
self._started = dt_util.utcnow()
self._update_life360()
track_time_interval(self._hass, self._update_life360, interval)
示例6: __init__
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def __init__(self, hass: HomeAssistant, client, visonic_device):
"""Initialise a Visonic X10 Device."""
#_LOGGER.info("Creating X10 Switch {0}".format(visonic_device.name))
self.client = client
self.visonic_device = visonic_device
self.x10id = self.visonic_device.id
self._name = "Visonic " + self.visonic_device.name
# Append device id to prevent name clashes in HA.
self.visonic_id = slugify(self._name) # VISONIC_ID_FORMAT.format( slugify(self._name), visonic_device.getDeviceID())
self.entity_id = ENTITY_ID_FORMAT.format(self.visonic_id)
self.current_value = self.visonic_device.state
self.visonic_device.install_change_handler(self.onChange)
示例7: __init__
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def __init__(self, visonic_device):
"""Initialize the sensor."""
#_LOGGER.info("Creating binary sensor {0}".format(visonic_device.dname))
self.visonic_device = visonic_device
self._name = "visonic_" + self.visonic_device.dname.lower()
# Append device id to prevent name clashes in HA.
self.visonic_id = slugify(self._name) # VISONIC_ID_FORMAT.format( slugify(self._name), visonic_device.getDeviceID())
self.entity_id = ENTITY_ID_FORMAT.format(self.visonic_id)
self.current_value = self.visonic_device.triggered or self.visonic_device.status
self.visonic_device.install_change_handler(self.onChange)
示例8: __init__
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def __init__(self, see, vehicle):
"""Initialize the Tracker."""
self._see = see
self.vehicle = vehicle
self.dev_id = slugify(self.vehicle.name)
示例9: unique_id
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def unique_id(self) -> str:
"""Return a unique, Home Assistant friendly identifier for this entity."""
return slugify(
f"{self._entry.unique_id}_{self._entity_type}_controller_enabled"
)
示例10: unique_id
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def unique_id(self) -> str:
"""Return a unique, Home Assistant friendly identifier for this entity."""
return slugify(f"{self._entry.unique_id}_{self._entity_type}_{self._attr}")
示例11: async_step_user
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def async_step_user(self, user_input=None):
"""Handle the initial step."""
errors = {}
if user_input is not None:
try:
url = user_input[CONF_URL]
password = user_input[CONF_PASSWORD]
name = user_input.get(CONF_NAME, DEFAULT_NAME)
mac_address = user_input.get(CONF_MAC)
controller = OpenSprinkler(url, password)
await self.hass.async_add_executor_job(controller.refresh)
if controller.mac_address is None:
if not mac_address:
raise MacAddressRequiredError
await self.async_set_unique_id(slugify(mac_address))
else:
await self.async_set_unique_id(slugify(controller.mac_address))
return self.async_create_entry(
title=name,
data={CONF_URL: url, CONF_PASSWORD: password, CONF_NAME: name,},
)
except OpenSprinklerConnectionError:
errors["base"] = "cannot_connect"
except OpenSprinklerAuthError:
errors["base"] = "invalid_auth"
except MacAddressRequiredError:
errors[CONF_MAC] = "mac_address_required"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
return self.async_show_form(
step_id="user", data_schema=DEVICE_SCHEMA, errors=errors
)
示例12: unique_id
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def unique_id(self) -> str:
"""Return a unique, Home Assistant friendly identifier for this entity."""
return slugify(f"{self._entry.unique_id}_{self._entity_type}_water_level")
示例13: __init__
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def __init__(
self,
hass,
data,
internal_name,
sensor_name,
vin,
unit,
licenseplate,
feature_name,
object_name,
attrib_name,
extended_attributes,
**kwargs,
):
"""Initialize the MercedesMe entity."""
self._hass = hass
self._data = data
self._state = False
self._name = f"{licenseplate} {sensor_name}"
self._internal_name = internal_name
self._internal_unit = unit
self._unit = unit
self._vin = vin
self._feature_name = feature_name
self._object_name = object_name
self._attrib_name = attrib_name
self._licenseplate = licenseplate
self._extended_attributes = extended_attributes
self._kwargs = kwargs
self._unique_id = slugify(f"{self._vin}_{self._internal_name}")
self._car = next(car for car in self._data.cars
if car.finorvin == self._vin)
conf = hass.data[DOMAIN].config
if conf.get(CONF_CARS) is not None:
for car_conf in conf.get(CONF_CARS):
if car_conf.get(CONF_CARS_VIN) == vin:
custom_car_name = car_conf.get(CONF_NAME)
if custom_car_name != "_notset_":
self._name = f"{custom_car_name} {sensor_name}".strip()
示例14: __init__
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def __init__(self, dev, instance):
conf = instance.conf
id_prefix = conf.get(CONF_OBJECT_ID_PREFIX)
self._unique_id = id_prefix + "_" + dev.type + "_" + dev.id
self.entity_id = "." + slugify(self._unique_id)
entity_id = instance._get_specific_config(CONF_ENTITY_ID,
None, dev.id, dev.block.id)
if entity_id is not None:
self.entity_id = "." + slugify(id_prefix + "_" + entity_id)
self._unique_id += "_" + slugify(entity_id)
self._show_id_in_name = conf.get(CONF_SHOW_ID_IN_NAME)
self._name_ext = None
#self._name = dev.type_name()
#if conf.get(CONF_SHOW_ID_IN_NAME):
# self._name += " [" + dev.id + "]" # 'Test' #light.name
self._dev = dev
self.hass = instance.hass
self.instance = instance
self._dev.cb_updated.append(self._updated)
dev.shelly_device = self
self._name = instance._get_specific_config(CONF_NAME, None,
dev.id, dev.block.id)
self._sensor_conf = instance._get_sensor_config(dev.id, dev.block.id)
self._is_removed = False
self._master_unit = False
self._settings = instance.get_settings(dev.id, dev.block.id)
示例15: __init__
# 需要导入模块: from homeassistant import util [as 别名]
# 或者: from homeassistant.util import slugify [as 别名]
def __init__(self, instance, version, py_shelly_version, extra):
"""Initialize the Version sensor."""
conf = instance.conf
id_prefix = slugify(conf.get(CONF_OBJECT_ID_PREFIX))
self._version = version
self._py_shelly_version = py_shelly_version
self.entity_id = "sensor." + id_prefix + "_version"
self._name = "ShellyForHass"
self._extra = extra
#self.instance = instance