Skip to content

Commit 39c374f

Browse files
committed
Use assert isinstance() instead of cast()
1 parent d24d6e5 commit 39c374f

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

plugwise/helper.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
version_to_model,
7979
)
8080

81-
# from typing import cast
82-
8381

8482
def check_model(name: str | None, vendor_name: str | None) -> str | None:
8583
"""Model checking before using version_to_model."""
@@ -863,13 +861,10 @@ def _appliance_measurements(
863861
data["select_dhw_mode"] = appl_p_loc.text
864862
case _ as meas_rn if meas_rn in BINARY_SENSORS:
865863
bs_key = cast(BinarySensorType, meas_rn)
866-
bs_value = cast(
867-
bool,
868-
format_measure(
869-
appl_p_loc.text,
870-
getattr(attrs, ATTR_UNIT_OF_MEASUREMENT),
871-
),
864+
bs_value = format_measure(
865+
appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)
872866
)
867+
assert isinstance(bs_value, bool)
873868
data["binary_sensors"][bs_key] = bs_value
874869
case _ as meas_rn if meas_rn in SENSORS:
875870
s_key = cast(SensorType, meas_rn)
@@ -893,22 +888,17 @@ def _appliance_measurements(
893888
]
894889
case _ as meas_rn if meas_rn in SWITCHES:
895890
sw_key = cast(SwitchType, meas_rn)
896-
sw_value = cast(
897-
bool,
898-
format_measure(
899-
appl_p_loc.text,
900-
getattr(attrs, ATTR_UNIT_OF_MEASUREMENT),
901-
),
891+
value = format_measure(
892+
appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)
902893
)
894+
sw_value = cast(bool, value)
903895
data["switches"][sw_key] = sw_value
904896
case "c_heating_state":
905-
data["c_heating_state"] = cast(
906-
bool,
907-
format_measure(
908-
appl_p_loc.text,
909-
getattr(attrs, ATTR_UNIT_OF_MEASUREMENT),
910-
),
897+
value = format_measure(
898+
appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)
911899
)
900+
assert isinstance(value, bool)
901+
data["c_heating_state"] = value
912902
case "elga_status_code":
913903
data["elga_status_code"] = int(appl_p_loc.text)
914904

0 commit comments

Comments
 (0)