mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Mark entity abc (#28869)
* Mark entity abc * Use abstractmethod in climate * Lint
This commit is contained in:
parent
21157f9dac
commit
94675ca5a7
@ -1,4 +1,5 @@
|
|||||||
"""Provides functionality to interact with climate devices."""
|
"""Provides functionality to interact with climate devices."""
|
||||||
|
from abc import abstractmethod
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import functools as ft
|
import functools as ft
|
||||||
import logging
|
import logging
|
||||||
@ -270,20 +271,20 @@ class ClimateDevice(Entity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@abstractmethod
|
||||||
def hvac_mode(self) -> str:
|
def hvac_mode(self) -> str:
|
||||||
"""Return hvac operation ie. heat, cool mode.
|
"""Return hvac operation ie. heat, cool mode.
|
||||||
|
|
||||||
Need to be one of HVAC_MODE_*.
|
Need to be one of HVAC_MODE_*.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@abstractmethod
|
||||||
def hvac_modes(self) -> List[str]:
|
def hvac_modes(self) -> List[str]:
|
||||||
"""Return the list of available hvac operation modes.
|
"""Return the list of available hvac operation modes.
|
||||||
|
|
||||||
Need to be a subset of HVAC_MODES.
|
Need to be a subset of HVAC_MODES.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self) -> Optional[str]:
|
def hvac_action(self) -> Optional[str]:
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
"""Support for the PRT Heatmiser themostats using the V3 protocol."""
|
"""Support for the PRT Heatmiser themostats using the V3 protocol."""
|
||||||
import logging
|
import logging
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateDevice, PLATFORM_SCHEMA
|
from homeassistant.components.climate import (
|
||||||
|
ClimateDevice,
|
||||||
|
PLATFORM_SCHEMA,
|
||||||
|
HVAC_MODE_HEAT,
|
||||||
|
)
|
||||||
from homeassistant.components.climate.const import SUPPORT_TARGET_TEMPERATURE
|
from homeassistant.components.climate.const import SUPPORT_TARGET_TEMPERATURE
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
@ -82,6 +87,22 @@ class HeatmiserV3Thermostat(ClimateDevice):
|
|||||||
"""Return the unit of measurement which this thermostat uses."""
|
"""Return the unit of measurement which this thermostat uses."""
|
||||||
return TEMP_CELSIUS
|
return TEMP_CELSIUS
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hvac_mode(self) -> str:
|
||||||
|
"""Return hvac operation ie. heat, cool mode.
|
||||||
|
|
||||||
|
Need to be one of HVAC_MODE_*.
|
||||||
|
"""
|
||||||
|
return HVAC_MODE_HEAT
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hvac_modes(self) -> List[str]:
|
||||||
|
"""Return the list of available hvac operation modes.
|
||||||
|
|
||||||
|
Need to be a subset of HVAC_MODES.
|
||||||
|
"""
|
||||||
|
return [HVAC_MODE_HEAT]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""An abstract class for entities."""
|
"""An abstract class for entities."""
|
||||||
|
from abc import ABC
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
@ -85,7 +85,7 @@ def async_generate_entity_id(
|
|||||||
return ensure_unique_string(entity_id_format.format(slugify(name)), current_ids)
|
return ensure_unique_string(entity_id_format.format(slugify(name)), current_ids)
|
||||||
|
|
||||||
|
|
||||||
class Entity:
|
class Entity(ABC):
|
||||||
"""An abstract class for Home Assistant entities."""
|
"""An abstract class for Home Assistant entities."""
|
||||||
|
|
||||||
# SAFE TO OVERWRITE
|
# SAFE TO OVERWRITE
|
||||||
|
2
pylintrc
2
pylintrc
@ -24,6 +24,7 @@ good-names=id,i,j,k,ex,Run,_,fp
|
|||||||
# inconsistent-return-statements - doesn't handle raise
|
# inconsistent-return-statements - doesn't handle raise
|
||||||
# unnecessary-pass - readability for functions which only contain pass
|
# unnecessary-pass - readability for functions which only contain pass
|
||||||
# import-outside-toplevel - TODO
|
# import-outside-toplevel - TODO
|
||||||
|
# too-many-ancestors - it's too strict.
|
||||||
disable=
|
disable=
|
||||||
format,
|
format,
|
||||||
abstract-class-little-used,
|
abstract-class-little-used,
|
||||||
@ -37,6 +38,7 @@ disable=
|
|||||||
not-context-manager,
|
not-context-manager,
|
||||||
redefined-variable-type,
|
redefined-variable-type,
|
||||||
too-few-public-methods,
|
too-few-public-methods,
|
||||||
|
too-many-ancestors,
|
||||||
too-many-arguments,
|
too-many-arguments,
|
||||||
too-many-branches,
|
too-many-branches,
|
||||||
too-many-instance-attributes,
|
too-many-instance-attributes,
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
"""The tests for the climate component."""
|
"""The tests for the climate component."""
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import SET_TEMPERATURE_SCHEMA, ClimateDevice
|
from homeassistant.components.climate import (
|
||||||
|
SET_TEMPERATURE_SCHEMA,
|
||||||
|
ClimateDevice,
|
||||||
|
HVAC_MODE_HEAT,
|
||||||
|
HVAC_MODE_OFF,
|
||||||
|
)
|
||||||
from tests.common import async_mock_service
|
from tests.common import async_mock_service
|
||||||
|
|
||||||
|
|
||||||
@ -38,9 +44,29 @@ async def test_set_temp_schema(hass, caplog):
|
|||||||
assert calls[-1].data == data
|
assert calls[-1].data == data
|
||||||
|
|
||||||
|
|
||||||
|
class MockClimateDevice(ClimateDevice):
|
||||||
|
"""Mock Climate device to use in tests."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hvac_mode(self) -> str:
|
||||||
|
"""Return hvac operation ie. heat, cool mode.
|
||||||
|
|
||||||
|
Need to be one of HVAC_MODE_*.
|
||||||
|
"""
|
||||||
|
return HVAC_MODE_HEAT
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hvac_modes(self) -> List[str]:
|
||||||
|
"""Return the list of available hvac operation modes.
|
||||||
|
|
||||||
|
Need to be a subset of HVAC_MODES.
|
||||||
|
"""
|
||||||
|
return [HVAC_MODE_OFF, HVAC_MODE_HEAT]
|
||||||
|
|
||||||
|
|
||||||
async def test_sync_turn_on(hass):
|
async def test_sync_turn_on(hass):
|
||||||
"""Test if adding turn_on work."""
|
"""Test if async turn_on calls sync turn_on."""
|
||||||
climate = ClimateDevice()
|
climate = MockClimateDevice()
|
||||||
climate.hass = hass
|
climate.hass = hass
|
||||||
|
|
||||||
climate.turn_on = MagicMock()
|
climate.turn_on = MagicMock()
|
||||||
@ -50,8 +76,8 @@ async def test_sync_turn_on(hass):
|
|||||||
|
|
||||||
|
|
||||||
async def test_sync_turn_off(hass):
|
async def test_sync_turn_off(hass):
|
||||||
"""Test if adding turn_on work."""
|
"""Test if async turn_off calls sync turn_off."""
|
||||||
climate = ClimateDevice()
|
climate = MockClimateDevice()
|
||||||
climate.hass = hass
|
climate.hass = hass
|
||||||
|
|
||||||
climate.turn_off = MagicMock()
|
climate.turn_off = MagicMock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user