コード例 #1
0
ファイル: __init__.py プロジェクト: tal2420/Home-Assistant
 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)
コード例 #2
0
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))
コード例 #4
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(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))
コード例 #7
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))
コード例 #8
0
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})")
コード例 #9
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))
コード例 #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
ファイル: octoprint.py プロジェクト: Martwall/home-assistant
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
ファイル: __init__.py プロジェクト: codacy-badger/core-1
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)