Address Blebox uniapi review sidenotes (#74298)
* Changes accordingly to sidenotes given by @MartinHjelmare in pull #73834. * Mini version bump according to notes in pull #73834. * Error message fix, test adjustment.pull/74360/head
parent
a4c6cd2fbe
commit
e7e940afa5
|
@ -131,8 +131,8 @@ build.json @home-assistant/supervisor
|
||||||
/homeassistant/components/binary_sensor/ @home-assistant/core
|
/homeassistant/components/binary_sensor/ @home-assistant/core
|
||||||
/tests/components/binary_sensor/ @home-assistant/core
|
/tests/components/binary_sensor/ @home-assistant/core
|
||||||
/homeassistant/components/bizkaibus/ @UgaitzEtxebarria
|
/homeassistant/components/bizkaibus/ @UgaitzEtxebarria
|
||||||
/homeassistant/components/blebox/ @bbx-a @bbx-jp @riokuu
|
/homeassistant/components/blebox/ @bbx-a @riokuu
|
||||||
/tests/components/blebox/ @bbx-a @bbx-jp @riokuu
|
/tests/components/blebox/ @bbx-a @riokuu
|
||||||
/homeassistant/components/blink/ @fronzbot
|
/homeassistant/components/blink/ @fronzbot
|
||||||
/tests/components/blink/ @fronzbot
|
/tests/components/blink/ @fronzbot
|
||||||
/homeassistant/components/blueprint/ @home-assistant/core
|
/homeassistant/components/blueprint/ @home-assistant/core
|
||||||
|
|
|
@ -3,13 +3,7 @@
|
||||||
from homeassistant.components.cover import CoverDeviceClass
|
from homeassistant.components.cover import CoverDeviceClass
|
||||||
from homeassistant.components.sensor import SensorDeviceClass
|
from homeassistant.components.sensor import SensorDeviceClass
|
||||||
from homeassistant.components.switch import SwitchDeviceClass
|
from homeassistant.components.switch import SwitchDeviceClass
|
||||||
from homeassistant.const import (
|
from homeassistant.const import TEMP_CELSIUS
|
||||||
STATE_CLOSED,
|
|
||||||
STATE_CLOSING,
|
|
||||||
STATE_OPEN,
|
|
||||||
STATE_OPENING,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
)
|
|
||||||
|
|
||||||
DOMAIN = "blebox"
|
DOMAIN = "blebox"
|
||||||
PRODUCT = "product"
|
PRODUCT = "product"
|
||||||
|
@ -30,19 +24,6 @@ BLEBOX_TO_HASS_DEVICE_CLASSES = {
|
||||||
"temperature": SensorDeviceClass.TEMPERATURE,
|
"temperature": SensorDeviceClass.TEMPERATURE,
|
||||||
}
|
}
|
||||||
|
|
||||||
BLEBOX_TO_HASS_COVER_STATES = {
|
|
||||||
None: None,
|
|
||||||
0: STATE_CLOSING, # moving down
|
|
||||||
1: STATE_OPENING, # moving up
|
|
||||||
2: STATE_OPEN, # manually stopped
|
|
||||||
3: STATE_CLOSED, # lower limit
|
|
||||||
4: STATE_OPEN, # upper limit / open
|
|
||||||
# gateController
|
|
||||||
5: STATE_OPEN, # overload
|
|
||||||
6: STATE_OPEN, # motor failure
|
|
||||||
# 7 is not used
|
|
||||||
8: STATE_OPEN, # safety stop
|
|
||||||
}
|
|
||||||
|
|
||||||
BLEBOX_TO_UNIT_MAP = {"celsius": TEMP_CELSIUS}
|
BLEBOX_TO_UNIT_MAP = {"celsius": TEMP_CELSIUS}
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,26 @@ from homeassistant.components.cover import (
|
||||||
CoverEntityFeature,
|
CoverEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPENING
|
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import BleBoxEntity, create_blebox_entities
|
from . import BleBoxEntity, create_blebox_entities
|
||||||
from .const import BLEBOX_TO_HASS_COVER_STATES, BLEBOX_TO_HASS_DEVICE_CLASSES
|
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES
|
||||||
|
|
||||||
|
BLEBOX_TO_HASS_COVER_STATES = {
|
||||||
|
None: None,
|
||||||
|
0: STATE_CLOSING, # moving down
|
||||||
|
1: STATE_OPENING, # moving up
|
||||||
|
2: STATE_OPEN, # manually stopped
|
||||||
|
3: STATE_CLOSED, # lower limit
|
||||||
|
4: STATE_OPEN, # upper limit / open
|
||||||
|
# gateController
|
||||||
|
5: STATE_OPEN, # overload
|
||||||
|
6: STATE_OPEN, # motor failure
|
||||||
|
# 7 is not used
|
||||||
|
8: STATE_OPEN, # safety stop
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from blebox_uniapi.error import BadOnValueError
|
|
||||||
import blebox_uniapi.light
|
import blebox_uniapi.light
|
||||||
from blebox_uniapi.light import BleboxColorMode
|
from blebox_uniapi.light import BleboxColorMode
|
||||||
|
|
||||||
|
@ -166,10 +165,10 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await self._feature.async_on(value)
|
await self._feature.async_on(value)
|
||||||
except BadOnValueError as ex:
|
except ValueError as exc:
|
||||||
_LOGGER.error(
|
raise ValueError(
|
||||||
"Turning on '%s' failed: Bad value %s (%s)", self.name, value, ex
|
f"Turning on '{self.name}' failed: Bad value {value}"
|
||||||
)
|
) from exc
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
"name": "BleBox devices",
|
"name": "BleBox devices",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/blebox",
|
"documentation": "https://www.home-assistant.io/integrations/blebox",
|
||||||
"requirements": ["blebox_uniapi==2.0.0"],
|
"requirements": ["blebox_uniapi==2.0.1"],
|
||||||
"codeowners": ["@bbx-a", "@bbx-jp", "@riokuu"],
|
"codeowners": ["@bbx-a", "@riokuu"],
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["blebox_uniapi"]
|
"loggers": ["blebox_uniapi"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,7 +402,7 @@ bimmer_connected==0.9.6
|
||||||
bizkaibus==0.1.1
|
bizkaibus==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.blebox
|
# homeassistant.components.blebox
|
||||||
blebox_uniapi==2.0.0
|
blebox_uniapi==2.0.1
|
||||||
|
|
||||||
# homeassistant.components.blink
|
# homeassistant.components.blink
|
||||||
blinkpy==0.19.0
|
blinkpy==0.19.0
|
||||||
|
|
|
@ -317,7 +317,7 @@ bellows==0.31.0
|
||||||
bimmer_connected==0.9.6
|
bimmer_connected==0.9.6
|
||||||
|
|
||||||
# homeassistant.components.blebox
|
# homeassistant.components.blebox
|
||||||
blebox_uniapi==2.0.0
|
blebox_uniapi==2.0.1
|
||||||
|
|
||||||
# homeassistant.components.blink
|
# homeassistant.components.blink
|
||||||
blinkpy==0.19.0
|
blinkpy==0.19.0
|
||||||
|
|
|
@ -509,17 +509,18 @@ async def test_turn_on_failure(feature, hass, config, caplog):
|
||||||
caplog.set_level(logging.ERROR)
|
caplog.set_level(logging.ERROR)
|
||||||
|
|
||||||
feature_mock, entity_id = feature
|
feature_mock, entity_id = feature
|
||||||
feature_mock.async_on = AsyncMock(side_effect=blebox_uniapi.error.BadOnValueError)
|
feature_mock.async_on = AsyncMock(side_effect=ValueError)
|
||||||
await async_setup_entity(hass, config, entity_id)
|
await async_setup_entity(hass, config, entity_id)
|
||||||
|
|
||||||
feature_mock.sensible_on_value = 123
|
feature_mock.sensible_on_value = 123
|
||||||
await hass.services.async_call(
|
with pytest.raises(ValueError) as info:
|
||||||
"light",
|
await hass.services.async_call(
|
||||||
SERVICE_TURN_ON,
|
"light",
|
||||||
{"entity_id": entity_id},
|
SERVICE_TURN_ON,
|
||||||
blocking=True,
|
{"entity_id": entity_id},
|
||||||
)
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
assert (
|
assert f"Turning on '{feature_mock.full_name}' failed: Bad value 123" in str(
|
||||||
f"Turning on '{feature_mock.full_name}' failed: Bad value 123 ()" in caplog.text
|
info.value
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue