예제 #1
0
 def event_listener(message):
     event = util_slugify("{} {}".format(config[DOMAIN][CONF_NAME],
                                         EVENT_CONTAINER))
     _LOGGER.debug(
         "Sending event {} notification with message {}".format(
             event, message))
     hass.bus.fire(event, message)
def slugify(value):
    """Coerce a value to a slug."""
    if value is None:
        raise vol.Invalid("Slug should not be None")
    slg = util_slugify(str(value))
    if len(slg) > 0:
        return slg
    raise vol.Invalid("Unable to slugify {}".format(value))
예제 #3
0
def slugify(value: Any) -> str:
    """Coerce a value to a slug."""
    if value is None:
        raise vol.Invalid('Slug should not be None')
    slg = util_slugify(str(value))
    if slg:
        return slg
    raise vol.Invalid('Unable to slugify {}'.format(value))
def slugify(value: Any) -> str:
    """Coerce a value to a slug."""
    if value is None:
        raise vol.Invalid("Slug should not be None")
    slg = util_slugify(str(value))
    if slg:
        return slg
    raise vol.Invalid(f"Unable to slugify {value}")
예제 #5
0
def slugify(value: Any) -> str:
    """Coerce a value to a slug."""
    if value is None:
        raise vol.Invalid('Slug should not be None')
    slg = util_slugify(str(value))
    if slg:
        return slg
    raise vol.Invalid('Unable to slugify {}'.format(value))
예제 #6
0
def slug(value):
    """Validate value is a valid slug."""
    if value is None:
        raise vol.Invalid('Slug should not be None')
    value = str(value)
    slg = util_slugify(value)
    if value == slg:
        return value
    raise vol.Invalid('invalid slug {} (try {})'.format(value, slg))
def slug(value):
    """Validate value is a valid slug."""
    if value is None:
        raise vol.Invalid("Slug should not be None")
    value = str(value)
    slg = util_slugify(value)
    if value == slg:
        return value
    raise vol.Invalid("invalid slug {} (try {})".format(value, slg))
def slug(value: Any) -> str:
    """Validate value is a valid slug."""
    if value is None:
        raise vol.Invalid("Slug should not be None")
    str_value = str(value)
    slg = util_slugify(str_value)
    if str_value == slg:
        return str_value
    raise vol.Invalid(f"invalid slug {value} (try {slg})")
def slug(value: Any) -> str:
    """Validate value is a valid slug."""
    if value is None:
        raise vol.Invalid("Slug should not be None")
    value = str(value)
    slg = util_slugify(value)
    if value == slg:
        return value
    raise vol.Invalid("invalid slug {} (try {})".format(value, slg))
예제 #10
0
def slug(value: Any) -> str:
    """Validate value is a valid slug."""
    if value is None:
        raise vol.Invalid('Slug should not be None')
    value = str(value)
    slg = util_slugify(value)
    if value == slg:
        return value
    raise vol.Invalid('invalid slug {} (try {})'.format(value, slg))
예제 #11
0
    def __init__(self, hass, device, client, config):
        """Set up instance."""
        self._hass = hass
        self._client = client
        self._device = device
        self.config = config

        sensor_info = []
        info = {}
        info["name"] = util_slugify(f"{DEFAULT_NAME}_{self._client.name}")
        info["friendly"] = self._client.name
        info["id"] = self._device
        sensor_info.append(info)

        load_platform(self._hass, "sensor", DOMAIN, sensor_info, self.config)
예제 #12
0
def entity_id(value: Any) -> str:
    """Validate Entity ID."""
    value = string(value).lower()
    if valid_entity_id(value):
        return value
    if re.match(OLD_ENTITY_ID_VALIDATION, value):
        # To ease the breaking change, we allow old slugs for now
        # Remove after 0.94 or 1.0
        fixed = '.'.join(util_slugify(part) for part in value.split('.', 1))
        INVALID_ENTITY_IDS_FOUND[value] = fixed
        logging.getLogger(__name__).warning(
            "Found invalid entity_id %s, please update with %s. This "
            "will become a breaking change.", value, fixed)
        return value

    raise vol.Invalid('Entity ID {} is an invalid entity id'.format(value))
예제 #13
0
def entity_id(value: Any) -> str:
    """Validate Entity ID."""
    value = string(value).lower()
    if valid_entity_id(value):
        return value
    if re.match(OLD_ENTITY_ID_VALIDATION, value):
        # To ease the breaking change, we allow old slugs for now
        # Remove after 0.94 or 1.0
        fixed = '.'.join(util_slugify(part) for part in value.split('.', 1))
        INVALID_ENTITY_IDS_FOUND[value] = fixed
        logging.getLogger(__name__).warning(
            "Found invalid entity_id %s, please update with %s. This "
            "will become a breaking change.",
            value, fixed
        )
        return value

    raise vol.Invalid('Entity ID {} is an invalid entity id'.format(value))
예제 #14
0
    def verify(value: Dict) -> Dict:
        """Validate all keys are slugs and then the value_schema."""
        if not isinstance(value, dict):
            raise vol.Invalid('expected dictionary')

        for key in value.keys():
            try:
                slug(key)
            except vol.Invalid:
                # To ease the breaking change, we allow old slugs for now
                # Remove after 0.94 or 1.0
                if re.match(OLD_SLUG_VALIDATION, key):
                    fixed = util_slugify(key)
                    INVALID_SLUGS_FOUND[key] = fixed
                    logging.getLogger(__name__).warning(
                        "Found invalid slug %s, please update with %s. This "
                        "will be come a breaking change.", key, fixed)
                else:
                    raise

        return schema(value)
예제 #15
0
    def verify(value: Dict) -> Dict:
        """Validate all keys are slugs and then the value_schema."""
        if not isinstance(value, dict):
            raise vol.Invalid('expected dictionary')

        for key in value.keys():
            try:
                slug(key)
            except vol.Invalid:
                # To ease the breaking change, we allow old slugs for now
                # Remove after 0.94 or 1.0
                if re.match(OLD_SLUG_VALIDATION, key):
                    fixed = util_slugify(key)
                    INVALID_SLUGS_FOUND[key] = fixed
                    logging.getLogger(__name__).warning(
                        "Found invalid slug %s, please update with %s. This "
                        "will be come a breaking change.",
                        key, fixed
                    )
                else:
                    raise

        return schema(value)
예제 #16
0
def has_all_unique_names(value):
    """Validate that printers have an unique name."""
    names = [util_slugify(printer['name']) for printer in value]
    vol.Schema(vol.Unique())(names)
    return value
예제 #17
0
def has_all_unique_names(value):
    """Validate that printers have an unique name."""
    names = [util_slugify(printer["name"]) for printer in value]
    vol.Schema(vol.Unique())(names)
    return value
예제 #18
0
 def event_listener(message):
     event = util_slugify("{} {}".format(name, EVENT_CONTAINER))
     hass.bus.fire(event, message)