| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,6 @@ | |||
| 10 | 10 | if TYPE_CHECKING: | |
| 11 | 11 | from .device import Device | |
| 12 | 12 | ||
| 13 | - | ||
| 14 | 13 | _LOGGER = logging.getLogger(__name__) | |
| 15 | 14 | ||
| 16 | 15 | ||
@@ -140,22 +139,24 @@ def value(self): | |||
| 140 | 139 | raise ValueError("Not an action and no attribute_getter set") | |
| 141 | 140 | ||
| 142 | 141 | container = self.container if self.container is not None else self.device | |
| 143 | - if isinstance(self.attribute_getter, Callable): | ||
| 142 | + if callable(self.attribute_getter): | ||
| 144 | 143 | return self.attribute_getter(container) | |
| 145 | 144 | return getattr(container, self.attribute_getter) | |
| 146 | 145 | ||
| 147 | - async def set_value(self, value): | ||
| 146 | + async def set_value(self, value: int | float | bool | str | Enum | None) -> Any: | ||
| 148 | 147 | """Set the value.""" | |
| 149 | 148 | if self.attribute_setter is None: | |
| 150 | 149 | raise ValueError("Tried to set read-only feature.") | |
| 151 | 150 | if self.type == Feature.Type.Number: # noqa: SIM102 | |
| 151 | + if not isinstance(value, (int, float)): | ||
| 152 | + raise ValueError("value must be a number") | ||
| 152 | 153 | if value < self.minimum_value or value > self.maximum_value: | |
| 153 | 154 | raise ValueError( | |
| 154 | 155 | f"Value {value} out of range " | |
| 155 | 156 | f"[{self.minimum_value}, {self.maximum_value}]" | |
| 156 | 157 | ) | |
| 157 | 158 | elif self.type == Feature.Type.Choice: # noqa: SIM102 | |
| 158 | - if value not in self.choices: | ||
| 159 | + if not self.choices or value not in self.choices: | ||
| 159 | 160 | raise ValueError( | |
| 160 | 161 | f"Unexpected value for {self.name}: {value}" | |
| 161 | 162 | f" - allowed: {self.choices}" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments