Allow float for int argument type [pylint plugin] (#114105)
This commit is contained in:
parent
5c97049f2e
commit
3929273b41
|
@ -159,7 +159,7 @@ class XiaomiGenericHumidifier(XiaomiCoordinatedMiioEntity, HumidifierEntity):
|
|||
self._state = False
|
||||
self.async_write_ha_state()
|
||||
|
||||
def translate_humidity(self, humidity):
|
||||
def translate_humidity(self, humidity: float) -> float | None:
|
||||
"""Translate the target humidity to the first valid step."""
|
||||
return (
|
||||
math.ceil(percentage_to_ranged_value((1, self._humidity_steps), humidity))
|
||||
|
@ -240,7 +240,7 @@ class XiaomiAirHumidifier(XiaomiGenericHumidifier, HumidifierEntity):
|
|||
else None
|
||||
)
|
||||
|
||||
async def async_set_humidity(self, humidity: int) -> None:
|
||||
async def async_set_humidity(self, humidity: float) -> None:
|
||||
"""Set the target humidity of the humidifier and set the mode to auto."""
|
||||
target_humidity = self.translate_humidity(humidity)
|
||||
if not target_humidity:
|
||||
|
@ -318,7 +318,7 @@ class XiaomiAirHumidifierMiot(XiaomiAirHumidifier):
|
|||
)
|
||||
return None
|
||||
|
||||
async def async_set_humidity(self, humidity: int) -> None:
|
||||
async def async_set_humidity(self, humidity: float) -> None:
|
||||
"""Set the target humidity of the humidifier and set the mode to auto."""
|
||||
target_humidity = self.translate_humidity(humidity)
|
||||
if not target_humidity:
|
||||
|
@ -393,7 +393,7 @@ class XiaomiAirHumidifierMjjsq(XiaomiAirHumidifier):
|
|||
return self._target_humidity
|
||||
return None
|
||||
|
||||
async def async_set_humidity(self, humidity: int) -> None:
|
||||
async def async_set_humidity(self, humidity: float) -> None:
|
||||
"""Set the target humidity of the humidifier and set the mode to Humidity."""
|
||||
target_humidity = self.translate_humidity(humidity)
|
||||
if not target_humidity:
|
||||
|
|
|
@ -81,7 +81,7 @@ def ranged_value_to_percentage(
|
|||
|
||||
|
||||
def percentage_to_ranged_value(
|
||||
low_high_range: tuple[float, float], percentage: int
|
||||
low_high_range: tuple[float, float], percentage: float
|
||||
) -> float:
|
||||
"""Given a range of low and high values convert a percentage to a single value.
|
||||
|
||||
|
|
|
@ -2968,6 +2968,15 @@ def _is_valid_type(
|
|||
):
|
||||
return True
|
||||
|
||||
# Special case for int in argument type
|
||||
if (
|
||||
expected_type == "int"
|
||||
and not in_return
|
||||
and isinstance(node, nodes.Name)
|
||||
and node.name in ("float", "int")
|
||||
):
|
||||
return True
|
||||
|
||||
# Name occurs when a namespace is not used, eg. "HomeAssistant"
|
||||
if isinstance(node, nodes.Name) and node.name == expected_type:
|
||||
return True
|
||||
|
|
|
@ -989,6 +989,39 @@ def test_media_player_entity(
|
|||
type_hint_checker.visit_classdef(class_node)
|
||||
|
||||
|
||||
def test_humidifier_entity(
|
||||
linter: UnittestLinter, type_hint_checker: BaseChecker
|
||||
) -> None:
|
||||
"""Ensure valid hints are accepted for humidifier entity."""
|
||||
# Set bypass option
|
||||
type_hint_checker.linter.config.ignore_missing_annotations = False
|
||||
|
||||
# Ensure that `float` and `int` are valid for `int` argument type
|
||||
class_node = astroid.extract_node(
|
||||
"""
|
||||
class Entity():
|
||||
pass
|
||||
|
||||
class HumidifierEntity(Entity):
|
||||
pass
|
||||
|
||||
class MyHumidifier( #@
|
||||
HumidifierEntity
|
||||
):
|
||||
def set_humidity(self, humidity: int) -> None:
|
||||
pass
|
||||
|
||||
def async_set_humidity(self, humidity: float) -> None:
|
||||
pass
|
||||
""",
|
||||
"homeassistant.components.pylint_test.humidifier",
|
||||
)
|
||||
type_hint_checker.visit_module(class_node.parent)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
type_hint_checker.visit_classdef(class_node)
|
||||
|
||||
|
||||
def test_number_entity(linter: UnittestLinter, type_hint_checker: BaseChecker) -> None:
|
||||
"""Ensure valid hints are accepted for number entity."""
|
||||
# Set bypass option
|
||||
|
|
Loading…
Reference in New Issue