Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejgray committed Feb 24, 2024
1 parent 8d23a28 commit eb68352
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ovos_PHAL_plugin_homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def __init__(self, bus=None, config=None):

def handle_check_connected(self, message: Message):
"""Return a bus response indicating whether the plugin is connected to a Home Assistant instance."""
self.bus.emit(message.response(data={"connected": self.instance_available}))
self.log.info(f"Checking connection to Home Assistant instance: {self.instance_available}")
self.bus.emit(
message.response(data={"connected": self.instance_available}, context=message.context)
)

def get_brightness_increment(self) -> int:
""" Get the brightness increment from the config
Expand Down
28 changes: 28 additions & 0 deletions test/unittests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,31 @@ def test_brightness_increment_decrease(self):
mock_call.assert_called_with("turn_on", {"brightness_step_pct": -20})
fake_bulb.decrease_brightness(50)
mock_call.assert_called_with("turn_on", {"brightness_step_pct": -50})

def test_handle_check_not_connected(self):
responded = False
def handle_response(message):
nonlocal responded
self.plugin.log.info(message.data)
responded = True
self.assertFalse(self.plugin.instance_available)
self.assertFalse(message.data["connected"])
self.plugin.bus.run_forever()
self.plugin.bus.once("ovos.phal.plugin.homeassistant.connected.response", handle_response)
fake_message = FakeMessage("ovos.phal.plugin.homeassistant.connected", {}, None)
self.plugin.handle_check_connected(fake_message)
self.assertTrue(responded)

def test_handle_check_connected(self):
responded = False
def handle_response(message):
nonlocal responded
self.plugin.log.info(message.data)
responded = True
self.assertTrue(message.data["connected"])
self.plugin.bus.run_forever()
self.plugin.bus.once("ovos.phal.plugin.homeassistant.connected.response", handle_response)
fake_message = FakeMessage("ovos.phal.plugin.homeassistant.connected", {}, None)
self.plugin.instance_available = True
self.plugin.handle_check_connected(fake_message)
self.assertTrue(responded)

0 comments on commit eb68352

Please sign in to comment.