Skip to content

Commit

Permalink
expose device info
Browse files Browse the repository at this point in the history
  • Loading branch information
gadgetmobile committed Mar 30, 2020
1 parent 4ae37de commit 72fa287
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 0 deletions.
9 changes: 9 additions & 0 deletions blebox_uniapi/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, api_session, info):
self._api_version = level
self._version = version
self._outdated = outdated
self._model = config.get("model", type)

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

Expand Down Expand Up @@ -190,6 +191,14 @@ def outdated(self):
# TODO: fixme
return self._outdated

@property
def brand(self):
return "BleBox"

@property
def model(self):
return self._model

# TODO: report timestamp of last measurement (if possible)

async def async_update_data(self):
Expand Down
4 changes: 4 additions & 0 deletions blebox_uniapi/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def full_name(self):
def device_class(self):
return self._device_class

@property
def product(self):
return self._product

# TODO: (cleanup) move to product/box ?
def raw_value(self, name):
product = self._product
Expand Down
1 change: 1 addition & 0 deletions blebox_uniapi/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Products:
],
},
"switchBox0": {
"model": "switchBox",
"api_path": "/api/relay/state",
"api_level_range": [20180604, 20190808],
"api": {
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,14 @@ async def async_update(self):
def outdated(self):
"""Return the temperature."""
return self._feature._product.outdated

@property
def device_info(self):
product = self._feature.product
return {
"name": product.name,
"mac": product.unique_id,
"manufacturer": product.brand,
"model": product.model,
"sw_version": product.firmware_version,
}
9 changes: 9 additions & 0 deletions tests/test_air_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ async def test_init(self, aioclient_mock):
assert entity.particulate_matter_2_5 is None
assert entity.particulate_matter_10 is None

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My air 1"
assert entity.device_info["mac"] == "1afe34db9437"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "airSensor"
assert entity.device_info["sw_version"] == "0.973"

async def test_update(self, aioclient_mock):
"""Test air quality sensor state after update."""

Expand Down
2 changes: 2 additions & 0 deletions tests/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ async def test_properties(mock_session, data):
assert "foobar" == box.name
assert None is box.last_data
assert "airSensor" == box.type
assert "airSensor" == box.model
assert "abcd1234ef" == box.unique_id
assert "1.23" == box.firmware_version
assert "4.56" == box.hardware_version
assert "BleBox" == box.brand
assert 20180403 == box.api_version
assert (1, 0, 0) == box.version
assert True is box.outdated
Expand Down
9 changes: 9 additions & 0 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ async def test_init(self, aioclient_mock):
assert entity.max_temp is None
assert entity.min_temp is None

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My SaunaBox"
assert entity.device_info["mac"] == "1afe34db9437"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "saunaBox"
assert entity.device_info["sw_version"] == "0.176"

async def test_update(self, aioclient_mock):
"""Test updating."""

Expand Down
27 changes: 27 additions & 0 deletions tests/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ async def test_init(self, aioclient_mock):

self.assert_state(entity, None)

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My shutter 1"
assert entity.device_info["mac"] == "2bee34e750b8"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "shutterBox"
assert entity.device_info["sw_version"] == "0.147"

async def test_update(self, aioclient_mock):
"""Test cover updating."""

Expand Down Expand Up @@ -375,6 +384,15 @@ async def test_init(self, aioclient_mock):
assert entity.current_cover_position is None
self.assert_state(entity, None)

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My gate 1"
assert entity.device_info["mac"] == "1afe34db9437"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "gateBox"
assert entity.device_info["sw_version"] == "0.176"

async def test_update(self, aioclient_mock):
"""Test cover updating."""

Expand Down Expand Up @@ -554,6 +572,15 @@ async def test_init(self, aioclient_mock):
assert entity.current_cover_position is None
self.assert_state(entity, None)

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My gate controller 1"
assert entity.device_info["mac"] == "0ff2ffaafe30db9437"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "gateController"
assert entity.device_info["sw_version"] == "1.390"

async def test_update(self, aioclient_mock):
"""Test cover updating."""

Expand Down
27 changes: 27 additions & 0 deletions tests/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ async def test_init(self, aioclient_mock):

assert entity.is_on is None

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My dimmer"
assert entity.device_info["mac"] == "1afe34e750b8"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "dimmerBox"
assert entity.device_info["sw_version"] == "0.247"

async def test_update(self, aioclient_mock):
"""Test light updating."""

Expand Down Expand Up @@ -431,6 +440,15 @@ async def test_init(self, aioclient_mock):

assert entity.is_on is None

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My wLightBoxS"
assert entity.device_info["mac"] == "1afe34e750b8"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "wLightBoxS"
assert entity.device_info["sw_version"] == "0.924"

async def test_update(self, aioclient_mock):
"""Test light updating."""

Expand Down Expand Up @@ -638,6 +656,15 @@ async def test_init(self, aioclient_mock):
# assert entity.brightness == 123
assert entity.is_on is None

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My light 1"
assert entity.device_info["mac"] == "1afe34e750b8"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "wLightBox"
assert entity.device_info["sw_version"] == "0.993"

async def test_update(self, aioclient_mock):
"""Test light updating."""

Expand Down
9 changes: 9 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ async def test_init(self, aioclient_mock):
assert entity.state is None
assert entity.outdated is False

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My tempSensor"
assert entity.device_info["mac"] == "1afe34db9437"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "tempSensor"
assert entity.device_info["sw_version"] == "0.176"

async def test_update(self, aioclient_mock):
"""Test sensor update."""

Expand Down
27 changes: 27 additions & 0 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ async def test_init(self, aioclient_mock):

assert entity.is_on is None

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My switchBox"
assert entity.device_info["mac"] == "1afe34e750b8"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "switchBox"
assert entity.device_info["sw_version"] == "0.247"

async def test_update_when_off(self, aioclient_mock):
"""Test switch updating when off."""

Expand Down Expand Up @@ -223,6 +232,15 @@ async def test_init(self, aioclient_mock):

assert entity.is_on is None

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My switchBox"
assert entity.device_info["mac"] == "1afe34e750b8"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "switchBox"
assert entity.device_info["sw_version"] == "0.247"

async def test_update_when_off(self, aioclient_mock):
"""Test switch updating when off."""

Expand Down Expand Up @@ -357,6 +375,15 @@ async def test_init(self, aioclient_mock):
assert entity.device_class == DEVICE_CLASS_SWITCH
assert entity.is_on is None

async def test_device_info(self, aioclient_mock):
await self.allow_get_info(aioclient_mock, self.DEVICE_INFO)
entity = (await self.async_entities(aioclient_mock))[0]
assert entity.device_info["name"] == "My switchBoxD"
assert entity.device_info["mac"] == "1afe34e750b8"
assert entity.device_info["manufacturer"] == "BleBox"
assert entity.device_info["model"] == "switchBoxD"
assert entity.device_info["sw_version"] == "0.200"

async def test_update_when_off(self, aioclient_mock):
"""Test switch updating when off."""

Expand Down

0 comments on commit 72fa287

Please sign in to comment.