Improve microBees code quality (#114939)

microBees code quality
This commit is contained in:
Federico D'Amico 2024-04-08 05:35:46 +02:00 committed by GitHub
parent 3daecc7a31
commit 111ffdd77e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 20 deletions

View File

@ -19,6 +19,8 @@ from .const import DOMAIN
from .coordinator import MicroBeesUpdateCoordinator
from .entity import MicroBeesEntity
COVER_IDS = {47: "roller_shutter"}
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
@ -32,11 +34,17 @@ async def async_setup_entry(
MBCover(
coordinator,
bee_id,
next(filter(lambda x: x.deviceID == 551, bee.actuators)).id,
next(filter(lambda x: x.deviceID == 552, bee.actuators)).id,
next(
(actuator.id for actuator in bee.actuators if actuator.deviceID == 551),
None,
),
next(
(actuator.id for actuator in bee.actuators if actuator.deviceID == 552),
None,
),
)
for bee_id, bee in coordinator.data.bees.items()
if bee.productID == 47
if bee.productID in COVER_IDS
)

View File

@ -60,19 +60,19 @@ class MBLight(MicroBeesActuatorEntity, LightEntity):
sendCommand = await self.coordinator.microbees.sendCommand(
self.actuator_id, 1, color=self._attr_rgbw_color
)
if sendCommand:
self.actuator.value = True
self.async_write_ha_state()
else:
if not sendCommand:
raise HomeAssistantError(f"Failed to turn on {self.name}")
self.actuator.value = True
self.async_write_ha_state()
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the light."""
sendCommand = await self.coordinator.microbees.sendCommand(
self.actuator_id, 0, color=self._attr_rgbw_color
)
if sendCommand:
self.actuator.value = False
self.async_write_ha_state()
else:
if not sendCommand:
raise HomeAssistantError(f"Failed to turn off {self.name}")
self.actuator.value = False
self.async_write_ha_state()

View File

@ -19,7 +19,10 @@
"missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]",
"authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]",
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]",
"user_rejected_authorize": "[%key:common::config_flow::abort::oauth2_user_rejected_authorize%]"
"user_rejected_authorize": "[%key:common::config_flow::abort::oauth2_user_rejected_authorize%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]",
"wrong_account": "You can only reauthenticate this entry with the same microBees account."
},
"create_entry": {
"default": "[%key:common::config_flow::create_entry::authenticated%]"

View File

@ -56,17 +56,17 @@ class MBSwitch(MicroBeesActuatorEntity, SwitchEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the switch."""
send_command = await self.coordinator.microbees.sendCommand(self.actuator_id, 1)
if send_command:
self.actuator.value = True
self.async_write_ha_state()
else:
if not send_command:
raise HomeAssistantError(f"Failed to turn on {self.name}")
self.actuator.value = True
self.async_write_ha_state()
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the switch."""
send_command = await self.coordinator.microbees.sendCommand(self.actuator_id, 0)
if send_command:
self.actuator.value = False
self.async_write_ha_state()
else:
if not send_command:
raise HomeAssistantError(f"Failed to turn off {self.name}")
self.actuator.value = False
self.async_write_ha_state()