mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Fix: Pin flags code generation returning FLAG_NONE (#2377)
Co-authored-by: Otto winter <otto@otto-winter.com>
This commit is contained in:
		| @@ -310,6 +310,19 @@ class FloatLiteral(Literal): | |||||||
|         return f"{self.f}f" |         return f"{self.f}f" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class BinOpExpression(Expression): | ||||||
|  |     __slots__ = ("op", "lhs", "rhs") | ||||||
|  |  | ||||||
|  |     def __init__(self, op: str, lhs: SafeExpType, rhs: SafeExpType): | ||||||
|  |         # Remove every None on end | ||||||
|  |         self.op = op | ||||||
|  |         self.lhs = safe_exp(lhs) | ||||||
|  |         self.rhs = safe_exp(rhs) | ||||||
|  |  | ||||||
|  |     def __str__(self): | ||||||
|  |         return f"{self.lhs} {self.op} {self.rhs}" | ||||||
|  |  | ||||||
|  |  | ||||||
| def safe_exp(obj: SafeExpType) -> Expression: | def safe_exp(obj: SafeExpType) -> Expression: | ||||||
|     """Try to convert obj to an expression by automatically converting native python types to |     """Try to convert obj to an expression by automatically converting native python types to | ||||||
|     expressions/literals. |     expressions/literals. | ||||||
| @@ -756,6 +769,10 @@ class MockObj(Expression): | |||||||
|             next_op = "->" |             next_op = "->" | ||||||
|         return MockObj(f"{self.base}[{item}]", next_op) |         return MockObj(f"{self.base}[{item}]", next_op) | ||||||
|  |  | ||||||
|  |     def __or__(self, other: SafeExpType) -> "MockObj": | ||||||
|  |         op = BinOpExpression("|", self, other) | ||||||
|  |         return MockObj(op) | ||||||
|  |  | ||||||
|  |  | ||||||
| class MockObjEnum(MockObj): | class MockObjEnum(MockObj): | ||||||
|     def __init__(self, *args, **kwargs): |     def __init__(self, *args, **kwargs): | ||||||
|   | |||||||
| @@ -90,7 +90,7 @@ def gpio_flags_expr(mode): | |||||||
|         CONF_PULLDOWN: cg.gpio_Flags.FLAG_PULLDOWN, |         CONF_PULLDOWN: cg.gpio_Flags.FLAG_PULLDOWN, | ||||||
|     } |     } | ||||||
|     active_flags = [v for k, v in FLAGS_MAPPING.items() if mode.get(k)] |     active_flags = [v for k, v in FLAGS_MAPPING.items() if mode.get(k)] | ||||||
|     if active_flags: |     if not active_flags: | ||||||
|         return cg.gpio_Flags.FLAG_NONE |         return cg.gpio_Flags.FLAG_NONE | ||||||
|  |  | ||||||
|     return reduce(operator.or_, active_flags) |     return reduce(operator.or_, active_flags) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user