Bump pykmtronic to 0.3.0 ()

pull/49220/head
Diogo Gomes 2021-04-14 17:11:51 +01:00 committed by GitHub
parent 9d4ad1821e
commit e4a7260384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 13 deletions

View File

@ -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(

View File

@ -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"]
}

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -17,6 +17,10 @@ async def test_relay_on_off(hass, aioclient_mock):
"http://1.1.1.1/status.xml",
text="<response><relay0>0</relay0><relay1>0</relay1></response>",
)
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."""