Skip to content

Commit

Permalink
Drop support for HA prior to 2023.7
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Jul 26, 2023
1 parent 53f2f1a commit f889455
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 83 deletions.
5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
strategy:
matrix:
include:
- ha-version: '2023.2'
- ha-version: '2023.7'
latest: true
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Мобильное приложение [Дом с Алисой](https://mobile.yandex.ru/apps/smarthome)
* Веб-интерфейс [Квазар](https://yandex.ru/quasar/iot)

Компонент работает на Home Assistant версии **2023.2** или новее.
Компонент работает на Home Assistant версии **2023.7** или новее.

## Ссылки
* [**Документация**](https://docs.yaha-cloud.ru/v0.6.x/)
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Мобильное приложение [Дом с Алисой](https://mobile.yandex.ru/apps/smarthome)
* Веб-интерфейс [Квазар](https://yandex.ru/quasar/iot)

Компонент работает на Home Assistant версии **2023.2** или новее.
Компонент работает на Home Assistant версии **2023.7** или новее.

## Полезные ссылки
* [Чат по компоненту в Телеграме :fontawesome-brands-telegram:](https://t.me/yandex_smart_home)
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"country": ["RU", "BY"],
"homeassistant": "2023.2",
"homeassistant": "2023.7",
"name": "Yandex Smart Home",
"render_readme": true
}
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.coverage.report]
exclude_also = [
"raise NotImplementedError",
"@abstractmethod"
]
75 changes: 32 additions & 43 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from homeassistant.helpers import entityfilter
from homeassistant.setup import async_setup_component
import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry
from pytest_homeassistant_custom_component.common import MockConfigEntry, MockUser

from custom_components import yandex_smart_home
from custom_components.yandex_smart_home import DOMAIN, async_setup, async_setup_entry, const

pytest_plugins = 'pytest_homeassistant_custom_component'


def pytest_configure(config):
def pytest_configure(*_):
yandex_smart_home._PYTEST = True


Expand All @@ -29,6 +29,15 @@ def auto_enable_custom_integrations(enable_custom_integrations):
yield


@pytest.fixture(name='skip_notifications', autouse=True)
def skip_notifications_fixture():
"""Skip notification calls."""
with patch('homeassistant.components.persistent_notification.async_create'), patch(
'homeassistant.components.persistent_notification.async_dismiss'
):
yield


@pytest.fixture
def config_entry():
return MockConfigEntry(
Expand All @@ -42,7 +51,7 @@ def config_entry():


@pytest.fixture
def config_entry_with_notifier(hass_admin_user):
def config_entry_with_notifier(hass_admin_user: MockUser):
return MockConfigEntry(domain=DOMAIN, data={const.CONF_NOTIFIER: [{
const.CONF_NOTIFIER_OAUTH_TOKEN: '',
const.CONF_NOTIFIER_SKILL_ID: '',
Expand Down Expand Up @@ -70,8 +79,8 @@ def config_entry_cloud_connection():
@pytest.fixture
def hass_platform(event_loop: asyncio.AbstractEventLoop, hass, config_entry):
demo_sensor = DemoSensor(
unique_id='outside_temp',
name='Outside Temperature',
'outside_temp',
'Outside Temperature',
state=15.6,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
Expand All @@ -80,29 +89,24 @@ def hass_platform(event_loop: asyncio.AbstractEventLoop, hass, config_entry):
)
demo_sensor.hass = hass
demo_sensor.entity_id = 'sensor.outside_temp'
demo_sensor._attr_name = 'Outside Temperature'

demo_light = DemoLight(
unique_id='light_kitchen',
name='Kitchen Light',
'light_kitchen',
'Kitchen Light',
available=True,
state=True,
)
demo_light.hass = hass
demo_light.entity_id = 'light.kitchen'
demo_light._attr_name = 'Kitchen Light'

event_loop.run_until_complete(
demo_sensor.async_update_ha_state()
)
event_loop.run_until_complete(
demo_light.async_update_ha_state()
)
demo_sensor.async_write_ha_state()
demo_light.async_write_ha_state()

event_loop.run_until_complete(
async_setup_component(hass, http.DOMAIN, {http.DOMAIN: {}})
)
event_loop.run_until_complete(
hass.async_block_till_done()
)

config_entry.add_to_hass(hass)
with patch.object(hass.config_entries.flow, 'async_init', return_value=None):
Expand All @@ -115,8 +119,8 @@ def hass_platform(event_loop: asyncio.AbstractEventLoop, hass, config_entry):
@pytest.fixture
def hass_platform_cloud_connection(event_loop: asyncio.AbstractEventLoop, hass, config_entry_cloud_connection):
demo_sensor = DemoSensor(
unique_id='outside_temp',
name='Outside Temperature',
'outside_temp',
'Outside Temperature',
state=15.6,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
Expand All @@ -125,42 +129,36 @@ def hass_platform_cloud_connection(event_loop: asyncio.AbstractEventLoop, hass,
)
demo_sensor.hass = hass
demo_sensor.entity_id = 'sensor.outside_temp'
demo_sensor._attr_name = 'Outside Temperature'

demo_binary_sensor = DemoBinarySensor(
unique_id='front_door',
name='Front Door',
'front_door',
'Front Door',
state=True,
device_class=BinarySensorDeviceClass.DOOR,
)
demo_binary_sensor.hass = hass
demo_binary_sensor.entity_id = 'binary_sensor.front_Door'
demo_binary_sensor._attr_name = 'Front Door'

demo_light = DemoLight(
unique_id='light_kitchen',
name='Kitchen Light',
'light_kitchen',
'Kitchen Light',
ct=240,
available=True,
state=True,
)
demo_light.hass = hass
demo_light.entity_id = 'light.kitchen'
demo_light._attr_name = 'Kitchen Light'

event_loop.run_until_complete(
demo_sensor.async_update_ha_state()
)
event_loop.run_until_complete(
demo_binary_sensor.async_update_ha_state()
)
event_loop.run_until_complete(
demo_light.async_update_ha_state()
)
demo_sensor.async_write_ha_state()
demo_binary_sensor.async_write_ha_state()
demo_light.async_write_ha_state()

event_loop.run_until_complete(
async_setup_component(hass, http.DOMAIN, {http.DOMAIN: {}})
)
event_loop.run_until_complete(
hass.async_block_till_done()
)

config_entry_cloud_connection.add_to_hass(hass)
event_loop.run_until_complete(async_setup(hass, {}))
Expand All @@ -169,12 +167,3 @@ def hass_platform_cloud_connection(event_loop: asyncio.AbstractEventLoop, hass,
event_loop.run_until_complete(hass.async_block_till_done())

return hass


@pytest.fixture(name='skip_notifications', autouse=True)
def skip_notifications_fixture():
"""Skip notification calls."""
with patch('homeassistant.components.persistent_notification.async_create'), patch(
'homeassistant.components.persistent_notification.async_dismiss'
):
yield
4 changes: 4 additions & 0 deletions tests/requirements_2023.7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest-homeassistant-custom-component==0.13.42
aiohttp-cors==0.7.0
home_assistant_intents==2023.7.24
hassil==1.2.0
24 changes: 16 additions & 8 deletions tests/test_capability.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

from typing import Any, Optional
from unittest.mock import patch

from homeassistant import core
from homeassistant.components import button, climate, cover, fan, humidifier, light, lock, media_player, switch
from homeassistant.const import STATE_ON
from homeassistant.const import STATE_ON, Platform
from homeassistant.core import HomeAssistant, State
from homeassistant.setup import async_setup_component

Expand Down Expand Up @@ -111,13 +113,19 @@ async def set_state(self, data, state):


async def test_capability_demo_platform(hass):
components = [button, switch, light, cover, media_player, fan, climate, humidifier, lock]

for component in components:
await async_setup_component(
hass, component.DOMAIN, {component.DOMAIN: [{'platform': 'demo'}]}
)
await hass.async_block_till_done()
with patch(
'homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM',
[
Platform.BUTTON, Platform.SWITCH, Platform.LIGHT, Platform.COVER, Platform.MEDIA_PLAYER, Platform.FAN,
Platform.CLIMATE, Platform.HUMIDIFIER, Platform.LOCK
],
):
await async_setup_component(hass, core.DOMAIN, {})
for component in [button, switch, light, cover, media_player, fan, climate, humidifier, lock]:
await async_setup_component(
hass, component.DOMAIN, {component.DOMAIN: [{'platform': 'demo'}]}
)
await hass.async_block_till_done()

# for x in sorted(hass.states.async_all(), key=lambda e: e.entity_id):
# e = YandexEntity(hass, BASIC_CONFIG, x)
Expand Down
17 changes: 14 additions & 3 deletions tests/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from unittest.mock import patch

from aiohttp import WSMessage, WSMsgType
from homeassistant import core
from homeassistant.components import switch
from homeassistant.const import Platform
from homeassistant.setup import async_setup_component
import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry
Expand Down Expand Up @@ -198,7 +201,10 @@ async def test_cloud_messages_invalid_format(hass_platform_cloud_connection, con
mock_reconnect.assert_called_once()


async def test_cloud_req_user_devices(hass_platform_cloud_connection, config, aioclient_mock):
@pytest.mark.parametrize('expected_lingering_timers', [True])
async def test_cloud_req_user_devices(
hass_platform_cloud_connection, config, aioclient_mock, expected_lingering_timers
):
hass = hass_platform_cloud_connection
requests = [{
'request_id': 'req_user_devices',
Expand Down Expand Up @@ -354,8 +360,13 @@ async def test_cloud_req_user_devices_action(hass_platform_cloud_connection, con
})
}]

await async_setup_component(hass, 'switch', {'switch': {'platform': 'demo'}})
await hass.async_block_till_done()
with patch(
'homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM',
[Platform.SWITCH],
):
await async_setup_component(hass, core.DOMAIN, {})
await async_setup_component(hass, switch.DOMAIN, {switch.DOMAIN: {'platform': 'demo'}})
await hass.async_block_till_done()

assert hass.states.get('switch.ac').state == 'off'

Expand Down
7 changes: 4 additions & 3 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ def supported(self) -> bool:

async def test_yandex_entity_capabilities(hass):
light = DemoLight(
unique_id='test_light',
name='Light',
'test_light',
'Light',
available=True,
state=True,
)
light.hass = hass
light.entity_id = 'light.test'
await light.async_update_ha_state()
light._attr_name = 'Light'
light.async_write_ha_state()

state = hass.states.get('light.test')
state_sensor = State('sensor.test', '33')
Expand Down
29 changes: 22 additions & 7 deletions tests/test_http.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from http import HTTPStatus
from unittest.mock import patch

from homeassistant import core
from homeassistant.components import switch
from homeassistant.const import Platform
from homeassistant.setup import async_setup_component
import pytest
from pytest_homeassistant_custom_component.common import MockUser

from custom_components.yandex_smart_home import async_unload_entry
from custom_components.yandex_smart_home.http import (
Expand All @@ -22,7 +28,8 @@ async def test_unauthorized_view(hass_platform, aiohttp_client, config_entry, so
assert response.status == HTTPStatus.NOT_FOUND


async def test_ping(hass_platform, aiohttp_client, config_entry, socket_enabled):
@pytest.mark.parametrize('expected_lingering_timers', [True])
async def test_ping(hass_platform, aiohttp_client, config_entry, socket_enabled, expected_lingering_timers):
http_client = await aiohttp_client(hass_platform.http.app)
response = await http_client.get(YandexSmartHomePingView.url)
assert response.status == HTTPStatus.OK
Expand Down Expand Up @@ -58,7 +65,8 @@ async def test_user_unlink(hass_platform, hass_client):
assert await response.json() == {'request_id': REQ_ID}


async def test_user_devices(hass_platform, hass_client, hass_admin_user):
@pytest.mark.parametrize('expected_lingering_timers', [True])
async def test_user_devices(hass_platform, hass_client, hass_admin_user: MockUser, expected_lingering_timers):
http_client = await hass_client()
response = await http_client.get(
YandexSmartHomeView.url + '/user/devices',
Expand Down Expand Up @@ -167,10 +175,17 @@ async def test_user_devices_query(hass_platform, hass_client):


async def test_user_devices_action(hass_platform, hass_client):
await async_setup_component(hass_platform, 'switch', {'switch': {'platform': 'demo'}})
await hass_platform.async_block_till_done()
hass = hass_platform

assert hass_platform.states.get('switch.ac').state == 'off'
with patch(
'homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM',
[Platform.SWITCH],
):
await async_setup_component(hass, core.DOMAIN, {})
await async_setup_component(hass, switch.DOMAIN, {switch.DOMAIN: {'platform': 'demo'}})
await hass.async_block_till_done()

assert hass.states.get('switch.ac').state == 'off'

http_client = await hass_client()

Expand Down Expand Up @@ -210,5 +225,5 @@ async def test_user_devices_action(hass_platform, hass_client):
}
}

await hass_platform.async_block_till_done()
assert hass_platform.states.get('switch.ac').state == 'on'
await hass.async_block_till_done()
assert hass.states.get('switch.ac').state == 'on'
Loading

0 comments on commit f889455

Please sign in to comment.