Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/wmspro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Platform.COVER,
Platform.LIGHT,
Platform.SCENE,
Platform.SWITCH,
]

type WebControlProConfigEntry = ConfigEntry[WebControlPro]
Expand Down
62 changes: 62 additions & 0 deletions homeassistant/components/wmspro/switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Support for loads connected with WMS WebControl pro."""

from __future__ import annotations

from datetime import timedelta
from typing import Any

from wmspro.const import (
WMS_WebControl_pro_API_actionDescription,
WMS_WebControl_pro_API_responseType,
)

from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from . import WebControlProConfigEntry
from .entity import WebControlProGenericEntity

SCAN_INTERVAL = timedelta(seconds=15)
PARALLEL_UPDATES = 1


async def async_setup_entry(
hass: HomeAssistant,
config_entry: WebControlProConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the WMS based switches from a config entry."""
hub = config_entry.runtime_data

async_add_entities(
WebControlProSwitch(config_entry.entry_id, dest)
for dest in hub.dests.values()
if dest.hasAction(WMS_WebControl_pro_API_actionDescription.LoadSwitch)
)


class WebControlProSwitch(WebControlProGenericEntity, SwitchEntity):
"""Representation of a WMS based switch."""

_attr_name = None

@property
def is_on(self) -> bool:
"""Return true if switch is on."""
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.LoadSwitch)
return action["onOffState"]

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on."""
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.LoadSwitch)
await action(
onOffState=True, responseType=WMS_WebControl_pro_API_responseType.Detailed
)

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off."""
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.LoadSwitch)
await action(
onOffState=False, responseType=WMS_WebControl_pro_API_responseType.Detailed
)
20 changes: 20 additions & 0 deletions tests/components/wmspro/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ def mock_hub_configuration_prod_awning_valance() -> Generator[AsyncMock]:
yield mock_hub_configuration


@pytest.fixture
def mock_hub_configuration_prod_load_switch() -> Generator[AsyncMock]:
"""Override WebControlPro._getConfiguration."""
with patch(
"wmspro.webcontrol.WebControlPro._getConfiguration",
return_value=load_json_object_fixture("config_prod_load_switch.json", DOMAIN),
) as mock_hub_configuration:
yield mock_hub_configuration


@pytest.fixture
def mock_hub_configuration_prod_roller_shutter() -> Generator[AsyncMock]:
"""Override WebControlPro._getConfiguration."""
Expand Down Expand Up @@ -114,6 +124,16 @@ def mock_hub_status_prod_dimmer() -> Generator[AsyncMock]:
yield mock_hub_status


@pytest.fixture
def mock_hub_status_prod_load_switch() -> Generator[AsyncMock]:
"""Override WebControlPro._getStatus."""
with patch(
"wmspro.webcontrol.WebControlPro._getStatus",
return_value=load_json_object_fixture("status_prod_load_switch.json", DOMAIN),
) as mock_hub_status:
yield mock_hub_status


@pytest.fixture
def mock_hub_status_prod_roller_shutter() -> Generator[AsyncMock]:
"""Override WebControlPro._getStatus."""
Expand Down
249 changes: 249 additions & 0 deletions tests/components/wmspro/fixtures/config_prod_load_switch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
{
"command": "getConfiguration",
"protocolVersion": "1.0.0",
"destinations": [
{
"id": 65355,
"animationType": 3,
"names": ["DACH", "", "", ""],
"actions": [
{
"id": 6,
"actionType": 2,
"actionDescription": 3,
"minValue": -127,
"maxValue": 127
},
{
"id": 16,
"actionType": 6,
"actionDescription": 12
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
},
{
"id": 23,
"actionType": 7,
"actionDescription": 12
}
]
},
{
"id": 90732,
"animationType": 1,
"names": ["MARKISE LINKS", "", "", ""],
"actions": [
{
"id": 0,
"actionType": 0,
"actionDescription": 0,
"minValue": 0,
"maxValue": 100
},
{
"id": 16,
"actionType": 6,
"actionDescription": 12
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
}
]
},
{
"id": 159890,
"animationType": 1,
"names": ["MARKISE VORNE", "", "", ""],
"actions": [
{
"id": 0,
"actionType": 0,
"actionDescription": 0,
"minValue": 0,
"maxValue": 100
},
{
"id": 16,
"actionType": 6,
"actionDescription": 12
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
}
]
},
{
"id": 201106,
"animationType": 1,
"names": ["MARKISE RECHTS", "", "", ""],
"actions": [
{
"id": 0,
"actionType": 0,
"actionDescription": 0,
"minValue": 0,
"maxValue": 100
},
{
"id": 16,
"actionType": 6,
"actionDescription": 12
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
}
]
},
{
"id": 317448,
"animationType": 6,
"names": ["LICHT SENKRECHT", "", "", ""],
"actions": [
{
"id": 0,
"actionType": 0,
"actionDescription": 8,
"minValue": 0,
"maxValue": 100
},
{
"id": 17,
"actionType": 6,
"actionDescription": 12
},
{
"id": 20,
"actionType": 4,
"actionDescription": 6
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
}
]
},
{
"id": 382168,
"animationType": 6,
"names": ["LICHT OBEN", "", "", ""],
"actions": [
{
"id": 0,
"actionType": 0,
"actionDescription": 8,
"minValue": 0,
"maxValue": 100
},
{
"id": 17,
"actionType": 6,
"actionDescription": 12
},
{
"id": 20,
"actionType": 4,
"actionDescription": 6
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
}
]
},
{
"id": 414040,
"animationType": 6,
"names": ["LICHT UNTEN", "", "", ""],
"actions": [
{
"id": 0,
"actionType": 0,
"actionDescription": 8,
"minValue": 0,
"maxValue": 100
},
{
"id": 17,
"actionType": 6,
"actionDescription": 12
},
{
"id": 20,
"actionType": 4,
"actionDescription": 6
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
}
]
},
{
"id": 499120,
"animationType": 5,
"names": ["HEIZUNG LINKS", "", "", ""],
"actions": [
{
"id": 20,
"actionType": 4,
"actionDescription": 7
},
{
"id": 21,
"actionType": 5,
"actionDescription": 10
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
}
]
},
{
"id": 533844,
"animationType": 5,
"names": ["HEIZUNG RECHTS", "", "", ""],
"actions": [
{
"id": 20,
"actionType": 4,
"actionDescription": 7
},
{
"id": 21,
"actionType": 5,
"actionDescription": 10
},
{
"id": 22,
"actionType": 8,
"actionDescription": 13
}
]
}
],
"rooms": [
{
"id": 39443,
"name": "Terasse",
Comment thread
mback2k marked this conversation as resolved.
"destinations": [
65355, 90732, 159890, 201106, 317448, 382168, 414040, 499120, 533844
],
"scenes": []
}
],
"scenes": []
}
28 changes: 28 additions & 0 deletions tests/components/wmspro/fixtures/status_prod_load_switch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"command": "getStatus",
"protocolVersion": "1.0.0",
"details": [
{
"destinationId": 499120,
"data": {
"drivingCause": 0,
"heartbeatError": false,
"blocking": false,
"productData": [
{
"actionId": 20,
"value": {
"onOffState": false
}
},
{
"actionId": 21,
"value": {
"onOffState": false
}
}
]
}
}
]
}
Loading
Loading