Python homeassistant.util.slugify() Examples
The following are 23
code examples of homeassistant.util.slugify().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
homeassistant.util
, or try the search function
.
Example #1
Source File: device_tracker.py From home-assistant-custom-components with MIT License | 6 votes |
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
Example #2
Source File: device_tracker.py From homeassistant-volkswagencarnet with Apache License 2.0 | 6 votes |
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
Example #3
Source File: __init__.py From hass-opensprinkler with MIT License | 6 votes |
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, }
Example #4
Source File: switch.py From hass-opensprinkler with MIT License | 5 votes |
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}_station_enabled_{self._station.index}" )
Example #5
Source File: sensor.py From ShellyForHASS with MIT License | 5 votes |
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
Example #6
Source File: device.py From ShellyForHASS with MIT License | 5 votes |
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)
Example #7
Source File: __init__.py From mbapipy with MIT License | 5 votes |
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()
Example #8
Source File: sensor.py From hass-opensprinkler with MIT License | 5 votes |
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}_station_status_{self._station.index}" )
Example #9
Source File: sensor.py From hass-opensprinkler with MIT License | 5 votes |
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}_last_run")
Example #10
Source File: sensor.py From hass-opensprinkler with MIT License | 5 votes |
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}_flow_rate")
Example #11
Source File: sensor.py From hass-opensprinkler with MIT License | 5 votes |
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")
Example #12
Source File: config_flow.py From hass-opensprinkler with MIT License | 5 votes |
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 )
Example #13
Source File: binary_sensor.py From hass-opensprinkler with MIT License | 5 votes |
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}_program_running_{self._program.index}" )
Example #14
Source File: binary_sensor.py From hass-opensprinkler with MIT License | 5 votes |
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}")
Example #15
Source File: sensor.py From xiaomi_cooker with Apache License 2.0 | 5 votes |
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)) )
Example #16
Source File: switch.py From hass-opensprinkler with MIT License | 5 votes |
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}_program_enabled_{self._program.index}" )
Example #17
Source File: switch.py From hass-opensprinkler with MIT License | 5 votes |
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" )
Example #18
Source File: device_tracker.py From home-assistant-archive with MIT License | 5 votes |
def __init__(self, see, vehicle): """Initialize the Tracker.""" self._see = see self.vehicle = vehicle self.dev_id = slugify(self.vehicle.name)
Example #19
Source File: binary_sensor.py From visonic with Apache License 2.0 | 5 votes |
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)
Example #20
Source File: switch.py From visonic with Apache License 2.0 | 5 votes |
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)
Example #21
Source File: device_tracker.py From homeassistant-config with The Unlicense | 5 votes |
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)
Example #22
Source File: switch.py From hass-circadian_lighting with Apache License 2.0 | 4 votes |
def __init__(self, hass, cl, name, lights_ct, lights_rgb, lights_xy, lights_brightness, disable_brightness_adjust, min_brightness, max_brightness, sleep_entity, sleep_state, sleep_colortemp, sleep_brightness, disable_entity, disable_state, initial_transition): """Initialize the Circadian Lighting switch.""" self.hass = hass self._cl = cl self._name = name self._entity_id = "switch." + slugify("{} {}".format('circadian_lighting', name)) self._state = None self._icon = ICON self._hs_color = None self._lights_ct = lights_ct self._lights_rgb = lights_rgb self._lights_xy = lights_xy self._lights_brightness = lights_brightness self._disable_brightness_adjust = disable_brightness_adjust self._min_brightness = min_brightness self._max_brightness = max_brightness self._sleep_entity = sleep_entity self._sleep_state = sleep_state self._sleep_colortemp = sleep_colortemp self._sleep_brightness = sleep_brightness self._disable_entity = disable_entity self._disable_state = disable_state self._initial_transition = initial_transition self._attributes = {} self._attributes['hs_color'] = self._hs_color self._attributes['brightness'] = None self._lights = [] if lights_ct != None: self._lights += lights_ct if lights_rgb != None: self._lights += lights_rgb if lights_xy != None: self._lights += lights_xy if lights_brightness != None: self._lights += lights_brightness """Register callbacks.""" dispatcher_connect(hass, CIRCADIAN_LIGHTING_UPDATE_TOPIC, self.update_switch) track_state_change(hass, self._lights, self.light_state_changed) if self._sleep_entity is not None: track_state_change(hass, self._sleep_entity, self.sleep_state_changed) if self._disable_entity is not None: track_state_change(hass, self._disable_entity, self.disable_state_changed)
Example #23
Source File: device_tracker.py From homeassistant-config with The Unlicense | 4 votes |
def _update_life360(self, now=None): checked_ids = [] err_key = 'get_circles' try: circles = self._api.get_circles() except _API_EXCS as exc: self._exc(err_key, exc) return self._ok(err_key) for circle in circles: err_key = 'get_circle "{}"'.format( circle.get('name') or circle.get('id')) try: members = self._api.get_circle_members(circle['id']) except _API_EXCS as exc: self._exc(err_key, exc) continue except KeyError: self._err(err_key, circle) continue self._ok(err_key) for member in members: err_key = 'Member data' try: m_id = member['id'] first = member.get('firstName') last = member.get('lastName') if first and last: full_name = ' '.join([first, last]) else: full_name = first or last name = _m_name(first, last) include_member = not self._members or name in self._members dev_id = ( self._prefix + slugify(name.replace(',', '_').replace('-', '_'))) if full_name not in self._seen_members: self._seen_members.add(full_name) _LOGGER.debug( '%s -> %s: will%s be tracked', full_name, dev_id, '' if include_member else ' NOT') sharing = bool(int(member['features']['shareLocation'])) except (KeyError, TypeError, ValueError): self._err(err_key, member) continue self._ok(err_key) if m_id not in checked_ids and include_member and sharing: checked_ids.append(m_id) self._update_member(member, dev_id)