def entity_id(value): """Validate Entity ID.""" if valid_entity_id(value): return value raise vol.Invalid( 'Entity ID {} does not match format <domain>.<object_id>'.format( value))
def service(value): """Validate service.""" # Services use same format as entities so we can use same helper. if valid_entity_id(value): return value raise vol.Invalid('Service {} does not match format <domain>.<name>' .format(value))
def service(value): """Validate service.""" # Services use same format as entities so we can use same helper. if valid_entity_id(value): return value raise vol.Invalid( 'Service {} does not match format <domain>.<name>'.format(value))
def entity_id(value): """Validate Entity ID.""" value = string(value).lower() if valid_entity_id(value): return value raise vol.Invalid('Entity ID {} does not match format <domain>.<object_id>' .format(value))
def _valid_customize(value): """Config validator for customize.""" if not isinstance(value, dict): raise vol.Invalid('Expected dictionary') for key, val in value.items(): if not valid_entity_id(key): raise vol.Invalid('Invalid entity ID: {}'.format(key)) if not isinstance(val, dict): raise vol.Invalid('Value of {} is not a dictionary'.format(key)) return value
def __init__(self, entity_id, state, attributes=None, last_changed=None, last_updated=None): """Initialize a new state.""" if not valid_entity_id(entity_id): raise InvalidEntityFormatError(( "Invalid entity id encountered: {}. " "Format should be <domain>.<object_id>").format(entity_id)) self.entity_id = entity_id.lower() self.state = str(state) self.attributes = MappingProxyType(attributes or {}) self.last_updated = last_updated or dt_util.utcnow() self.last_changed = last_changed or self.last_updated
def __init__(self, entity_id, state, attributes=None, last_changed=None, last_updated=None): """Initialize a new state.""" if not valid_entity_id(entity_id): raise InvalidEntityFormatError(( "Invalid entity id encountered: {}. " "Format should be <domain>.<object_id>").format(entity_id)) self.entity_id = entity_id.lower() self.state = str(state) self.attributes = MappingProxyType(attributes or {}) self.last_updated = dt_util.strip_microseconds( last_updated or dt_util.utcnow()) # Strip microsecond from last_changed else we cannot guarantee # state == State.from_dict(state.as_dict()) # This behavior occurs because to_dict uses datetime_to_str # which does not preserve microseconds self.last_changed = dt_util.strip_microseconds( last_changed or self.last_updated)
def __init__(self, entity_id, state, attributes=None, last_changed=None, last_updated=None): """Initialize a new state.""" if not valid_entity_id(entity_id): raise InvalidEntityFormatError(( "Invalid entity id encountered: {}. " "Format should be <domain>.<object_id>").format(entity_id)) self.entity_id = entity_id.lower() self.state = state self.attributes = attributes or {} self.last_updated = dt_util.strip_microseconds( last_updated or dt_util.utcnow()) # Strip microsecond from last_changed else we cannot guarantee # state == State.from_dict(state.as_dict()) # This behavior occurs because to_dict uses datetime_to_str # which does not preserve microseconds self.last_changed = dt_util.strip_microseconds( last_changed or self.last_updated)
def entity_id(value): """Validate Entity ID.""" value = string(value).lower() if valid_entity_id(value): return value raise vol.Invalid('Entity ID {} is an invalid entity id'.format(value))