Skip to content

Commit

Permalink
Update controller.py
Browse files Browse the repository at this point in the history
Introduced the ZHA to support the communication using the Quirks
  • Loading branch information
davidrpfarinha committed Nov 30, 2023
1 parent b0837e0 commit c839bde
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions custom_components/smartir/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
MQTT_CONTROLLER = 'MQTT'
LOOKIN_CONTROLLER = 'LOOKin'
ESPHOME_CONTROLLER = 'ESPHome'
ZHA_CONTROLLER = 'ZHA'

ENC_BASE64 = 'Base64'
ENC_HEX = 'Hex'
Expand All @@ -26,6 +27,7 @@
MQTT_COMMANDS_ENCODING = [ENC_RAW]
LOOKIN_COMMANDS_ENCODING = [ENC_PRONTO, ENC_RAW]
ESPHOME_COMMANDS_ENCODING = [ENC_RAW]
ZHA_COMMANDS_ENCODING = [ENC_RAW]


def get_controller(hass, controller, encoding, controller_data, delay):
Expand All @@ -35,7 +37,8 @@ def get_controller(hass, controller, encoding, controller_data, delay):
XIAOMI_CONTROLLER: XiaomiController,
MQTT_CONTROLLER: MQTTController,
LOOKIN_CONTROLLER: LookinController,
ESPHOME_CONTROLLER: ESPHomeController
ESPHOME_CONTROLLER: ESPHomeController,
ZHA_CONTROLLER: ZHAController
}
try:
return controllers[controller](hass, controller, encoding, controller_data, delay)
Expand Down Expand Up @@ -131,6 +134,29 @@ async def send(self, command):
await self.hass.services.async_call(
'remote', 'send_command', service_data)

class ZHAController(AbstractController):
"""Controls a Moes device."""

def check_encoding(self, encoding):
"""Check if the encoding is supported by the controller."""
if encoding not in ZHA_COMMANDS_ENCODING:
raise Exception("The encoding is not supported "
"by the ZHA controller.")

async def send(self, command):
"""Send a command."""
service_data = {
'cluster_type': 'in',
'endpoint_id': '1',
'command': '2',
'ieee': self._controller_data,
'command_type': 'server',
'params': { 'code': command},
'cluster_id': '57348'
}

await self.hass.services.async_call(
'zha', 'issue_zigbee_cluster_command', service_data)

class MQTTController(AbstractController):
"""Controls a MQTT device."""
Expand Down Expand Up @@ -183,4 +209,4 @@ async def send(self, command):
service_data = {'command': json.loads(command)}

await self.hass.services.async_call(
'esphome', self._controller_data, service_data)
'esphome', self._controller_data, service_data)

0 comments on commit c839bde

Please sign in to comment.