mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Improve time config validation
This commit is contained in:
		| @@ -246,13 +246,6 @@ time_period_dict = vol.All( | |||||||
|                          'seconds', 'milliseconds', 'microseconds'), |                          'seconds', 'milliseconds', 'microseconds'), | ||||||
|     lambda value: TimePeriod(**value)) |     lambda value: TimePeriod(**value)) | ||||||
|  |  | ||||||
| TIME_PERIOD_EXPLICIT_MESSAGE = ("The old way of being able to write time values without a " |  | ||||||
|                                 "time unit (like \"1000\" for 1000 milliseconds) has been " |  | ||||||
|                                 "removed in 1.5.0 as it was ambiguous in some places. Please " |  | ||||||
|                                 "now explicitly specify the time unit (like \"1000ms\"). See " |  | ||||||
|                                 "https://esphomelib.com/esphomeyaml/configuration-types.html#time " |  | ||||||
|                                 "for more information.") |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def time_period_str_colon(value): | def time_period_str_colon(value): | ||||||
|     """Validate and transform time offset with format HH:MM[:SS].""" |     """Validate and transform time offset with format HH:MM[:SS].""" | ||||||
| @@ -284,13 +277,6 @@ def time_period_str_unit(value): | |||||||
|     elif not isinstance(value, (str, unicode)): |     elif not isinstance(value, (str, unicode)): | ||||||
|         raise vol.Invalid("Expected string for time period with unit.") |         raise vol.Invalid("Expected string for time period with unit.") | ||||||
|  |  | ||||||
|     try: |  | ||||||
|         float(value) |  | ||||||
|     except ValueError: |  | ||||||
|         pass |  | ||||||
|     else: |  | ||||||
|         raise vol.Invalid(TIME_PERIOD_EXPLICIT_MESSAGE) |  | ||||||
|  |  | ||||||
|     unit_to_kwarg = { |     unit_to_kwarg = { | ||||||
|         'us': 'microseconds', |         'us': 'microseconds', | ||||||
|         'microseconds': 'microseconds', |         'microseconds': 'microseconds', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user