diff --git a/homeassistant/components/plaato/binary_sensor.py b/homeassistant/components/plaato/binary_sensor.py index 0ee61b7668b..27150692d6f 100644 --- a/homeassistant/components/plaato/binary_sensor.py +++ b/homeassistant/components/plaato/binary_sensor.py @@ -20,7 +20,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Set up Plaato from a config entry.""" if config_entry.data[CONF_USE_WEBHOOK]: - return False + return coordinator = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR] async_add_entities( @@ -29,11 +29,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): sensor_type, coordinator, ) - for sensor_type in coordinator.data.binary_sensors.keys() + for sensor_type in coordinator.data.binary_sensors ) - return True - class PlaatoBinarySensor(PlaatoEntity, BinarySensorEntity): """Representation of a Binary Sensor.""" diff --git a/homeassistant/components/plaato/config_flow.py b/homeassistant/components/plaato/config_flow.py index 290776f47c1..8dbf6d50fca 100644 --- a/homeassistant/components/plaato/config_flow.py +++ b/homeassistant/components/plaato/config_flow.py @@ -30,7 +30,7 @@ _LOGGER = logging.getLogger(__package__) class PlaatoConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handles a Plaato config flow.""" - VERSION = 2 + VERSION = 1 CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL def __init__(self): @@ -128,16 +128,16 @@ class PlaatoConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def _show_api_method_form( self, device_type: PlaatoDeviceType, errors: dict = None ): - data_scheme = vol.Schema({vol.Optional(CONF_TOKEN, default=""): str}) + data_schema = vol.Schema({vol.Optional(CONF_TOKEN, default=""): str}) if device_type == PlaatoDeviceType.Airlock: - data_scheme = data_scheme.extend( + data_schema = data_schema.extend( {vol.Optional(CONF_USE_WEBHOOK, default=False): bool} ) return self.async_show_form( step_id="api_method", - data_schema=data_scheme, + data_schema=data_schema, errors=errors, description_placeholders={PLACEHOLDER_DEVICE_TYPE: device_type.name}, ) diff --git a/homeassistant/components/plaato/const.py b/homeassistant/components/plaato/const.py index f50eaaac0ed..1700b803775 100644 --- a/homeassistant/components/plaato/const.py +++ b/homeassistant/components/plaato/const.py @@ -25,3 +25,12 @@ DEVICE_ID = "device_id" UNDO_UPDATE_LISTENER = "undo_update_listener" DEFAULT_SCAN_INTERVAL = 5 MIN_UPDATE_INTERVAL = timedelta(minutes=1) + +DEVICE_STATE_ATTRIBUTES = { + "beer_name": "beer_name", + "keg_date": "keg_date", + "mode": "mode", + "original_gravity": "original_gravity", + "final_gravity": "final_gravity", + "alcohol_by_volume": "alcohol_by_volume", +} diff --git a/homeassistant/components/plaato/entity.py b/homeassistant/components/plaato/entity.py index 6f72c3419a4..7cb1a77a9fb 100644 --- a/homeassistant/components/plaato/entity.py +++ b/homeassistant/components/plaato/entity.py @@ -7,6 +7,7 @@ from .const import ( DEVICE, DEVICE_ID, DEVICE_NAME, + DEVICE_STATE_ATTRIBUTES, DEVICE_TYPE, DOMAIN, SENSOR_DATA, @@ -69,8 +70,13 @@ class PlaatoEntity(entity.Entity): @property def device_state_attributes(self): """Return the state attributes of the monitored installation.""" - if self._attributes is not None: - return self._attributes + if self._attributes: + return { + attr_key: self._attributes[plaato_key] + for attr_key, plaato_key in DEVICE_STATE_ATTRIBUTES.items() + if plaato_key in self._attributes + and self._attributes[plaato_key] is not None + } @property def available(self): diff --git a/homeassistant/components/plaato/sensor.py b/homeassistant/components/plaato/sensor.py index 3f5e467f504..1dd347305e1 100644 --- a/homeassistant/components/plaato/sensor.py +++ b/homeassistant/components/plaato/sensor.py @@ -59,11 +59,9 @@ async def async_setup_entry(hass, entry, async_add_entities): coordinator = entry_data[COORDINATOR] async_add_entities( PlaatoSensor(entry_data, sensor_type, coordinator) - for sensor_type in coordinator.data.sensors.keys() + for sensor_type in coordinator.data.sensors ) - return True - class PlaatoSensor(PlaatoEntity): """Representation of a Plaato Sensor.""" diff --git a/tests/components/plaato/test_config_flow.py b/tests/components/plaato/test_config_flow.py index 10562b6aa60..7966882a977 100644 --- a/tests/components/plaato/test_config_flow.py +++ b/tests/components/plaato/test_config_flow.py @@ -95,15 +95,12 @@ async def test_show_config_form_validate_webhook(hass, webhook_id): assert result["type"] == RESULT_TYPE_FORM assert result["step_id"] == "api_method" - async def return_async_value(val): - return val - hass.config.components.add("cloud") with patch( "homeassistant.components.cloud.async_active_subscription", return_value=True ), patch( "homeassistant.components.cloud.async_create_cloudhook", - return_value=return_async_value("https://hooks.nabu.casa/ABCD"), + return_value="https://hooks.nabu.casa/ABCD", ): result = await hass.config_entries.flow.async_configure( result["flow_id"], @@ -243,21 +240,34 @@ async def test_options(hass): data={}, options={CONF_SCAN_INTERVAL: 5}, ) - config_entry.add_to_hass(hass) - with patch("homeassistant.components.plaato.async_setup_entry", return_value=True): + + with patch( + "homeassistant.components.plaato.async_setup", return_value=True + ) as mock_setup, patch( + "homeassistant.components.plaato.async_setup_entry", return_value=True + ) as mock_setup_entry: + + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + result = await hass.config_entries.options.async_init(config_entry.entry_id) - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM - assert result["step_id"] == "user" + assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result["step_id"] == "user" - result = await hass.config_entries.options.async_configure( - result["flow_id"], - user_input={CONF_SCAN_INTERVAL: 10}, - ) + result = await hass.config_entries.options.async_configure( + result["flow_id"], + user_input={CONF_SCAN_INTERVAL: 10}, + ) - assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY - assert result["data"][CONF_SCAN_INTERVAL] == 10 + await hass.async_block_till_done() + + assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY + assert result["data"][CONF_SCAN_INTERVAL] == 10 + + assert len(mock_setup.mock_calls) == 1 + assert len(mock_setup_entry.mock_calls) == 1 async def test_options_webhook(hass, webhook_id): @@ -268,19 +278,32 @@ async def test_options_webhook(hass, webhook_id): data={CONF_USE_WEBHOOK: True, CONF_WEBHOOK_ID: None}, options={CONF_SCAN_INTERVAL: 5}, ) - config_entry.add_to_hass(hass) - with patch("homeassistant.components.plaato.async_setup_entry", return_value=True): + + with patch( + "homeassistant.components.plaato.async_setup", return_value=True + ) as mock_setup, patch( + "homeassistant.components.plaato.async_setup_entry", return_value=True + ) as mock_setup_entry: + + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + result = await hass.config_entries.options.async_init(config_entry.entry_id) - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM - assert result["step_id"] == "webhook" - assert result["description_placeholders"] == {"webhook_url": ""} + assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result["step_id"] == "webhook" + assert result["description_placeholders"] == {"webhook_url": ""} - result = await hass.config_entries.options.async_configure( - result["flow_id"], - user_input={CONF_WEBHOOK_ID: WEBHOOK_ID}, - ) + result = await hass.config_entries.options.async_configure( + result["flow_id"], + user_input={CONF_WEBHOOK_ID: WEBHOOK_ID}, + ) - assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY - assert result["data"][CONF_WEBHOOK_ID] == CONF_WEBHOOK_ID + await hass.async_block_till_done() + + assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY + assert result["data"][CONF_WEBHOOK_ID] == CONF_WEBHOOK_ID + + assert len(mock_setup.mock_calls) == 1 + assert len(mock_setup_entry.mock_calls) == 1