Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: David Simon <[email protected]>
  • Loading branch information
DavidMikeSimon committed Sep 17, 2023
1 parent 58cdb51 commit c1f01c9
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions ha_mqtt_discoverable/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class BinarySensorInfo(EntityInfo):

component: str = "binary_sensor"
off_delay: Optional[int] = None
"""For sensors that only send on state updates (like PIRs),
this variable sets a delay in seconds after which the sensor’s state will be updated back to off."""
"""For sensors that only send on state updates (like PIRs), this variable
sets a delay in seconds after which the sensor's state will be updated back
to off."""
payload_off: str = "off"
"""Payload to send for the ON state"""
payload_on: str = "on"
Expand All @@ -57,13 +58,13 @@ class SwitchInfo(EntityInfo):
"""Flag that defines if switch works in optimistic mode.
Default: true if no state_topic defined, else false."""
payload_off: str = "OFF"
"""The payload that represents off state. If specified, will be used for both comparing
to the value in the state_topic (see value_template and state_off for details)
and sending as off command to the command_topic"""
"""The payload that represents off state. If specified, will be used for
both comparing to the value in the state_topic (see value_template and
state_off for details) and sending as off command to the command_topic"""
payload_on: str = "ON"
"""The payload that represents on state. If specified, will be used for both comparing
to the value in the state_topic (see value_template and state_on for details)
and sending as on command to the command_topic."""
"""The payload that represents on state. If specified, will be used for both
comparing to the value in the state_topic (see value_template and state_on
for details) and sending as on command to the command_topic."""
retain: Optional[bool] = None
"""If the published message should have the retain flag on or not"""
state_topic: Optional[str] = None
Expand Down Expand Up @@ -115,7 +116,8 @@ class NumberInfo(EntityInfo):
"""Flag that defines if switch works in optimistic mode.
Default: true if no state_topic defined, else false."""
payload_reset: Optional[str] = None
"""A special payload that resets the state to None when received on the state_topic."""
"""A special payload that resets the state to None when received on the
state_topic."""
retain: Optional[bool] = None
"""If the published message should have the retain flag on or not"""
state_topic: Optional[str] = None
Expand Down Expand Up @@ -186,7 +188,8 @@ def set_state(self, state: str | int | float) -> None:
self._state_helper(str(state))


# Inherit the on and off methods from the BinarySensor class, changing only the documentation string
# Inherit the on and off methods from the BinarySensor class, changing only the
# documentation string
class Switch(Subscriber[SwitchInfo], BinarySensor):
"""Implements an MQTT switch:
https://www.home-assistant.io/integrations/switch.mqtt
Expand Down Expand Up @@ -217,8 +220,8 @@ class DeviceTrigger(Discoverable[DeviceTriggerInfo]):
"""

def generate_config(self) -> dict[str, Any]:
"""Publish a custom configuration:
since this entity does not provide a `state_topic`, HA expects a `topic` key in the config
"""Publish a custom configuration: since this entity does not provide a
`state_topic`, HA expects a `topic` key in the config
"""
config = super().generate_config()
# Publish our `state_topic` as `topic`
Expand Down Expand Up @@ -251,8 +254,9 @@ def set_text(self, text: str) -> None:
text(str): Value of the text configured for this entity
"""
if not self._entity.min <= len(text) <= self._entity.max:
bound = f"[{self._entity.min}, {self._entity.max}]"
raise RuntimeError(
f"Text is not within configured length boundaries [{self._entity.min}, {self._entity.max}]"
f"Text is not within configured length boundaries {bound}"
)

logger.info(f"Setting {self._entity.name} to {text} using {self.state_topic}")
Expand All @@ -266,14 +270,15 @@ class Number(Subscriber[NumberInfo]):

def set_value(self, value: float) -> None:
"""
Update the numeric value. Raises an error if it is not within the acceptable range.
Update the numeric value. Raises an error if not within the acceptable range.
Args:
text(str): Value of the text configured for this entity
"""
if not self._entity.min <= value <= self._entity.max:
bound = f"[{self._entity.min}, {self._entity.max}]"
raise RuntimeError(
f"Value is not within configured boundaries [{self._entity.min}, {self._entity.max}]"
f"Value is not within configured boundaries {bound}"
)

logger.info(f"Setting {self._entity.name} to {value} using {self.state_topic}")
Expand Down

0 comments on commit c1f01c9

Please sign in to comment.