diff --git a/homeassistant/components/kmtronic/__init__.py b/homeassistant/components/kmtronic/__init__.py index 241e65fbe7f..d311940f4bc 100644 --- a/homeassistant/components/kmtronic/__init__.py +++ b/homeassistant/components/kmtronic/__init__.py @@ -48,10 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): await hub.async_update_relays() except aiohttp.client_exceptions.ClientResponseError as err: raise UpdateFailed(f"Wrong credentials: {err}") from err - except ( - asyncio.TimeoutError, - aiohttp.client_exceptions.ClientConnectorError, - ) as err: + except aiohttp.client_exceptions.ClientConnectorError as err: raise UpdateFailed(f"Error communicating with API: {err}") from err coordinator = DataUpdateCoordinator( diff --git a/homeassistant/components/kmtronic/manifest.json b/homeassistant/components/kmtronic/manifest.json index 27e9f953eb7..b7bccbe6f2d 100644 --- a/homeassistant/components/kmtronic/manifest.json +++ b/homeassistant/components/kmtronic/manifest.json @@ -3,6 +3,6 @@ "name": "KMtronic", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/kmtronic", - "requirements": ["pykmtronic==0.0.3"], + "requirements": ["pykmtronic==0.3.0"], "codeowners": ["@dgomes"] } diff --git a/homeassistant/components/kmtronic/switch.py b/homeassistant/components/kmtronic/switch.py index d37cd54ce1a..31b0fcb54c1 100644 --- a/homeassistant/components/kmtronic/switch.py +++ b/homeassistant/components/kmtronic/switch.py @@ -45,21 +45,26 @@ class KMtronicSwitch(CoordinatorEntity, SwitchEntity): def is_on(self): """Return entity state.""" if self._reverse: - return not self._relay.is_on - return self._relay.is_on + return not self._relay.is_energised + return self._relay.is_energised async def async_turn_on(self, **kwargs) -> None: """Turn the switch on.""" if self._reverse: - await self._relay.turn_off() + await self._relay.de_energise() else: - await self._relay.turn_on() + await self._relay.energise() self.async_write_ha_state() async def async_turn_off(self, **kwargs) -> None: """Turn the switch off.""" if self._reverse: - await self._relay.turn_on() + await self._relay.energise() else: - await self._relay.turn_off() + await self._relay.de_energise() + self.async_write_ha_state() + + async def async_toggle(self, **kwargs) -> None: + """Toggle the switch.""" + await self._relay.toggle() self.async_write_ha_state() diff --git a/requirements_all.txt b/requirements_all.txt index 58497938086..ca2705f5bf6 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1485,7 +1485,7 @@ pyitachip2ir==0.0.7 pykira==0.1.1 # homeassistant.components.kmtronic -pykmtronic==0.0.3 +pykmtronic==0.3.0 # homeassistant.components.kodi pykodi==0.2.5 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 9d5da4349ad..9a24bc0925d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -808,7 +808,7 @@ pyisy==2.1.1 pykira==0.1.1 # homeassistant.components.kmtronic -pykmtronic==0.0.3 +pykmtronic==0.3.0 # homeassistant.components.kodi pykodi==0.2.5 diff --git a/tests/components/kmtronic/test_switch.py b/tests/components/kmtronic/test_switch.py index df8ecda2c2e..70a298878bd 100644 --- a/tests/components/kmtronic/test_switch.py +++ b/tests/components/kmtronic/test_switch.py @@ -17,6 +17,10 @@ async def test_relay_on_off(hass, aioclient_mock): "http://1.1.1.1/status.xml", text="00", ) + aioclient_mock.get( + "http://1.1.1.1/relays.cgi?relay=1", + text="OK", + ) MockConfigEntry( domain=DOMAIN, data={"host": "1.1.1.1", "username": "foo", "password": "bar"} @@ -55,6 +59,20 @@ async def test_relay_on_off(hass, aioclient_mock): state = hass.states.get("switch.relay1") assert state.state == "off" + # Mocks the response for turning a relay1 on + aioclient_mock.get( + "http://1.1.1.1/FF0101", + text="", + ) + + await hass.services.async_call( + "switch", "toggle", {"entity_id": "switch.relay1"}, blocking=True + ) + + await hass.async_block_till_done() + state = hass.states.get("switch.relay1") + assert state.state == "on" + async def test_update(hass, aioclient_mock): """Tests switch refreshes status periodically."""