Skip to content

Commit

Permalink
Refactor RWSensor class: Update min and max attributes to use Sensor[…
Browse files Browse the repository at this point in the history
…Any] for improved type handling and cast dependencies in the dependencies method to ensure correct type resolution.
  • Loading branch information
maslyankov committed Jan 3, 2025
1 parent 346b59a commit 1e56fa3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/sunsynk/rwsensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
import re
from typing import Callable, Generator
from typing import Any, Callable, Generator, cast

import attrs
from mqtt_entity.utils import BOOL_OFF, BOOL_ON
Expand All @@ -20,8 +20,8 @@
class RWSensor(Sensor[SensorType]):
"""Read & write sensor."""

min: SensorType | NumType = 0
max: SensorType | NumType = 0xFFFF
min: Sensor[Any] | NumType = 0
max: Sensor[Any] | NumType = 0xFFFF

def reg(self, *regs: int, msg: str = "") -> RegType:
"""Check the registers are within the bitmask."""
Expand Down Expand Up @@ -57,9 +57,9 @@ def dependencies(self) -> list[SensorType]:
"""Dependencies."""
deps: list[SensorType] = []
if isinstance(self.min, Sensor):
deps.append(self.min)
deps.append(cast(SensorType, self.min))
if isinstance(self.max, Sensor):
deps.append(self.max)
deps.append(cast(SensorType, self.max))
return deps


Expand Down

0 comments on commit 1e56fa3

Please sign in to comment.