diff --git a/README.md b/README.md index 5b4a37f..b406ca7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Ferroamp MQTT support sends updates to these topics: * extapi/data/esm (interval 60s) ## Prerequisites -- Home assistant `2021.12` +- Home assistant `2022.12.x` - Enable Ferroamp MQTT by contacting [Ferroamp Support](https://ferroamp.com/sv/kontakt/) to get the username and password for your Energy MQTT broker. - Enable MQTT in Home assistant and set the broker to your Ferroamp Energy IP and configure it with your username and password received from Ferroamp (or setup a bridge-connection if you already have an MQTT-server, see the `Configuring Bridges`-section in the [Mosquitto documentation](https://mosquitto.org/man/mosquitto-conf-5.html)). diff --git a/custom_components/ferroamp/__init__.py b/custom_components/ferroamp/__init__.py index 9414c64..6b966da 100644 --- a/custom_components/ferroamp/__init__.py +++ b/custom_components/ferroamp/__init__.py @@ -52,6 +52,15 @@ async def async_unload_entry(hass, entry): async def async_setup(hass: core.HomeAssistant, config: dict) -> bool: + # Make sure MQTT is available and the entry is loaded + if not hass.config_entries.async_entries( + mqtt.DOMAIN + ) or not await hass.config_entries.async_wait_component( + hass.config_entries.async_entries(mqtt.DOMAIN)[0] + ): + _LOGGER.error("MQTT integration is not available") + return False + _LOGGER.debug("Setting up ferroamp battery service calls") hass.data.setdefault(DOMAIN, {}) device_registry = dr.async_get(hass) diff --git a/hacs.json b/hacs.json index 6885db7..79a8fe9 100644 --- a/hacs.json +++ b/hacs.json @@ -1,4 +1,4 @@ { "name": "Ferroamp Sensors", - "homeassistant": "2022.8.0b0" + "homeassistant": "2022.12.0b0" } diff --git a/requirements.test.txt b/requirements.test.txt index 1d895b5..0ea09db 100644 --- a/requirements.test.txt +++ b/requirements.test.txt @@ -1,5 +1,5 @@ # Strictly for tests -pytest-homeassistant-custom-component==0.10.2 +pytest-homeassistant-custom-component==0.12.27 janus==1.0.0 # From our manifest.json for our custom component aiohttp_cors==0.7.0 diff --git a/tests/test_init.py b/tests/test_init.py index 38cc74b..8f38ac6 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -9,7 +9,7 @@ from homeassistant.helpers import device_registry from pytest_homeassistant_custom_component.common import async_fire_mqtt_message, MockConfigEntry -from custom_components.ferroamp import ATTR_POWER, ATTR_TARGET +from custom_components.ferroamp import ATTR_POWER, ATTR_TARGET, async_setup from custom_components.ferroamp.const import DOMAIN, CONF_INTERVAL, DATA_DEVICES, DATA_PREFIXES, DATA_LISTENERS @@ -32,6 +32,12 @@ def create_config(name="Ferroamp", prefix="extapi", unique_id="ferroamp"): ) +async def test_no_mqtt(hass, caplog): + result = await async_setup(hass, {}) + assert not result + assert "MQTT integration is not available" in caplog.text + + async def test_unload(hass, mqtt_mock): config_entry = create_config() config_entry.add_to_hass(hass)