1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 19:32:19 +01:00

Add cover position/tilt support (#496)

* Add climate support

* Fixes

* Updates

* Updates

* Add ota

* Remove climate changes

* Lint
This commit is contained in:
Otto Winter
2019-04-08 18:08:58 +02:00
committed by GitHub
parent cb9f36a153
commit 7fd5634a51
21 changed files with 425 additions and 192 deletions

View File

@@ -1,14 +1,14 @@
from collections import OrderedDict
import math
from esphome.core import CORE, HexInt, Lambda, TimePeriod, TimePeriodMicroseconds, \
TimePeriodMilliseconds, TimePeriodSeconds, TimePeriodMinutes
from esphome.helpers import cpp_string_escape, indent_all_but_first_and_last
# pylint: disable=unused-import, wrong-import-order
from typing import Any, Generator, List, Optional, Tuple, Union # noqa
from esphome.core import ID # noqa
from esphome.py_compat import text_type, string_types, integer_types
from typing import Any, Generator, List, Optional, Tuple, Type, Union, Dict, Callable # noqa
from esphome.core import ( # noqa
CORE, HexInt, ID, Lambda, TimePeriod, TimePeriodMicroseconds,
TimePeriodMilliseconds, TimePeriodMinutes, TimePeriodSeconds)
from esphome.helpers import cpp_string_escape, indent_all_but_first_and_last
from esphome.py_compat import integer_types, string_types, text_type
class Expression(object):
@@ -30,7 +30,8 @@ class Expression(object):
return self.required
SafeExpType = Union[Expression, bool, str, text_type, int, float, TimePeriod]
SafeExpType = Union[Expression, bool, str, text_type, int, float, TimePeriod,
Type[bool], Type[int], Type[float]]
class RawExpression(Expression):
@@ -190,9 +191,9 @@ class LambdaExpression(Expression):
self.parameters = parameters
self.requires.append(self.parameters)
self.capture = capture
self.return_type = return_type
self.return_type = safe_exp(return_type) if return_type is not None else None
if return_type is not None:
self.requires.append(return_type)
self.requires.append(self.return_type)
for i in range(1, len(parts), 3):
self.requires.append(parts[i])
@@ -271,6 +272,8 @@ def safe_exp(
obj # type: Union[Expression, bool, str, unicode, int, long, float, TimePeriod, list]
):
# type: (...) -> Expression
from esphome.cpp_types import bool_, float_, int32
if isinstance(obj, Expression):
return obj
if isinstance(obj, bool):
@@ -293,6 +296,12 @@ def safe_exp(
return IntLiteral(int(obj.total_minutes))
if isinstance(obj, (tuple, list)):
return ArrayInitializer(*[safe_exp(o) for o in obj])
if obj is bool:
return bool_
if obj is int:
return int32
if obj is float:
return float_
raise ValueError(u"Object is not an expression", obj)
@@ -425,15 +434,21 @@ def process_lambda(value, # type: Lambda
def templatable(value, # type: Any
args, # type: List[Tuple[Expression, str]]
output_type # type: Optional[Expression]
args, # type: List[Tuple[SafeExpType, str]]
output_type, # type: Optional[SafeExpType],
to_exp=None # type: Optional[Any]
):
if isinstance(value, Lambda):
for lambda_ in process_lambda(value, args, return_type=output_type):
yield None
yield lambda_
else:
yield value
if to_exp is None:
yield value
elif isinstance(to_exp, dict):
yield to_exp[value]
else:
yield to_exp(value)
class MockObj(Expression):