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/75243/head
parent
533ae85a49
commit
a5693c083f
|
@ -129,8 +129,8 @@ build.json @home-assistant/supervisor
|
|||
/homeassistant/components/binary_sensor/ @home-assistant/core
|
||||
/tests/components/binary_sensor/ @home-assistant/core
|
||||
/homeassistant/components/bizkaibus/ @UgaitzEtxebarria
|
||||
/homeassistant/components/blebox/ @bbx-a @bbx-jp @riokuu
|
||||
/tests/components/blebox/ @bbx-a @bbx-jp @riokuu
|
||||
/homeassistant/components/blebox/ @bbx-a @riokuu
|
||||
/tests/components/blebox/ @bbx-a @riokuu
|
||||
/homeassistant/components/blink/ @fronzbot
|
||||
/tests/components/blink/ @fronzbot
|
||||
/homeassistant/components/blueprint/ @home-assistant/core
|
||||
|
|
|
@ -3,13 +3,7 @@
|
|||
from homeassistant.components.cover import CoverDeviceClass
|
||||
from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.components.switch import SwitchDeviceClass
|
||||
from homeassistant.const import (
|
||||
STATE_CLOSED,
|
||||
STATE_CLOSING,
|
||||
STATE_OPEN,
|
||||
STATE_OPENING,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
|
||||
DOMAIN = "blebox"
|
||||
PRODUCT = "product"
|
||||
|
@ -30,19 +24,6 @@ BLEBOX_TO_HASS_DEVICE_CLASSES = {
|
|||
"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}
|
||||
|
||||
|
|
|
@ -9,12 +9,26 @@ from homeassistant.components.cover import (
|
|||
CoverEntityFeature,
|
||||
)
|
||||
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.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
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(
|
||||
|
|
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
|||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from blebox_uniapi.error import BadOnValueError
|
||||
import blebox_uniapi.light
|
||||
from blebox_uniapi.light import BleboxColorMode
|
||||
|
||||
|
@ -166,10 +165,10 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity):
|
|||
else:
|
||||
try:
|
||||
await self._feature.async_on(value)
|
||||
except BadOnValueError as ex:
|
||||
_LOGGER.error(
|
||||
"Turning on '%s' failed: Bad value %s (%s)", self.name, value, ex
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise ValueError(
|
||||
f"Turning on '{self.name}' failed: Bad value {value}"
|
||||
) from exc
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the light off."""
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
"name": "BleBox devices",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/blebox",
|
||||
"requirements": ["blebox_uniapi==2.0.0"],
|
||||
"codeowners": ["@bbx-a", "@bbx-jp", "@riokuu"],
|
||||
"requirements": ["blebox_uniapi==2.0.1"],
|
||||
"codeowners": ["@bbx-a", "@riokuu"],
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["blebox_uniapi"]
|
||||
}
|
||||
|
|
|
@ -402,7 +402,7 @@ bimmer_connected==0.9.6
|
|||
bizkaibus==0.1.1
|
||||
|
||||
# homeassistant.components.blebox
|
||||
blebox_uniapi==2.0.0
|
||||
blebox_uniapi==2.0.1
|
||||
|
||||
# homeassistant.components.blink
|
||||
blinkpy==0.19.0
|
||||
|
|
|
@ -314,7 +314,7 @@ bellows==0.31.1
|
|||
bimmer_connected==0.9.6
|
||||
|
||||
# homeassistant.components.blebox
|
||||
blebox_uniapi==2.0.0
|
||||
blebox_uniapi==2.0.1
|
||||
|
||||
# homeassistant.components.blink
|
||||
blinkpy==0.19.0
|
||||
|
|
|
@ -509,17 +509,18 @@ async def test_turn_on_failure(feature, hass, config, caplog):
|
|||
caplog.set_level(logging.ERROR)
|
||||
|
||||
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)
|
||||
|
||||
feature_mock.sensible_on_value = 123
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
SERVICE_TURN_ON,
|
||||
{"entity_id": entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
with pytest.raises(ValueError) as info:
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
SERVICE_TURN_ON,
|
||||
{"entity_id": entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert (
|
||||
f"Turning on '{feature_mock.full_name}' failed: Bad value 123 ()" in caplog.text
|
||||
assert f"Turning on '{feature_mock.full_name}' failed: Bad value 123" in str(
|
||||
info.value
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue