Skip to content

Commit

Permalink
New broadlink service
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilis-panos committed Apr 21, 2019
1 parent a972bf7 commit d26887a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 54 deletions.
8 changes: 3 additions & 5 deletions docs/CLIMATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ _Please note that the device_code field only accepts positive numbers. The .json
**name** (Optional): The name of the device<br />
**unique_id** (Optional): An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception.<br />
**device_code** (Required): .... (Accepts only positive numbers)<br />
**controller_send_service** (Required): The service that will be used to send the commands. Only `broadlink_send_packet` (Broadlink controller) and `mqtt.publish` is currently supported.<br />
**controller_command_topic** (Optional): MQTT topic on which to send commands when *controller_send_service* is mqtt.publish<br />
**controller_data** (Required): The data required for the controller to function. Enter the IP address of the Broadlink device (must be an already configured device) or the MQTT topic on which to send commands.<br />
**temperature_sensor** (Optional): *entity_id* for a temperature sensor<br />
**humidity_sensor** (Optional): *entity_id* for a humidity sensor<br />
**power_sensor** (Optional): *entity_id* for a sensor that monitors whether your device is actually On or Off. This may be a power monitor sensor. (Accepts only on/off states)<br />
Expand All @@ -32,7 +31,7 @@ climate:
name: Office AC
unique_id: office_ac
device_code: 1000
controller_send_service: switch.broadlink_send_packet_192_168_10_10
controller_data: 192.168.10.10
temperature_sensor: sensor.temperature
humidity_sensor: sensor.humidity
power_sensor: binary_sensor.ac_power
Expand All @@ -49,8 +48,7 @@ climate:
name: Office AC
unique_id: office_ac
device_code: 2000
controller_send_service: mqtt.publish
controller_command_topic: home-assistant/office-ac/command
controller_data: home-assistant/office-ac/command
temperature_sensor: sensor.temperature
humidity_sensor: sensor.humidity
power_sensor: binary_sensor.ac_power
Expand Down
8 changes: 3 additions & 5 deletions docs/FAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Find your device's brand code [here](FAN.md#available-codes-for-fan-devices) and
**name** (Optional): The name of the device<br />
**unique_id** (Optional): An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception.<br />
**device_code** (Required): ...... (Accepts only positive numbers)<br />
**controller_send_service** (Required): The service that will be used to send the commands. Only `broadlink_send_packet` (Broadlink controller) and `mqtt.publish` is currently supported.<br />
**controller_command_topic** (Optional): MQTT topic on which to send commands when *controller_send_service* is mqtt.publish<br />
**controller_data** (Required): The data required for the controller to function. Enter the IP address of the Broadlink device or the MQTT topic on which to send commands.<br />
**power_sensor** (Optional): *entity_id* for a sensor that monitors whether your device is actually On or Off. This may be a power monitor sensor. (Accepts only on/off states)<br />

## Example (using broadlink controller):
Expand All @@ -27,7 +26,7 @@ fan:
name: Bedroom fan
unique_id: bedroom_fan
device_code: 1000
controller_send_service: switch.broadlink_send_packet_192_168_10_10
controller_data: 192.168.10.10
power_sensor: binary_sensor.fan_power
```
Make sure the broadlink switch is already installed. Go to the Home Assistant UI/dev service, find the broadlink send_packet service and copy the name of it.
Expand All @@ -42,8 +41,7 @@ fan:
name: Bedroom fan
unique_id: bedroom_fan
device_code: 2000
controller_send_service: mqtt.publish
controller_command_topic: home-assistant/bedroom-fan/command
controller_data: home-assistant/bedroom-fan/command
power_sensor: binary_sensor.fan_power
```

Expand Down
8 changes: 3 additions & 5 deletions docs/MEDIA_PLAYER.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Find your device's brand code [here](MEDIA_PLAYER.md#available-codes-for-tv-devi
**name** (Optional): The name of the device<br />
**unique_id** (Optional): An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception.<br />
**device_code** (Required): ...... (Accepts only positive numbers)<br />
**controller_send_service** (Required): The service that will be used to send the commands. Only `broadlink_send_packet` (Broadlink controller) and `mqtt.publish` is currently supported.<br />
**controller_command_topic** (Optional): MQTT topic on which to send commands when *controller_send_service* is mqtt.publish<br />
**controller_data** (Required): The data required for the controller to function. Enter the IP address of the Broadlink device or the MQTT topic on which to send commands.<br />
**power_sensor** (Optional): *entity_id* for a sensor that monitors whether your device is actually On or Off. This may be a power monitor sensor. (Accepts only on/off states)<br />

## Example (using broadlink controller):
Expand All @@ -27,7 +26,7 @@ media_player:
name: Living room TV
unique_id: living_room_tv
device_code: 1000
controller_send_service: switch.broadlink_send_packet_192_168_10_10
controller_data: 192.168.10.10
power_sensor: binary_sensor.tv_power
```
Make sure the broadlink switch is already installed. Go to the Home Assistant UI/dev service, find the broadlink send_packet service and copy the name of it.
Expand All @@ -42,8 +41,7 @@ media_player:
name: Living room TV
unique_id: living_room_tv
device_code: 2000
controller_send_service: mqtt.publish
controller_command_topic: home-assistant/living-room-tv/command
controller_data: home-assistant/living-room-tv/command
power_sensor: binary_sensor.tv_power
```

Expand Down
12 changes: 4 additions & 8 deletions smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

CONF_UNIQUE_ID = 'unique_id'
CONF_DEVICE_CODE = 'device_code'
CONF_CONTROLLER_SEND_SERVICE = "controller_send_service"
CONF_CONTROLLER_COMMAND_TOPIC = "controller_command_topic"
CONF_CONTROLLER_DATA = "controller_data"
CONF_TEMPERATURE_SENSOR = 'temperature_sensor'
CONF_HUMIDITY_SENSOR = 'humidity_sensor'
CONF_POWER_SENSOR = 'power_sensor'
Expand All @@ -43,8 +42,7 @@
vol.Optional(CONF_UNIQUE_ID): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_DEVICE_CODE): cv.positive_int,
vol.Required(CONF_CONTROLLER_SEND_SERVICE): cv.entity_id,
vol.Optional(CONF_CONTROLLER_COMMAND_TOPIC): cv.string,
vol.Required(CONF_CONTROLLER_DATA): cv.string,
vol.Optional(CONF_TEMPERATURE_SENSOR): cv.entity_id,
vol.Optional(CONF_HUMIDITY_SENSOR): cv.entity_id,
vol.Optional(CONF_POWER_SENSOR): cv.entity_id
Expand Down Expand Up @@ -96,8 +94,7 @@ def __init__(self, hass, config, device_data):
self._unique_id = config.get(CONF_UNIQUE_ID)
self._name = config.get(CONF_NAME)
self._device_code = config.get(CONF_DEVICE_CODE)
self._controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
self._controller_command_topic = config.get(CONF_CONTROLLER_COMMAND_TOPIC)
self._controller_data = config.get(CONF_CONTROLLER_DATA)
self._temperature_sensor = config.get(CONF_TEMPERATURE_SENSOR)
self._humidity_sensor = config.get(CONF_HUMIDITY_SENSOR)
self._power_sensor = config.get(CONF_POWER_SENSOR)
Expand Down Expand Up @@ -132,8 +129,7 @@ def __init__(self, hass, config, device_data):
self.hass,
self._supported_controller,
self._commands_encoding,
self._controller_send_service,
self._controller_command_topic)
self._controller_data)

async def async_added_to_hass(self):
"""Run when entity about to be added."""
Expand Down
19 changes: 6 additions & 13 deletions smartir/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
MQTT_COMMANDS_ENCODING = [ENC_RAW]

class Controller():
def __init__(self, hass, controller, encoding, service, topic=None):
def __init__(self, hass, controller, encoding, controller_data):
if controller not in [
BROADLINK_CONTROLLER, XIAOMI_CONTROLLER, MQTT_CONTROLLER]:
raise Exception("The controller is not supported.")
Expand All @@ -40,16 +40,10 @@ def __init__(self, hass, controller, encoding, service, topic=None):
raise Exception("The encoding is not supported "
"by the mqtt controller.")

if not topic:
raise Exception("controller_command_topic must be "
"specified for mqtt controllers.")

self.hass = hass
self._service_domain = split_entity_id(service)[0]
self._service_name = split_entity_id(service)[1]
self._command_topic = topic
self._controller = controller
self._encoding = encoding
self._controller_data = controller_data

async def send(self, command):
if self._controller == BROADLINK_CONTROLLER:
Expand All @@ -73,20 +67,19 @@ async def send(self, command):
"Pronto to Base64 encoding")

service_data = {
'host': self._controller_data,
'packet': command
}

await self.hass.services.async_call(
self._service_domain, self._service_name,
service_data)
'broadlink', 'send', service_data)


if self._controller == MQTT_CONTROLLER:
service_data = {
'topic': self._command_topic,
'topic': self._controller_data,
'payload': command
}

await self.hass.services.async_call(
self._service_domain, self._service_name,
service_data)
'mqtt', 'publish', service_data)
12 changes: 4 additions & 8 deletions smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@

CONF_UNIQUE_ID = 'unique_id'
CONF_DEVICE_CODE = 'device_code'
CONF_CONTROLLER_SEND_SERVICE = "controller_send_service"
CONF_CONTROLLER_COMMAND_TOPIC = "controller_command_topic"
CONF_CONTROLLER_DATA = "controller_data"
CONF_POWER_SENSOR = 'power_sensor'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_UNIQUE_ID): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_DEVICE_CODE): cv.positive_int,
vol.Required(CONF_CONTROLLER_SEND_SERVICE): cv.entity_id,
vol.Optional(CONF_CONTROLLER_COMMAND_TOPIC): cv.string,
vol.Required(CONF_CONTROLLER_DATA): cv.string,
vol.Optional(CONF_POWER_SENSOR): cv.entity_id
})

Expand Down Expand Up @@ -84,8 +82,7 @@ def __init__(self, hass, config, device_data):
self._unique_id = config.get(CONF_UNIQUE_ID)
self._name = config.get(CONF_NAME)
self._device_code = config.get(CONF_DEVICE_CODE)
self._controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
self._controller_command_topic = config.get(CONF_CONTROLLER_COMMAND_TOPIC)
self._controller_data = config.get(CONF_CONTROLLER_DATA)
self._power_sensor = config.get(CONF_POWER_SENSOR)

self._manufacturer = device_data['manufacturer']
Expand Down Expand Up @@ -115,8 +112,7 @@ def __init__(self, hass, config, device_data):
self.hass,
self._supported_controller,
self._commands_encoding,
self._controller_send_service,
self._controller_command_topic)
self._controller_data)

async def async_added_to_hass(self):
"""Run when entity about to be added."""
Expand Down
12 changes: 4 additions & 8 deletions smartir/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@

CONF_UNIQUE_ID = 'unique_id'
CONF_DEVICE_CODE = 'device_code'
CONF_CONTROLLER_SEND_SERVICE = "controller_send_service"
CONF_CONTROLLER_COMMAND_TOPIC = "controller_command_topic"
CONF_CONTROLLER_DATA = "controller_data"
CONF_POWER_SENSOR = 'power_sensor'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_UNIQUE_ID): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_DEVICE_CODE): cv.positive_int,
vol.Required(CONF_CONTROLLER_SEND_SERVICE): cv.entity_id,
vol.Optional(CONF_CONTROLLER_COMMAND_TOPIC): cv.string,
vol.Required(CONF_CONTROLLER_DATA): cv.string,
vol.Optional(CONF_POWER_SENSOR): cv.entity_id
})

Expand Down Expand Up @@ -84,8 +82,7 @@ def __init__(self, hass, config, device_data):
self._unique_id = config.get(CONF_UNIQUE_ID)
self._name = config.get(CONF_NAME)
self._device_code = config.get(CONF_DEVICE_CODE)
self._controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
self._controller_command_topic = config.get(CONF_CONTROLLER_COMMAND_TOPIC)
self._controller_data = config.get(CONF_CONTROLLER_DATA)
self._power_sensor = config.get(CONF_POWER_SENSOR)

self._manufacturer = device_data['manufacturer']
Expand Down Expand Up @@ -133,8 +130,7 @@ def __init__(self, hass, config, device_data):
self.hass,
self._supported_controller,
self._commands_encoding,
self._controller_send_service,
self._controller_command_topic)
self._controller_data)

async def async_added_to_hass(self):
"""Run when entity about to be added."""
Expand Down
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "1.3.9",
"minHAVersion": "0.89.0b0",
"releaseNotes": "A new version (1.3.9) is available that is compatible with your system. Call the ``smartir.update_component`` service to update the component.",
"minHAVersion": "0.92.0b0",
"releaseNotes": "A new version (1.4.0) is available that is compatible with your system. Call the ``smartir.update_component`` service to update the component.",
"files": [
"__init__.py",
"climate.py",
Expand Down

0 comments on commit d26887a

Please sign in to comment.