Fix review requests for BleBox support from #35370 (#35786)

* fix review requests from #35370

* fix pylint W0621 (redefined-outer-name)
pull/35793/head
gadgetmobile 2020-05-18 22:30:15 +02:00 committed by GitHub
parent 8258fa515d
commit 93fddbed2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 24 deletions

View File

@ -74,7 +74,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
@callback
def create_blebox_entities(hass, config_entry, async_add, entity_klass, entity_type):
def create_blebox_entities(
hass, config_entry, async_add_entities, entity_klass, entity_type
):
"""Create entities from a BleBox product's features."""
product = hass.data[DOMAIN][config_entry.entry_id][PRODUCT]
@ -84,7 +86,7 @@ def create_blebox_entities(hass, config_entry, async_add, entity_klass, entity_t
for feature in product.features[entity_type]:
entities.append(entity_klass(feature))
async_add(entities, True)
async_add_entities(entities, True)
class BleBoxEntity(Entity):

View File

@ -5,10 +5,10 @@ from homeassistant.components.air_quality import AirQualityEntity
from . import BleBoxEntity, create_blebox_entities
async def async_setup_entry(hass, config_entry, async_add):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a BleBox air quality entity."""
create_blebox_entities(
hass, config_entry, async_add, BleBoxAirQualityEntity, "air_qualities"
hass, config_entry, async_add_entities, BleBoxAirQualityEntity, "air_qualities"
)

View File

@ -16,10 +16,12 @@ from . import BleBoxEntity, create_blebox_entities
from .const import BLEBOX_TO_HASS_COVER_STATES, BLEBOX_TO_HASS_DEVICE_CLASSES
async def async_setup_entry(hass, config_entry, async_add):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a BleBox entry."""
create_blebox_entities(hass, config_entry, async_add, BleBoxCoverEntity, "covers")
create_blebox_entities(
hass, config_entry, async_add_entities, BleBoxCoverEntity, "covers"
)
class BleBoxCoverEntity(BleBoxEntity, CoverEntity):

View File

@ -24,10 +24,12 @@ from . import BleBoxEntity, create_blebox_entities
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a BleBox entry."""
create_blebox_entities(hass, config_entry, async_add, BleBoxLightEntity, "lights")
create_blebox_entities(
hass, config_entry, async_add_entities, BleBoxLightEntity, "lights"
)
class BleBoxLightEntity(BleBoxEntity, LightEntity):
@ -69,9 +71,9 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity):
async def async_turn_on(self, **kwargs):
"""Turn the light on."""
white = kwargs.get(ATTR_WHITE_VALUE, None)
hs_color = kwargs.get(ATTR_HS_COLOR, None)
brightness = kwargs.get(ATTR_BRIGHTNESS, None)
white = kwargs.get(ATTR_WHITE_VALUE)
hs_color = kwargs.get(ATTR_HS_COLOR)
brightness = kwargs.get(ATTR_BRIGHTNESS)
feature = self._feature
value = feature.sensible_on_value
@ -90,7 +92,7 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity):
await self._feature.async_on(value)
except BadOnValueError as ex:
_LOGGER.error(
"turning on '%s' failed: Bad value %s (%s)", self.name, value, ex
"Turning on '%s' failed: Bad value %s (%s)", self.name, value, ex
)
async def async_turn_off(self, **kwargs):

View File

@ -6,10 +6,12 @@ from . import BleBoxEntity, create_blebox_entities
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES, BLEBOX_TO_UNIT_MAP
async def async_setup_entry(hass, config_entry, async_add):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a BleBox entry."""
create_blebox_entities(hass, config_entry, async_add, BleBoxSensorEntity, "sensors")
create_blebox_entities(
hass, config_entry, async_add_entities, BleBoxSensorEntity, "sensors"
)
class BleBoxSensorEntity(BleBoxEntity, Entity):

View File

@ -5,10 +5,10 @@ from . import BleBoxEntity, create_blebox_entities
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES
async def async_setup_entry(hass, config_entry, async_add):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a BleBox switch entity."""
create_blebox_entities(
hass, config_entry, async_add, BleBoxSwitchEntity, "switches"
hass, config_entry, async_add_entities, BleBoxSwitchEntity, "switches"
)

View File

@ -71,7 +71,7 @@ def config_fixture():
@pytest.fixture(name="feature")
def feature(request):
def feature_fixture(request):
"""Return an entity wrapper from given fixture name."""
return request.getfixturevalue(request.param)

View File

@ -36,14 +36,14 @@ def create_valid_feature_mock(path="homeassistant.components.blebox.Products"):
return feature
@pytest.fixture
def valid_feature_mock():
@pytest.fixture(name="valid_feature_mock")
def valid_feature_mock_fixture():
"""Return a valid, complete BleBox feature mock."""
return create_valid_feature_mock()
@pytest.fixture
def flow_feature_mock():
@pytest.fixture(name="flow_feature_mock")
def flow_feature_mock_fixture():
"""Return a mocked user flow feature."""
return create_valid_feature_mock(
"homeassistant.components.blebox.config_flow.Products"
@ -74,8 +74,8 @@ async def test_flow_works(hass, valid_feature_mock, flow_feature_mock):
}
@pytest.fixture
def product_class_mock():
@pytest.fixture(name="product_class_mock")
def product_class_mock_fixture():
"""Return a mocked feature."""
path = "homeassistant.components.blebox.config_flow.Products"
patcher = patch(path, DEFAULT, blebox_uniapi.products.Products, True, True)

View File

@ -593,5 +593,5 @@ async def test_turn_on_failure(feature, hass, config, caplog):
)
assert (
f"turning on '{feature_mock.full_name}' failed: Bad value 123 ()" in caplog.text
f"Turning on '{feature_mock.full_name}' failed: Bad value 123 ()" in caplog.text
)