Skip to content

Commit

Permalink
Merge pull request #78 from litinoveweedle/pass_remote_params
Browse files Browse the repository at this point in the history
Pass remote controller parameters
  • Loading branch information
litinoveweedle authored Jul 16, 2024
2 parents 231ca2f + 7fe69c2 commit 836c639
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
6 changes: 5 additions & 1 deletion custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
CONF_UNIQUE_ID = "unique_id"
CONF_DEVICE_CODE = "device_code"
CONF_CONTROLLER_DATA = "controller_data"
CONF_CONTROLLER_PARAMS = "controller_params"
CONF_DELAY = "delay"
CONF_TEMPERATURE_SENSOR = "temperature_sensor"
CONF_HUMIDITY_SENSOR = "humidity_sensor"
Expand All @@ -57,6 +58,7 @@
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_DEVICE_CODE): cv.positive_int,
vol.Required(CONF_CONTROLLER_DATA): cv.string,
vol.Optional(CONF_CONTROLLER_PARAMS, default={}): dict,
vol.Optional(CONF_DELAY, default=DEFAULT_DELAY): cv.positive_float,
vol.Optional(CONF_TEMPERATURE_SENSOR): cv.entity_id,
vol.Optional(CONF_HUMIDITY_SENSOR): cv.entity_id,
Expand Down Expand Up @@ -105,6 +107,7 @@ def __init__(self, hass, config, device_data):
self._name = config.get(CONF_NAME)
self._device_code = config.get(CONF_DEVICE_CODE)
self._controller_data = config.get(CONF_CONTROLLER_DATA)
self._controller_params = config.get(CONF_CONTROLLER_PARAMS)
self._delay = config.get(CONF_DELAY)
self._temperature_sensor = config.get(CONF_TEMPERATURE_SENSOR)
self._humidity_sensor = config.get(CONF_HUMIDITY_SENSOR)
Expand Down Expand Up @@ -221,12 +224,13 @@ def __init__(self, hass, config, device_data):
self._temp_lock = asyncio.Lock()

# Init the IR/RF controller
self._controller_params["delay"] = self._delay
self._controller = get_controller(
self.hass,
self._supported_controller,
self._commands_encoding,
self._controller_data,
self._delay,
self._controller_params,
)

async def async_added_to_hass(self):
Expand Down
15 changes: 10 additions & 5 deletions custom_components/smartir/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.const import ATTR_ENTITY_ID


def get_controller(hass, controller, encoding, controller_data, delay):
def get_controller(hass, controller, encoding, controller_data, controller_params):
"""Return a controller compatible with the specification provided."""
controllers = {
BROADLINK_CONTROLLER: BroadlinkController,
Expand All @@ -22,7 +22,7 @@ def get_controller(hass, controller, encoding, controller_data, delay):
}
try:
return controllers[controller](
hass, controller, encoding, controller_data, delay
hass, controller, encoding, controller_data, controller_params
)
except KeyError:
raise Exception("The controller is not supported.")
Expand All @@ -31,12 +31,12 @@ def get_controller(hass, controller, encoding, controller_data, delay):
class AbstractController(ABC):
"""Representation of a controller."""

def __init__(self, hass, controller, encoding, controller_data, delay):
def __init__(self, hass, controller, encoding, controller_data, controller_params):
self.hass = hass
self._controller = controller
self._encoding = encoding
self._controller_data = controller_data
self._delay = delay
self._controller_params = controller_params

@abstractmethod
def check_encoding(self, encoding):
Expand Down Expand Up @@ -91,8 +91,13 @@ async def send(self, command):
service_data = {
ATTR_ENTITY_ID: self._controller_data,
"command": commands,
"delay_secs": self._delay,
}
if "delay_secs" in self._controller_params:
service_data["delay_secs"] = self._controller_params["delay_secs"]
else:
service_data["delay_secs"] = self._controller_params["delay"]
if "num_repeats" in self._controller_params:
service_data["num_repeats"] = self._controller_params["num_repeats"]

await self.hass.services.async_call("remote", "send_command", service_data)

Expand Down
6 changes: 5 additions & 1 deletion custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
CONF_UNIQUE_ID = "unique_id"
CONF_DEVICE_CODE = "device_code"
CONF_CONTROLLER_DATA = "controller_data"
CONF_CONTROLLER_PARAMS = "controller_params"
CONF_DELAY = "delay"
CONF_POWER_SENSOR = "power_sensor"
CONF_POWER_SENSOR_DELAY = "power_sensor_delay"
Expand All @@ -45,6 +46,7 @@
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_DEVICE_CODE): cv.positive_int,
vol.Required(CONF_CONTROLLER_DATA): cv.string,
vol.Optional(CONF_CONTROLLER_PARAMS, default={}): dict,
vol.Optional(CONF_DELAY, default=DEFAULT_DELAY): cv.positive_float,
vol.Optional(CONF_POWER_SENSOR): cv.entity_id,
vol.Optional(
Expand Down Expand Up @@ -83,6 +85,7 @@ def __init__(self, hass, config, device_data):
self._name = config.get(CONF_NAME)
self._device_code = config.get(CONF_DEVICE_CODE)
self._controller_data = config.get(CONF_CONTROLLER_DATA)
self._controller_params = config.get(CONF_CONTROLLER_PARAMS)
self._delay = config.get(CONF_DELAY)
self._power_sensor = config.get(CONF_POWER_SENSOR)
self._power_sensor_delay = config.get(CONF_POWER_SENSOR_DELAY)
Expand Down Expand Up @@ -125,12 +128,13 @@ def __init__(self, hass, config, device_data):
self._temp_lock = asyncio.Lock()

# Init the IR/RF controller
self._controller_params["delay"] = self._delay
self._controller = get_controller(
self.hass,
self._supported_controller,
self._commands_encoding,
self._controller_data,
self._delay,
self._controller_params,
)

async def async_added_to_hass(self):
Expand Down
6 changes: 5 additions & 1 deletion custom_components/smartir/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
CONF_UNIQUE_ID = "unique_id"
CONF_DEVICE_CODE = "device_code"
CONF_CONTROLLER_DATA = "controller_data"
CONF_CONTROLLER_PARAMS = "controller_params"
CONF_DELAY = "delay"
CONF_POWER_SENSOR = "power_sensor"
CONF_POWER_SENSOR_DELAY = "power_sensor_delay"
Expand All @@ -40,6 +41,7 @@
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_DEVICE_CODE): cv.positive_int,
vol.Required(CONF_CONTROLLER_DATA): cv.string,
vol.Optional(CONF_CONTROLLER_PARAMS, default={}): dict,
vol.Optional(CONF_DELAY, default=DEFAULT_DELAY): cv.positive_float,
vol.Optional(CONF_POWER_SENSOR): cv.entity_id,
vol.Optional(
Expand Down Expand Up @@ -80,6 +82,7 @@ def __init__(self, hass, config, device_data):
self._name = config.get(CONF_NAME)
self._device_code = config.get(CONF_DEVICE_CODE)
self._controller_data = config.get(CONF_CONTROLLER_DATA)
self._controller_params = config.get(CONF_CONTROLLER_PARAMS)
self._delay = config.get(CONF_DELAY)
self._power_sensor = config.get(CONF_POWER_SENSOR)
self._power_sensor_delay = config.get(CONF_POWER_SENSOR_DELAY)
Expand Down Expand Up @@ -161,12 +164,13 @@ def __init__(self, hass, config, device_data):
self._temp_lock = asyncio.Lock()

# Init the IR/RF controller
self._controller_params["delay"] = self._delay
self._controller = get_controller(
self.hass,
self._supported_controller,
self._commands_encoding,
self._controller_data,
self._delay,
self._controller_params,
)

async def async_added_to_hass(self):
Expand Down
4 changes: 4 additions & 0 deletions docs/CLIMATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Find your device's brand code [here](CLIMATE.md#available-codes-for-climate-devi
| `unique_id` | string | optional | An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception. |
| `device_code` | number | required | (Accepts only positive numbers) |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands, or the ZHA zigbee cluster to send commands to. |
| `controller_params` | dict | optional | Dictionary containing list of additional key/values which will be passed to the remote.send_command service. For example `delay_sec` and `num_repeats` for Broadlink remote. For allowed key/values reffer to the HA documentation for remote.send_command service. |
| `delay` | number | optional | Adjusts the delay in seconds between multiple commands. The default is 0.5 |
| `temperature_sensor` | string | optional | _entity_id_ for a temperature sensor |
| `humidity_sensor` | string | optional | _entity_id_ for a humidity sensor |
Expand All @@ -31,6 +32,9 @@ climate:
unique_id: office_ac
device_code: 1000
controller_data: remote.bedroom_remote
controller_params:
delay_secs: 0.5
num_repeats: 3
temperature_sensor: sensor.temperature
humidity_sensor: sensor.humidity
power_sensor: binary_sensor.ac_power
Expand Down
4 changes: 4 additions & 0 deletions docs/FAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Find your device's brand code [here](FAN.md#available-codes-for-fan-devices) and
| `unique_id` | string | optional | An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception. |
| `device_code` | number | required | (Accepts only positive numbers) |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands, or the ZHA zigbee cluster to send commands to. |
| `controller_params` | dict | optional | Dictionary containing list of additional key/values which will be passed to the remote.send_command service. For example `delay_sec` and `num_repeats` for Broadlink remote. For allowed key/values reffer to the HA documentation for remote.send_command service. |
| `delay` | number | optional | Adjusts the delay in seconds between multiple commands. The default is 0.5 |
| `power_sensor` | string | 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) |
| `power_sensor_delay` | int | optional | Maximum delay in second in which power sensor is able to report back to HA changed state of the device, default is 10 seconds. If sensor reaction time is longer extend this time, otherwise you might get unwanted changes in the device state. |
Expand All @@ -29,6 +30,9 @@ fan:
unique_id: bedroom_fan
device_code: 1000
controller_data: remote.bedroom_remote
controller_params:
delay_secs: 0.5
num_repeats: 3
power_sensor: binary_sensor.fan_power
```
Expand Down
4 changes: 4 additions & 0 deletions docs/MEDIA_PLAYER.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Find your device's brand code [here](MEDIA_PLAYER.md#available-codes-for-tv-devi
| `unique_id` | string | optional | An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception. |
| `device_code` | number | required | (Accepts only positive numbers) |
| `controller_data` | string | required | The data required for the controller to function. Enter the entity_id of the Broadlink remote **(must be an already configured device)**, or the entity id of the Xiaomi IR controller, or the MQTT topic on which to send commands, or the ZHA zigbee cluster to send commands to. |
| `controller_params` | dict | optional | Dictionary containing list of additional key/values which will be passed to the remote.send_command service. For example `delay_sec` and `num_repeats` for Broadlink remote. For allowed key/values reffer to the HA documentation for remote.send_command service. |
| `delay` | number | optional | Adjusts the delay in seconds between multiple commands. The default is 0.5 |
| `power_sensor` | string | 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) |
| `power_sensor_delay` | int | optional | Maximum delay in second in which power sensor is able to report back to HA changed state of the device, default is 10 seconds. If sensor reaction time is longer extend this time, otherwise you might get unwanted changes in the device state. |
Expand All @@ -30,6 +31,9 @@ media_player:
unique_id: living_room_tv
device_code: 1000
controller_data: remote.bedroom_remote
controller_params:
delay_secs: 0.5
num_repeats: 3
power_sensor: binary_sensor.tv_power
```
Expand Down

0 comments on commit 836c639

Please sign in to comment.