Skip to content

Commit

Permalink
Not all SmartTasks are for dimmers
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Jan 16, 2023
1 parent 344ede5 commit 773aca7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pytradfri/smart_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class StartActionResponse(BaseResponse):
"""Represent a start action response."""

transition_time: Optional[int] = Field(alias=ATTR_TRANSITION_TIME)
dimmer: int = Field(alias=ATTR_LIGHT_DIMMER)
dimmer: Optional[int] = Field(alias=ATTR_LIGHT_DIMMER)


class TimeIntervalResponse(BaseModel):
Expand Down Expand Up @@ -309,7 +309,8 @@ def devices_list(self) -> list[dict[str, int]]:
if idx != self.index:
list_record: dict[str, int] = {}
list_record[ATTR_ID] = record.id
list_record[ATTR_LIGHT_DIMMER] = record.dimmer
if record.dimmer is not None:
list_record[ATTR_LIGHT_DIMMER] = record.dimmer

if record.transition_time is not None:
list_record[ATTR_TRANSITION_TIME] = record.transition_time
Expand Down Expand Up @@ -342,7 +343,7 @@ def transition_time(self) -> int | None:
return None

@property
def dimmer(self) -> int:
def dimmer(self) -> int | None:
"""Return dimmer level."""
return self.raw.dimmer

Expand Down Expand Up @@ -404,10 +405,13 @@ def set_transition_time(self, transition_time: int) -> Command[None]:
root_start_action_list: list[dict[str, int]] = [
{
ATTR_ID: self.raw.id,
ATTR_LIGHT_DIMMER: self.raw.dimmer,
ATTR_TRANSITION_TIME: transition_time * 10 * 60,
}
]

if self.raw.dimmer is not None:
root_start_action_list[0][ATTR_LIGHT_DIMMER] = self.raw.dimmer

root_start_action_list.extend(self.devices_list)

command: dict[str, dict[str, Any]] = {
Expand Down

0 comments on commit 773aca7

Please sign in to comment.