Skip to content

Commit

Permalink
Merge branch 'gicamm:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
optiluca committed Nov 14, 2022
2 parents 23b2c27 + 2ef7f1f commit bcfedcb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 66 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Comelit Hub/Vedo integration

With Comelit Hub/Vedo integration, you can connect your Home Assistant instance to Comelit Simple Home and Vedo systems.
With Comelit Hub/Vedo integration, you can connect your Home Assistant instance to Comelit Simple Home and Vedo systems.

For more information, see the [Wiki](https://github.com/gicamm/homeassistant-comelit/wiki).

### Installation

Expand Down Expand Up @@ -29,22 +31,14 @@ comelit:

```
### How to find the hub serial?
#### MQTT Mosquitto Client
Execute the mosquitto client and look at the output
```bash
mosquitto_sub -v -h 192.168.188.21 -u hsrv-user -P sf1nE9bjPc -t 'HSrv/002529170576/rx/localClient-XXXX' -p 1883 -i 654321
```

It prints the full topic name, like below:
```
HSrv/SERIAL/tx/localClient-XXXX
```

#### Comelit app
- Open the Comelit app
- Scan for a new hub device
- Copy the serial

For more information, see the [Wiki](https://github.com/gicamm/homeassistant-comelit/wiki).

### Supported features
- Lights
- Shutters
Expand Down
72 changes: 35 additions & 37 deletions custom_components/comelit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,42 @@ def setup(hass, config):
hass.data[DOMAIN]['conf'] = conf

# Comelit Hub
hub_conf = conf["hub"]
if hub_conf is not None:
schema = HUB_SCHEMA(hub_conf)
hub_host = schema[CONF_HOST]
mqtt_port = schema[CONF_PORT]
mqtt_user = schema[CONF_MQTT_USER]
mqtt_password = schema[CONF_MQTT_PASSWORD]
hub_user = schema[CONF_USERNAME]
scan_interval = schema[CONF_SCAN_INTERVAL]
hub_password = schema[CONF_PASSWORD]
hub_serial = schema[CONF_SERIAL]
hub_client = schema[CONF_CLIENT]
hub = ComelitHub(hub_client, hub_serial, hub_host, mqtt_port, mqtt_user, mqtt_password, hub_user, hub_password, scan_interval)
hass.data[DOMAIN]['hub'] = hub
hass.helpers.discovery.load_platform('sensor', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('light', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('cover', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('scene', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('switch', DOMAIN, {}, config)
_LOGGER.info("Comelit Hub integration started")
if 'hub' in conf:
hub_conf = conf["hub"]
if hub_conf is not None:
schema = HUB_SCHEMA(hub_conf)
hub_host = schema[CONF_HOST]
mqtt_port = schema[CONF_PORT]
mqtt_user = schema[CONF_MQTT_USER]
mqtt_password = schema[CONF_MQTT_PASSWORD]
hub_user = schema[CONF_USERNAME]
scan_interval = schema[CONF_SCAN_INTERVAL]
hub_password = schema[CONF_PASSWORD]
hub_serial = schema[CONF_SERIAL]
hub_client = schema[CONF_CLIENT]
hub = ComelitHub(hub_client, hub_serial, hub_host, mqtt_port, mqtt_user, mqtt_password, hub_user,
hub_password, scan_interval)
hass.data[DOMAIN]['hub'] = hub
hass.helpers.discovery.load_platform('sensor', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('light', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('cover', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('scene', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('switch', DOMAIN, {}, config)
_LOGGER.info("Comelit Hub integration started")

# Comelit Vedo
vedo_conf = conf["vedo"]
if vedo_conf is not None:
schema = VEDO_SCHEMA(vedo_conf)
vedo_host = schema[CONF_HOST]
vedo_port = schema[CONF_PORT]
vedo_pwd = schema[CONF_PASSWORD]
scan_interval = schema[CONF_SCAN_INTERVAL]
vedo = ComelitVedo(vedo_host, vedo_port, vedo_pwd, scan_interval)
hass.data[DOMAIN]['vedo'] = vedo
# hass.helpers.discovery.load_platform('binary_sensor', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('alarm_control_panel', DOMAIN, {}, config)
_LOGGER.info("Comelit Vedo integration started")
if 'vedo' in conf:
vedo_conf = conf["vedo"]
if vedo_conf is not None:
schema = VEDO_SCHEMA(vedo_conf)
vedo_host = schema[CONF_HOST]
vedo_port = schema[CONF_PORT]
vedo_pwd = schema[CONF_PASSWORD]
scan_interval = schema[CONF_SCAN_INTERVAL]
vedo = ComelitVedo(vedo_host, vedo_port, vedo_pwd, scan_interval)
hass.data[DOMAIN]['vedo'] = vedo
# hass.helpers.discovery.load_platform('binary_sensor', DOMAIN, {}, config)
hass.helpers.discovery.load_platform('alarm_control_panel', DOMAIN, {}, config)
_LOGGER.info("Comelit Vedo integration started")

return True





12 changes: 7 additions & 5 deletions custom_components/comelit/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def __init__(self, id, description, closed, position, hub):
ComelitDevice.__init__(self, id, None, description)
self._state = closed
self._hub = hub
self._position = position
if position != -1:
self._position = position

@property
def is_closed(self):
Expand Down Expand Up @@ -58,10 +59,11 @@ def close_cover(self, **kwargs):
def update_state(self, state, position):
super().update_state(state)

old = self._position
self._position = position
if old != position:
self.async_schedule_update_ha_state()
if position != -1:
old = self._position
self._position = position
if old != position:
self.async_schedule_update_ha_state()

def stop_cover(self, **kwargs):
_LOGGER.debug(f"Trying to STOP cover {self.name}! is_opening={self.is_opening}, is_closing={self.is_closing}")
Expand Down
31 changes: 18 additions & 13 deletions custom_components/comelit/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import paho.mqtt.client as mqtt
from threading import Thread

from homeassistant.const import STATE_CLOSED, STATE_OPEN, STATE_CLOSING, STATE_OPENING, STATE_ON, STATE_OFF
from homeassistant.const import STATE_CLOSED, STATE_OPEN, STATE_CLOSING, STATE_OPENING, STATE_ON, STATE_OFF, \
STATE_UNKNOWN

from .scene import ComelitScenario
from .sensor import PowerSensor, TemperatureSensor, HumiditySensor
Expand Down Expand Up @@ -321,19 +322,23 @@ def update_light(self, id, description, data):

def update_cover(self, id, description, data, status_key):
try:
if data['status'] == '0':
# Not moving
if data['open_status'] == '1':
state = STATE_OPEN
else:
state = STATE_CLOSED
elif data['status'] == '1':
state = STATE_OPENING
elif data['status'] == '2':
state = STATE_CLOSING
if 'position' in data:
if data['status'] == '0':
# Not moving
if data['open_status'] == '1':
state = STATE_OPEN
else:
state = STATE_CLOSED
elif data['status'] == '1':
state = STATE_OPENING
elif data['status'] == '2':
state = STATE_CLOSING

position = int(100 * float(data['position']) / 255)
else: # unable to define the position. works for legacy cover
state = STATE_UNKNOWN
position = -1

position = int(100*float(data['position'])/255)

if id not in self.covers: # Add the new cover
if hasattr(self, 'cover_add_entities'):
cover = ComelitCover(id, description, state, position, CommandHub(self))
Expand Down

0 comments on commit bcfedcb

Please sign in to comment.