Skip to content

Commit

Permalink
cover test api response update, fix wrong seeding of light tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swistakm committed Mar 13, 2024
1 parent bdd5e20 commit 65eaff2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
5 changes: 0 additions & 5 deletions blebox_uniapi/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,10 @@ def __init__(
self._firmware_version = firmware_version
self._hardware_version = hardware_version
self._api_version = level

self._model = config.get("model", type)

self._api = config.get("api", {})

self._features = self.create_features(config, info, extended_state)

self._config = config

self._update_last_data(extended_state)

def create_features(
Expand Down
9 changes: 6 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ async def allow_get_info(self, aioclient_mock, info=None):
json_get_expect(
aioclient_mock, f"http://{self.IP}:80/api/device/state", json=data
)
if hasattr(self, "DEVICE_EXTENDED_INFO"):
data = self.DEVICE_EXTENDED_INFO if info is None else info
if (
(hasattr(self, "DEVICE_EXTENDED_INFO")) and
(path := getattr(self, "DEVICE_EXTENDED_INFO_PATH"))
):
data = self.DEVICE_EXTENDED_INFO or info
json_get_expect(
aioclient_mock,
f"http://{self.IP}:80{self.DEVICE_EXTENDED_INFO_PATH}",
f"http://{self.IP}:80/{path.lstrip('/')}",
json=data,
)

Expand Down
26 changes: 23 additions & 3 deletions tests/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ async def test_unkown_position(self, aioclient_mock):
class TestGateBoxB(CoverTest):
"""Tests for cover devices representing a BleBox gateBoxB subgroup."""

DEV_INFO_PATH = "state"
DEV_INFO_PATH = "state/extended"

DEVICE_INFO = json.loads(
"""
Expand Down Expand Up @@ -512,7 +512,17 @@ class TestGateBoxB(CoverTest):
STATE_DEFAULT = json.loads(
"""
{
"gate": {"currentPos": 0}
"gate": {
"currentPos": 0,
"openCloseMode": 0,
"gateType": 1,
"gatePulseTimeMs": 1500,
"gateOutputState": 0,
"extraButtonType": 1,
"extraButtonPulseTimeMs": 1500,
"extraButtonOutputState": 0,
"inputsType": 0
}
}
"""
)
Expand All @@ -524,7 +534,17 @@ class TestGateBoxB(CoverTest):
STATE_UNKNOWN = json.loads(
"""
{
"gate": {"currentPos": -1}
"gate": {
"currentPos": -1,
"openCloseMode": 0,
"gateType": 1,
"gatePulseTimeMs": 1500,
"gateOutputState": 0,
"extraButtonType": 1,
"extraButtonPulseTimeMs": 1500,
"extraButtonOutputState": 0,
"inputsType": 0
}
}
"""
)
Expand Down
21 changes: 8 additions & 13 deletions tests/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class TestWLightBoxS(DefaultBoxTest):
DEVICE_EXTENDED_INFO = {
"rgbw": {
"desiredColor": "f5",
"currentColor": "f5",
"currentColor": "f5", # 245 in decimal
"lastOnColor": "f5",
"durationsMs": {"colorFade": 1000, "effectFade": 1000, "effectStep": 1000},
"effectID": 0,
Expand Down Expand Up @@ -542,9 +542,8 @@ async def test_init(self, aioclient_mock):

assert entity.name == "My wLightBoxS (wLightBoxS#brightness_mono1)"
assert entity.unique_id == "BleBox-wLightBoxS-1afe34e750b8-brightness_mono1"
assert entity.brightness is None

assert entity.is_on is None
assert entity.brightness == 0xf5
assert entity.is_on

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
Expand Down Expand Up @@ -863,16 +862,12 @@ async def test_init(self, aioclient_mock):
assert entity.name == "My light 1 (wLightBox#color_RGBorW)"
assert entity.unique_id == "BleBox-wLightBox-1afe34e750b8-color_RGBorW"
# In current state of master branch white_value is not property of BleBoxLightEntity, fake test... dissapointing
# assert entity.supported_features & SUPPORT_WHITE_VALUE
# assert entity.white_value is None

# assert entity.supported_features & SUPPORT_COLOR
# assert entity.hs_color is None
# assert entity.white_value is None
assert entity._feature.supports_white
assert entity._feature.white_value == 0x3A

# assert entity.supported_features & SUPPORT_BRIGHTNESS
# assert entity.brightness == 123
assert entity.is_on is None
assert entity._feature.supports_color
assert entity.brightness == 0xFA
assert entity.is_on is True

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
Expand Down

0 comments on commit 65eaff2

Please sign in to comment.