Skip to content

Commit

Permalink
Improve docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Sep 28, 2023
1 parent 1b51d8e commit 6e8226d
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 76 deletions.
12 changes: 6 additions & 6 deletions custom_components/yandex_smart_home/capability.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Implement the Yandex Smart Home base capability."""
"""Implement the Yandex Smart Home base device capability."""
from abc import abstractmethod
from functools import cached_property
from typing import Any, Protocol
Expand Down Expand Up @@ -32,7 +32,7 @@ class Capability(Protocol[CapabilityInstanceActionState]):
@property
@abstractmethod
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
...

@property
Expand Down Expand Up @@ -63,7 +63,7 @@ def get_value(self) -> Any:
...

def get_instance_state(self) -> CapabilityInstanceState | None:
"""Return a state for a device query request."""
"""Return a state for a state query request."""
if (value := self.get_value()) is not None:
return CapabilityInstanceState(
type=self.type, state=CapabilityInstanceStateValue(instance=self.instance, value=value)
Expand Down Expand Up @@ -104,12 +104,12 @@ def get_value(self) -> None:


class StateCapability(Capability[CapabilityInstanceActionState], Protocol):
"""Base class for a device property based on the state."""
"""Base class for a device capability based on the state."""

state: State

def __init__(self, hass: HomeAssistant, config: Config, state: State):
"""Initialize a capability for a state."""
"""Initialize a capability for the state."""
self._hass = hass
self._config = config

Expand All @@ -118,7 +118,7 @@ def __init__(self, hass: HomeAssistant, config: Config, state: State):

@property
def _state_features(self) -> int:
"""Return features attribute for the state."""
"""Return supported features for the state."""
return int(self.state.attributes.get(ATTR_SUPPORTED_FEATURES, 0))

@property
Expand Down
6 changes: 3 additions & 3 deletions custom_components/yandex_smart_home/capability_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ColorSettingCapability(StateCapability[ColorSettingCapabilityInstanceActio
instance = ColorSettingCapabilityInstance.BASE

def __init__(self, hass: HomeAssistant, config: Config, state: State):
"""Initialize a capability for a state."""
"""Initialize a capability for the state."""
super().__init__(hass, config, state)

self._color = RGBColorCapability(hass, config, state)
Expand All @@ -47,7 +47,7 @@ def __init__(self, hass: HomeAssistant, config: Config, state: State):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
for capability in self._capabilities:
if capability.supported:
return True
Expand Down Expand Up @@ -333,7 +333,7 @@ class ColorSceneCapability(StateCapability[SceneInstanceActionState]):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == light.DOMAIN and self._state_features & light.LightEntityFeature.EFFECT:
return bool(self.supported_scenes)

Expand Down
4 changes: 2 additions & 2 deletions custom_components/yandex_smart_home/capability_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class CustomToggleCapability(CustomCapability, ToggleCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return True

def get_value(self) -> bool | None:
Expand Down Expand Up @@ -182,7 +182,7 @@ class CustomRangeCapability(CustomCapability, RangeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return True

@property
Expand Down
20 changes: 10 additions & 10 deletions custom_components/yandex_smart_home/capability_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ModeCapability(Capability[ModeCapabilityInstanceActionState], Protocol):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return bool(self.supported_yandex_modes)

@property
Expand Down Expand Up @@ -171,7 +171,7 @@ class ThermostatCapability(StateModeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == climate.DOMAIN:
return super().supported

Expand Down Expand Up @@ -211,7 +211,7 @@ class SwingCapability(StateModeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == climate.DOMAIN and self._state_features & climate.ClimateEntityFeature.SWING_MODE:
return super().supported

Expand Down Expand Up @@ -308,7 +308,7 @@ class ProgramCapabilityHumidifier(ProgramCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == humidifier.DOMAIN and self._state_features & humidifier.HumidifierEntityFeature.MODES:
return super().supported

Expand Down Expand Up @@ -377,7 +377,7 @@ class ProgramCapabilityFan(ProgramCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == fan.DOMAIN:
if self._state_features & fan.FanEntityFeature.PRESET_MODE:
if (
Expand Down Expand Up @@ -433,7 +433,7 @@ class InputSourceCapability(StateModeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == media_player.DOMAIN:
if const.MEDIA_PLAYER_FEATURE_SELECT_SOURCE in self._entity_config.get(const.CONF_FEATURES, []):
return True
Expand Down Expand Up @@ -530,7 +530,7 @@ class FanSpeedCapabilityClimate(FanSpeedCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == climate.DOMAIN and self._state_features & climate.ClimateEntityFeature.FAN_MODE:
return super().supported

Expand Down Expand Up @@ -609,7 +609,7 @@ class FanSpeedCapabilityFanViaPreset(FanSpeedCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == fan.DOMAIN:
if self._state_features & fan.FanEntityFeature.PRESET_MODE:
if (
Expand Down Expand Up @@ -652,7 +652,7 @@ class FanSpeedCapabilityFanViaPercentage(FanSpeedCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == fan.DOMAIN:
if (
self._state_features & fan.FanEntityFeature.SET_SPEED
Expand Down Expand Up @@ -769,7 +769,7 @@ class CleanupModeCapability(StateModeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == vacuum.DOMAIN and self._state_features & vacuum.VacuumEntityFeature.FAN_SPEED:
return super().supported

Expand Down
24 changes: 12 additions & 12 deletions custom_components/yandex_smart_home/capability_onoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class OnOffCapabilityBasic(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain in (light.DOMAIN, fan.DOMAIN, switch.DOMAIN, humidifier.DOMAIN, input_boolean.DOMAIN)

async def _set_instance_state(self, context: Context, state: OnOffCapabilityInstanceActionState) -> None:
Expand All @@ -141,7 +141,7 @@ class OnOffCapabilityAutomation(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return bool(self.state.domain == automation.DOMAIN)

def get_value(self) -> bool | None:
Expand All @@ -165,7 +165,7 @@ class OnOffCapabilityGroup(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain in group.DOMAIN

async def _set_instance_state(self, context: Context, state: OnOffCapabilityInstanceActionState) -> None:
Expand All @@ -185,7 +185,7 @@ class OnOffCapabilityScript(OnlyOnCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain in (scene.DOMAIN, script.DOMAIN)

async def _set_instance_state(self, context: Context, state: OnOffCapabilityInstanceActionState) -> None:
Expand All @@ -205,7 +205,7 @@ class OnOffCapabilityButton(OnlyOnCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == button.DOMAIN

async def _set_instance_state(self, context: Context, state: OnOffCapabilityInstanceActionState) -> None:
Expand All @@ -225,7 +225,7 @@ class OnOffCapabilityInputButton(OnlyOnCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == input_button.DOMAIN

async def _set_instance_state(self, context: Context, state: OnOffCapabilityInstanceActionState) -> None:
Expand All @@ -245,7 +245,7 @@ class OnOffCapabilityLock(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == lock.DOMAIN

def get_value(self) -> bool | None:
Expand All @@ -270,7 +270,7 @@ class OnOffCapabilityCover(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == cover.DOMAIN

def get_value(self) -> bool | None:
Expand All @@ -295,7 +295,7 @@ class OnOffCapabilityMediaPlayer(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == media_player.DOMAIN:
if CONF_TURN_ON in self._entity_config or CONF_TURN_OFF in self._entity_config:
return True
Expand Down Expand Up @@ -327,7 +327,7 @@ class OnOffCapabilityVacuum(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain != vacuum.DOMAIN:
return False

Expand Down Expand Up @@ -379,7 +379,7 @@ class OnOffCapabilityClimate(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == climate.DOMAIN

def get_value(self) -> bool | None:
Expand Down Expand Up @@ -418,7 +418,7 @@ class OnOffCapabilityWaterHeater(OnOffCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == water_heater.DOMAIN

def get_value(self) -> bool | None:
Expand Down
16 changes: 8 additions & 8 deletions custom_components/yandex_smart_home/capability_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class CoverPositionCapability(StateRangeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == cover.DOMAIN and bool(self._state_features & cover.CoverEntityFeature.SET_POSITION)

@property
Expand Down Expand Up @@ -211,7 +211,7 @@ class TemperatureCapabilityWaterHeater(TemperatureCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == water_heater.DOMAIN and bool(
self._state_features & water_heater.WaterHeaterEntityFeature.TARGET_TEMPERATURE
)
Expand Down Expand Up @@ -246,7 +246,7 @@ class TemperatureCapabilityClimate(TemperatureCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == climate.DOMAIN and bool(
self._state_features & climate.ClimateEntityFeature.TARGET_TEMPERATURE
)
Expand Down Expand Up @@ -292,7 +292,7 @@ class HumidityCapabilityHumidifier(HumidityCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
return self.state.domain == humidifier.DOMAIN

async def set_instance_state(self, context: Context, state: RangeCapabilityInstanceActionState) -> None:
Expand Down Expand Up @@ -325,7 +325,7 @@ class HumidityCapabilityXiaomiFan(HumidityCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == fan.DOMAIN:
if self.state.attributes.get(ATTR_MODEL, "").startswith(MODEL_PREFIX_XIAOMI_AIRPURIFIER):
if ATTR_TARGET_HUMIDITY in self.state.attributes:
Expand Down Expand Up @@ -356,7 +356,7 @@ class BrightnessCapability(StateRangeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == light.DOMAIN:
if self._state_features & light.SUPPORT_BRIGHTNESS:
return True
Expand Down Expand Up @@ -411,7 +411,7 @@ class VolumeCapability(StateRangeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == media_player.DOMAIN:
if self._state_features & media_player.MediaPlayerEntityFeature.VOLUME_STEP:
return True
Expand Down Expand Up @@ -492,7 +492,7 @@ class ChannelCapability(StateRangeCapability):

@property
def supported(self) -> bool:
"""Test if the capability is supported for its state."""
"""Test if the capability is supported."""
if self.state.domain == media_player.DOMAIN:
if (
self._state_features & media_player.MediaPlayerEntityFeature.PREVIOUS_TRACK
Expand Down
Loading

0 comments on commit 6e8226d

Please sign in to comment.