mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +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."""
|
||||
from abc import abstractmethod
|
||||
from datetime import timedelta
|
||||
import functools as ft
|
||||
import logging
|
||||
@ -270,20 +271,20 @@ class ClimateDevice(Entity):
|
||||
return None
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def hvac_mode(self) -> str:
|
||||
"""Return hvac operation ie. heat, cool mode.
|
||||
|
||||
Need to be one of HVAC_MODE_*.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def hvac_modes(self) -> List[str]:
|
||||
"""Return the list of available hvac operation modes.
|
||||
|
||||
Need to be a subset of HVAC_MODES.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def hvac_action(self) -> Optional[str]:
|
||||
|
@ -1,9 +1,14 @@
|
||||
"""Support for the PRT Heatmiser themostats using the V3 protocol."""
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
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.const import (
|
||||
TEMP_CELSIUS,
|
||||
@ -82,6 +87,22 @@ class HeatmiserV3Thermostat(ClimateDevice):
|
||||
"""Return the unit of measurement which this thermostat uses."""
|
||||
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
|
||||
def current_temperature(self):
|
||||
"""Return the current temperature."""
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""An abstract class for entities."""
|
||||
|
||||
from abc import ABC
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
@ -85,7 +85,7 @@ def async_generate_entity_id(
|
||||
return ensure_unique_string(entity_id_format.format(slugify(name)), current_ids)
|
||||
|
||||
|
||||
class Entity:
|
||||
class Entity(ABC):
|
||||
"""An abstract class for Home Assistant entities."""
|
||||
|
||||
# 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
|
||||
# unnecessary-pass - readability for functions which only contain pass
|
||||
# import-outside-toplevel - TODO
|
||||
# too-many-ancestors - it's too strict.
|
||||
disable=
|
||||
format,
|
||||
abstract-class-little-used,
|
||||
@ -37,6 +38,7 @@ disable=
|
||||
not-context-manager,
|
||||
redefined-variable-type,
|
||||
too-few-public-methods,
|
||||
too-many-ancestors,
|
||||
too-many-arguments,
|
||||
too-many-branches,
|
||||
too-many-instance-attributes,
|
||||
|
@ -1,10 +1,16 @@
|
||||
"""The tests for the climate component."""
|
||||
from unittest.mock import MagicMock
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
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
|
||||
|
||||
|
||||
@ -38,9 +44,29 @@ async def test_set_temp_schema(hass, caplog):
|
||||
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):
|
||||
"""Test if adding turn_on work."""
|
||||
climate = ClimateDevice()
|
||||
"""Test if async turn_on calls sync turn_on."""
|
||||
climate = MockClimateDevice()
|
||||
climate.hass = hass
|
||||
|
||||
climate.turn_on = MagicMock()
|
||||
@ -50,8 +76,8 @@ async def test_sync_turn_on(hass):
|
||||
|
||||
|
||||
async def test_sync_turn_off(hass):
|
||||
"""Test if adding turn_on work."""
|
||||
climate = ClimateDevice()
|
||||
"""Test if async turn_off calls sync turn_off."""
|
||||
climate = MockClimateDevice()
|
||||
climate.hass = hass
|
||||
|
||||
climate.turn_off = MagicMock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user