mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Update support to external library pypglab to version 0.0.5 (#141876)
update support to external library pypglab to version 0.0.5
This commit is contained in:
parent
0488012c77
commit
c0e8f14745
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
from pypglab.mqtt import (
|
from pypglab.mqtt import (
|
||||||
Client as PyPGLabMqttClient,
|
Client as PyPGLabMqttClient,
|
||||||
Sub_State as PyPGLabSubState,
|
Sub_State as PyPGLabSubState,
|
||||||
Subcribe_CallBack as PyPGLabSubscribeCallBack,
|
Subscribe_CallBack as PyPGLabSubscribeCallBack,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components import mqtt
|
from homeassistant.components import mqtt
|
||||||
|
@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Any
|
|||||||
|
|
||||||
from pypglab.const import SENSOR_REBOOT_TIME, SENSOR_TEMPERATURE, SENSOR_VOLTAGE
|
from pypglab.const import SENSOR_REBOOT_TIME, SENSOR_TEMPERATURE, SENSOR_VOLTAGE
|
||||||
from pypglab.device import Device as PyPGLabDevice
|
from pypglab.device import Device as PyPGLabDevice
|
||||||
from pypglab.sensor import Sensor as PyPGLabSensors
|
from pypglab.sensor import StatusSensor as PyPGLabSensors
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
@ -31,7 +31,7 @@ class PGLabSensorsCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
|
|
||||||
# get a reference of PG Lab device internal sensors state
|
# get a reference of PG Lab device internal sensors state
|
||||||
self._sensors: PyPGLabSensors = pglab_device.sensors
|
self._sensors: PyPGLabSensors = pglab_device.status_sensor
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
|
@ -220,7 +220,7 @@ class PGLabDiscovery:
|
|||||||
configuration_url=f"http://{pglab_device.ip}/",
|
configuration_url=f"http://{pglab_device.ip}/",
|
||||||
connections={(CONNECTION_NETWORK_MAC, pglab_device.mac)},
|
connections={(CONNECTION_NETWORK_MAC, pglab_device.mac)},
|
||||||
identifiers={(DOMAIN, pglab_device.id)},
|
identifiers={(DOMAIN, pglab_device.id)},
|
||||||
manufacturer=pglab_device.manufactor,
|
manufacturer=pglab_device.manufacturer,
|
||||||
model=pglab_device.type,
|
model=pglab_device.type,
|
||||||
name=pglab_device.name,
|
name=pglab_device.name,
|
||||||
sw_version=pglab_device.firmware_version,
|
sw_version=pglab_device.firmware_version,
|
||||||
|
@ -37,7 +37,7 @@ class PGLabBaseEntity(Entity):
|
|||||||
sw_version=pglab_device.firmware_version,
|
sw_version=pglab_device.firmware_version,
|
||||||
hw_version=pglab_device.hardware_version,
|
hw_version=pglab_device.hardware_version,
|
||||||
model=pglab_device.type,
|
model=pglab_device.type,
|
||||||
manufacturer=pglab_device.manufactor,
|
manufacturer=pglab_device.manufacturer,
|
||||||
configuration_url=f"http://{pglab_device.ip}/",
|
configuration_url=f"http://{pglab_device.ip}/",
|
||||||
connections={(CONNECTION_NETWORK_MAC, pglab_device.mac)},
|
connections={(CONNECTION_NETWORK_MAC, pglab_device.mac)},
|
||||||
)
|
)
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
"loggers": ["pglab"],
|
"loggers": ["pglab"],
|
||||||
"mqtt": ["pglab/discovery/#"],
|
"mqtt": ["pglab/discovery/#"],
|
||||||
"quality_scale": "bronze",
|
"quality_scale": "bronze",
|
||||||
"requirements": ["pypglab==0.0.3"],
|
"requirements": ["pypglab==0.0.5"],
|
||||||
"single_config_entry": true
|
"single_config_entry": true
|
||||||
}
|
}
|
||||||
|
2
requirements_all.txt
generated
2
requirements_all.txt
generated
@ -2223,7 +2223,7 @@ pypca==0.0.7
|
|||||||
pypck==0.8.5
|
pypck==0.8.5
|
||||||
|
|
||||||
# homeassistant.components.pglab
|
# homeassistant.components.pglab
|
||||||
pypglab==0.0.3
|
pypglab==0.0.5
|
||||||
|
|
||||||
# homeassistant.components.pjlink
|
# homeassistant.components.pjlink
|
||||||
pypjlink2==1.2.1
|
pypjlink2==1.2.1
|
||||||
|
2
requirements_test_all.txt
generated
2
requirements_test_all.txt
generated
@ -1814,7 +1814,7 @@ pypalazzetti==0.1.19
|
|||||||
pypck==0.8.5
|
pypck==0.8.5
|
||||||
|
|
||||||
# homeassistant.components.pglab
|
# homeassistant.components.pglab
|
||||||
pypglab==0.0.3
|
pypglab==0.0.5
|
||||||
|
|
||||||
# homeassistant.components.pjlink
|
# homeassistant.components.pjlink
|
||||||
pypjlink2==1.2.1
|
pypjlink2==1.2.1
|
||||||
|
50
tests/components/pglab/test_common.py
Normal file
50
tests/components/pglab/test_common.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
"""Common code for PG LAB Electronics tests."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.common import async_fire_mqtt_message
|
||||||
|
|
||||||
|
|
||||||
|
def get_device_discovery_payload(
|
||||||
|
number_of_shutters: int,
|
||||||
|
number_of_boards: int,
|
||||||
|
device_name: str = "test",
|
||||||
|
) -> dict[str, any]:
|
||||||
|
"""Return the device discovery payload."""
|
||||||
|
|
||||||
|
# be sure the number of shutters and boards are in the correct range
|
||||||
|
assert 0 <= number_of_boards <= 8
|
||||||
|
assert 0 <= number_of_shutters <= (number_of_boards * 4)
|
||||||
|
|
||||||
|
# define the number of E-RELAY boards connected to E-BOARD
|
||||||
|
boards = "1" * number_of_boards + "0" * (8 - number_of_boards)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"ip": "192.168.1.16",
|
||||||
|
"mac": "80:34:28:1B:18:5A",
|
||||||
|
"name": device_name,
|
||||||
|
"hw": "1.0.7",
|
||||||
|
"fw": "1.0.0",
|
||||||
|
"type": "E-BOARD",
|
||||||
|
"id": "E-BOARD-DD53AC85",
|
||||||
|
"manufacturer": "PG LAB Electronics",
|
||||||
|
"params": {"shutters": number_of_shutters, "boards": boards},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def send_discovery_message(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
payload: dict[str, any] | None,
|
||||||
|
) -> None:
|
||||||
|
"""Send the discovery message to make E-BOARD device discoverable."""
|
||||||
|
|
||||||
|
topic = "pglab/discovery/E-BOARD-DD53AC85/config"
|
||||||
|
|
||||||
|
async_fire_mqtt_message(
|
||||||
|
hass,
|
||||||
|
topic,
|
||||||
|
json.dumps(payload if payload is not None else ""),
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
@ -1,7 +1,5 @@
|
|||||||
"""The tests for the PG LAB Electronics cover."""
|
"""The tests for the PG LAB Electronics cover."""
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
from homeassistant.components import cover
|
from homeassistant.components import cover
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
DOMAIN as COVER_DOMAIN,
|
DOMAIN as COVER_DOMAIN,
|
||||||
@ -19,6 +17,8 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .test_common import get_device_discovery_payload, send_discovery_message
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message
|
from tests.common import async_fire_mqtt_message
|
||||||
from tests.typing import MqttMockHAClient
|
from tests.typing import MqttMockHAClient
|
||||||
|
|
||||||
@ -43,25 +43,13 @@ async def test_cover_features(
|
|||||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test cover features."""
|
"""Test cover features."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
|
||||||
payload = {
|
|
||||||
"ip": "192.168.1.16",
|
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 4, "boards": "10000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
payload = get_device_discovery_payload(
|
||||||
hass,
|
number_of_shutters=4,
|
||||||
topic,
|
number_of_boards=1,
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
assert len(hass.states.async_all("cover")) == 4
|
assert len(hass.states.async_all("cover")) == 4
|
||||||
|
|
||||||
@ -75,25 +63,13 @@ async def test_cover_availability(
|
|||||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Check if covers are properly created."""
|
"""Check if covers are properly created."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
|
||||||
payload = {
|
|
||||||
"ip": "192.168.1.16",
|
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 6, "boards": "11000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
payload = get_device_discovery_payload(
|
||||||
hass,
|
number_of_shutters=6,
|
||||||
topic,
|
number_of_boards=2,
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# We are creating 6 covers using two E-RELAY devices connected to E-BOARD.
|
# We are creating 6 covers using two E-RELAY devices connected to E-BOARD.
|
||||||
# Now we are going to check if all covers are created and their state is unknown.
|
# Now we are going to check if all covers are created and their state is unknown.
|
||||||
@ -111,25 +87,12 @@ async def test_cover_change_state_via_mqtt(
|
|||||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test state update via MQTT."""
|
"""Test state update via MQTT."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
payload = get_device_discovery_payload(
|
||||||
payload = {
|
number_of_shutters=2,
|
||||||
"ip": "192.168.1.16",
|
number_of_boards=1,
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 2, "boards": "10000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# Check initial state is unknown
|
# Check initial state is unknown
|
||||||
cover = hass.states.get("cover.test_shutter_0")
|
cover = hass.states.get("cover.test_shutter_0")
|
||||||
@ -165,25 +128,13 @@ async def test_cover_mqtt_state_by_calling_service(
|
|||||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Calling service to OPEN/CLOSE cover and check mqtt state."""
|
"""Calling service to OPEN/CLOSE cover and check mqtt state."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
|
||||||
payload = {
|
|
||||||
"ip": "192.168.1.16",
|
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 2, "boards": "10000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
payload = get_device_discovery_payload(
|
||||||
hass,
|
number_of_shutters=2,
|
||||||
topic,
|
number_of_boards=1,
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
cover = hass.states.get("cover.test_shutter_0")
|
cover = hass.states.get("cover.test_shutter_0")
|
||||||
assert cover.state == STATE_UNKNOWN
|
assert cover.state == STATE_UNKNOWN
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
"""The tests for the PG LAB Electronics discovery device."""
|
"""The tests for the PG LAB Electronics discovery device."""
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message
|
from .test_common import get_device_discovery_payload, send_discovery_message
|
||||||
|
|
||||||
from tests.typing import MqttMockHAClient
|
from tests.typing import MqttMockHAClient
|
||||||
|
|
||||||
|
|
||||||
@ -19,25 +18,13 @@ async def test_device_discover(
|
|||||||
setup_pglab,
|
setup_pglab,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up a device."""
|
"""Test setting up a device."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
|
||||||
payload = {
|
|
||||||
"ip": "192.168.1.16",
|
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "11000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
payload = get_device_discovery_payload(
|
||||||
hass,
|
number_of_shutters=0,
|
||||||
topic,
|
number_of_boards=2,
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# Verify device and registry entries are created
|
# Verify device and registry entries are created
|
||||||
device_entry = device_reg.async_get_device(
|
device_entry = device_reg.async_get_device(
|
||||||
@ -60,25 +47,12 @@ async def test_device_update(
|
|||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test update a device."""
|
"""Test update a device."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
payload = get_device_discovery_payload(
|
||||||
payload = {
|
number_of_shutters=0,
|
||||||
"ip": "192.168.1.16",
|
number_of_boards=2,
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "11000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# Verify device is created
|
# Verify device is created
|
||||||
device_entry = device_reg.async_get_device(
|
device_entry = device_reg.async_get_device(
|
||||||
@ -90,12 +64,7 @@ async def test_device_update(
|
|||||||
payload["fw"] = "1.0.1"
|
payload["fw"] = "1.0.1"
|
||||||
payload["hw"] = "1.0.8"
|
payload["hw"] = "1.0.8"
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
await send_discovery_message(hass, payload)
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Verify device is created
|
# Verify device is created
|
||||||
device_entry = device_reg.async_get_device(
|
device_entry = device_reg.async_get_device(
|
||||||
@ -114,25 +83,12 @@ async def test_device_remove(
|
|||||||
setup_pglab,
|
setup_pglab,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test remove a device."""
|
"""Test remove a device."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
payload = get_device_discovery_payload(
|
||||||
payload = {
|
number_of_shutters=0,
|
||||||
"ip": "192.168.1.16",
|
number_of_boards=2,
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "11000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# Verify device is created
|
# Verify device is created
|
||||||
device_entry = device_reg.async_get_device(
|
device_entry = device_reg.async_get_device(
|
||||||
@ -140,12 +96,7 @@ async def test_device_remove(
|
|||||||
)
|
)
|
||||||
assert device_entry is not None
|
assert device_entry is not None
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
await send_discovery_message(hass, None)
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Verify device entry is removed
|
# Verify device entry is removed
|
||||||
device_entry = device_reg.async_get_device(
|
device_entry = device_reg.async_get_device(
|
||||||
|
@ -8,34 +8,12 @@ from syrupy import SnapshotAssertion
|
|||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .test_common import get_device_discovery_payload, send_discovery_message
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message
|
from tests.common import async_fire_mqtt_message
|
||||||
from tests.typing import MqttMockHAClient
|
from tests.typing import MqttMockHAClient
|
||||||
|
|
||||||
|
|
||||||
async def send_discovery_message(hass: HomeAssistant) -> None:
|
|
||||||
"""Send mqtt discovery message."""
|
|
||||||
|
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
|
||||||
payload = {
|
|
||||||
"ip": "192.168.1.16",
|
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "00000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2024-02-26 01:21:34")
|
@freeze_time("2024-02-26 01:21:34")
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"sensor_suffix",
|
"sensor_suffix",
|
||||||
@ -55,7 +33,12 @@ async def test_sensors(
|
|||||||
"""Check if sensors are properly created and updated."""
|
"""Check if sensors are properly created and updated."""
|
||||||
|
|
||||||
# send the discovery message to make E-BOARD device discoverable
|
# send the discovery message to make E-BOARD device discoverable
|
||||||
await send_discovery_message(hass)
|
payload = get_device_discovery_payload(
|
||||||
|
number_of_shutters=0,
|
||||||
|
number_of_boards=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# check initial sensors state
|
# check initial sensors state
|
||||||
state = hass.states.get(f"sensor.test_{sensor_suffix}")
|
state = hass.states.get(f"sensor.test_{sensor_suffix}")
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""The tests for the PG LAB Electronics switch."""
|
"""The tests for the PG LAB Electronics switch."""
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import json
|
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.switch import (
|
from homeassistant.components.switch import (
|
||||||
@ -20,6 +19,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
from .test_common import get_device_discovery_payload, send_discovery_message
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message, async_fire_time_changed
|
from tests.common import async_fire_mqtt_message, async_fire_time_changed
|
||||||
from tests.typing import MqttMockHAClient
|
from tests.typing import MqttMockHAClient
|
||||||
|
|
||||||
@ -38,25 +39,13 @@ async def test_available_relay(
|
|||||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Check if relay are properly created when two E-Relay boards are connected."""
|
"""Check if relay are properly created when two E-Relay boards are connected."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
|
||||||
payload = {
|
|
||||||
"ip": "192.168.1.16",
|
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "11000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
payload = get_device_discovery_payload(
|
||||||
hass,
|
number_of_shutters=0,
|
||||||
topic,
|
number_of_boards=2,
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
for i in range(16):
|
for i in range(16):
|
||||||
state = hass.states.get(f"switch.test_relay_{i}")
|
state = hass.states.get(f"switch.test_relay_{i}")
|
||||||
@ -68,25 +57,13 @@ async def test_change_state_via_mqtt(
|
|||||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test state update via MQTT."""
|
"""Test state update via MQTT."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
|
||||||
payload = {
|
|
||||||
"ip": "192.168.1.16",
|
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "10000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
payload = get_device_discovery_payload(
|
||||||
hass,
|
number_of_shutters=0,
|
||||||
topic,
|
number_of_boards=1,
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# Simulate response from the device
|
# Simulate response from the device
|
||||||
state = hass.states.get("switch.test_relay_0")
|
state = hass.states.get("switch.test_relay_0")
|
||||||
@ -123,25 +100,13 @@ async def test_mqtt_state_by_calling_service(
|
|||||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_pglab
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Calling service to turn ON/OFF relay and check mqtt state."""
|
"""Calling service to turn ON/OFF relay and check mqtt state."""
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
|
||||||
payload = {
|
|
||||||
"ip": "192.168.1.16",
|
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "10000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
payload = get_device_discovery_payload(
|
||||||
hass,
|
number_of_shutters=0,
|
||||||
topic,
|
number_of_boards=1,
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# Turn relay ON
|
# Turn relay ON
|
||||||
await call_service(hass, "switch.test_relay_0", SERVICE_TURN_ON)
|
await call_service(hass, "switch.test_relay_0", SERVICE_TURN_ON)
|
||||||
@ -177,26 +142,13 @@ async def test_discovery_update(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Update discovery message and check if relay are property updated."""
|
"""Update discovery message and check if relay are property updated."""
|
||||||
|
|
||||||
# publish the first discovery message
|
payload = get_device_discovery_payload(
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
device_name="first_test",
|
||||||
payload = {
|
number_of_shutters=0,
|
||||||
"ip": "192.168.1.16",
|
number_of_boards=1,
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "first_test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "10000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# test the available relay in the first configuration
|
# test the available relay in the first configuration
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
@ -206,25 +158,13 @@ async def test_discovery_update(
|
|||||||
|
|
||||||
# prepare a new message ... the same device but renamed
|
# prepare a new message ... the same device but renamed
|
||||||
# and with different relay configuration
|
# and with different relay configuration
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
payload = get_device_discovery_payload(
|
||||||
payload = {
|
device_name="second_test",
|
||||||
"ip": "192.168.1.16",
|
number_of_shutters=0,
|
||||||
"mac": "80:34:28:1B:18:5A",
|
number_of_boards=2,
|
||||||
"name": "second_test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "11000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# be sure that old relay are been removed
|
# be sure that old relay are been removed
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
@ -245,25 +185,12 @@ async def test_disable_entity_state_change_via_mqtt(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test state update via MQTT of disable entity."""
|
"""Test state update via MQTT of disable entity."""
|
||||||
|
|
||||||
topic = "pglab/discovery/E-Board-DD53AC85/config"
|
payload = get_device_discovery_payload(
|
||||||
payload = {
|
number_of_shutters=0,
|
||||||
"ip": "192.168.1.16",
|
number_of_boards=1,
|
||||||
"mac": "80:34:28:1B:18:5A",
|
|
||||||
"name": "test",
|
|
||||||
"hw": "1.0.7",
|
|
||||||
"fw": "1.0.0",
|
|
||||||
"type": "E-Board",
|
|
||||||
"id": "E-Board-DD53AC85",
|
|
||||||
"manufacturer": "PG LAB Electronics",
|
|
||||||
"params": {"shutters": 0, "boards": "10000000"},
|
|
||||||
}
|
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
await send_discovery_message(hass, payload)
|
||||||
|
|
||||||
# Be sure that the entity relay_0 is available
|
# Be sure that the entity relay_0 is available
|
||||||
state = hass.states.get("switch.test_relay_0")
|
state = hass.states.get("switch.test_relay_0")
|
||||||
@ -298,12 +225,7 @@ async def test_disable_entity_state_change_via_mqtt(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Re-send the discovery message
|
# Re-send the discovery message
|
||||||
async_fire_mqtt_message(
|
await send_discovery_message(hass, payload)
|
||||||
hass,
|
|
||||||
topic,
|
|
||||||
json.dumps(payload),
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Be sure that the state is not changed
|
# Be sure that the state is not changed
|
||||||
state = hass.states.get("switch.test_relay_0")
|
state = hass.states.get("switch.test_relay_0")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user