Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark entity abc #28869

Merged
merged 3 commits into from Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions homeassistant/components/climate/__init__.py
@@ -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
Expand Down Expand Up @@ -270,20 +271,20 @@ def target_humidity(self) -> Optional[int]:
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]:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/helpers/entity.py
@@ -1,5 +1,5 @@
"""An abstract class for entities."""

from abc import ABC
import asyncio
from datetime import datetime, timedelta
import logging
Expand Down Expand Up @@ -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
Expand Down
36 changes: 31 additions & 5 deletions tests/components/climate/test_init.py
@@ -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


Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down