Skip to content

Commit

Permalink
Merge pull request #9 from koalo/feature/dualactor
Browse files Browse the repository at this point in the history
Fully support dual channel actors
  • Loading branch information
gluap committed Jan 8, 2020
2 parents a9dbe8e + a1a7161 commit d7ab4b8
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 329 deletions.
27 changes: 21 additions & 6 deletions README.rst
Expand Up @@ -167,40 +167,55 @@ commands instead of buying a weather station.

Changelog
=========
**0.30.0**

- **breaking change**: instead of creating multiple devices for single physical devices with multiple actor channels which was rather buggy add a ``channel`` parameter to the respective functions inpyduofern.duofern.Duofern() which allows to handle channels in a consistent manner. See discussion in https://github.com/gluap/pyduofern/pull/9 . For each device available channels are listed in in Duofern().modules['by_code'][code]['channels']. The default channel available for all devices is ``None``, otherwise an ``int`` is expected.


**0.25.2**

- try to fix https://github.com/gluap/pyduofern/issues/2

**0.25.1**
- changed custom component to fix bug in switch implementation accidentally introduced
recently.

- changed custom component to fix bug in switch implementation accidentally introduced recently.

**0.25**

- restarted from 0.23 to get somewhat working auto detection

**0.24**

- somewhat broken changes for auto detection

**0.23.5**

- python 3.7 support should enable current hassio version

**0.23.3**

- added ``--position`` to CLI

**0.23.2**

- renamed README.rst and moved version number from `setup.py` to `__init__.py`

**0.23.1**

- fixed references to repository url
- upped version for pypi release

**0.23**

- added recordings and increased coverage of unit tests (no result-based tests yet though -- just checking if every replay runs until the end without hanging)

**0.22**
- Added recording of actions for replay in integration tests
- Improved unit tests
- Enable travis
- Enable coveralls

* Added recording of actions for replay in integration tests
* Improved unit tests
* Enable travis
* Enable coveralls

**0.21.1**

- fixed bug where device IDs containing `cc` would be be messed up when inserting channel number.
14 changes: 8 additions & 6 deletions examples/homeassistant/custom_components/duofern/__init__.py
Expand Up @@ -11,7 +11,7 @@
# Import the device class from the component that you want to support

# Home Assistant depends on 3rd party packages for API specific code.
REQUIREMENTS = ['pyduofern==0.25.2']
REQUIREMENTS = ['pyduofern==0.30.0']

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -40,11 +40,13 @@ def setup(hass, config):

from pyduofern.duofern_stick import DuofernStickThreaded

newstyle_config = hass.config_entries.async_entries(DOMAIN)[0]
if newstyle_config:
serial_port = newstyle_config.data['serial_port']
code = newstyle_config.data['code']
configfile = newstyle_config.data['config_file']
newstyle_config = hass.config_entries.async_entries(DOMAIN)
if len(newstyle_config) > 0:
newstyle_config = newstyle_config[0]
if newstyle_config:
serial_port = newstyle_config.data['serial_port']
code = newstyle_config.data['code']
configfile = newstyle_config.data['config_file']

elif config.get(DOMAIN) is not None:
serial_port = config[DOMAIN].get(CONF_SERIAL_PORT)
Expand Down
3 changes: 1 addition & 2 deletions examples/homeassistant/custom_components/duofern/cover.py
Expand Up @@ -19,8 +19,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
stick = hass.data[DOMAIN]['stick']

# Add devices
to_add = [DuofernShutter(device['id'], device['name'], stick, hass) for device in stick.config['devices'] if
not (device['id'].startswith('46') or device['id'].startswith('43')) and not device['id'] in hass.data[DOMAIN]['devices'].keys()]
to_add = [DuofernShutter(device['id'], device['name'], stick, hass) for device in stick.config['devices'] if (device['id'].startswith('40') or device['id'].startswith('41') or device['id'].startswith('42') or device['id'].startswith('47') or device['id'].startswith('49') or device['id'].startswith('61')) and not device['id'] in hass.data[DOMAIN]['devices'].keys()]
add_devices(to_add)


Expand Down
49 changes: 33 additions & 16 deletions examples/homeassistant/custom_components/duofern/light.py
Expand Up @@ -31,20 +31,36 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
stick = hass.data["duofern"]['stick']

# Add devices
to_add = [DuofernLight(device['id'], device['name'], stick, hass) for device in stick.config['devices'] if
(device['id'].startswith('46') or device['id'].startswith('43')) and not device['id'] in hass.data[DOMAIN]['devices'].keys()]
add_devices(to_add)

for device in stick.config['devices']:
if device['id'].startswith('46') or device['id'].startswith('48'):
if device['id'] in hass.data[DOMAIN]['devices'].keys():
continue
add_devices([DuofernLight(device['id'], device['name'], stick, hass)])

if device['id'].startswith('43'):
for channel in [1,2]:
chanNo = "{:02x}".format(channel)
if device['id']+chanNo in hass.data[DOMAIN]['devices'].keys():
continue
add_devices([DuofernLight(device['id'], device['name'], stick, hass, channel=channel)])

class DuofernLight(Light):
def __init__(self, id, desc, stick, hass):
"""Initialize the shutter."""
self._id = id
def __init__(self, code, desc, stick, hass, channel=None):
"""Initialize the light."""
self._code = code
self._id = code
self._name = desc

if channel:
chanNo = "{:02x}".format(channel)
self._id += chanNo
self._name += chanNo

self._state = None
self._brightness = None
self._stick = stick
hass.data[DOMAIN]['devices'][id] = self
self._channel = channel
hass.data[DOMAIN]['devices'][self._id] = self

@property
def name(self):
Expand All @@ -53,8 +69,9 @@ def name(self):
@property
def is_on(self):
try:
_LOGGER.info(self._stick.duofern_parser.modules['by_code'][self._id])
return self._stick.duofern_parser.modules['by_code'][self._id]['state'] == "on"
_LOGGER.info(self._stick.duofern_parser.modules['by_code'][self._code])
state = self._stick.duofern_parser.get_state(self._code, 'state', channel=self._channel)
return state == "on"
except KeyError:
return None

Expand All @@ -63,14 +80,14 @@ def unique_id(self):
return self._id

def turn_on(self):
self._stick.command(self._id, "on")
# this is a hotfix because currently the state is not correctly detected from duofern
self._stick.duofern_parser.modules['by_code'][self._id]['state'] = "on"
self._stick.command(self._code, "on", channel=self._channel)
# this is a hotfix because currently the state is detected with delay from duofern
self._stick.duofern_parser.update_state(self._code, 'state', "on", channel=self._channel)

def turn_off(self):
self._stick.command(self._id, "off")
# this is a hotfix because currently the state is not correctly detected from duofern
self._stick.duofern_parser.modules['by_code'][self._id]['state'] = 0
self._stick.command(self._code, "off", channel=self._channel)
# this is a hotfix because currently the state is detected with delay from duofern
self._stick.duofern_parser.update_state(self._code, 'state', "off", channel=self._channel)

def update(self):
pass
Expand Up @@ -5,5 +5,5 @@
"dependencies": [],
"config_flow": true,
"codeowners": ["@gluap"],
"requirements": ["pyduofern==0.25.2"]
}
"requirements": ["pyduofern==0.30.0"]
}
2 changes: 1 addition & 1 deletion examples/readme.rst
Expand Up @@ -15,7 +15,7 @@ The following is setup procedure with hassio
git clone https://github.com/gluap/pyduofern/
cp -r pyduofern/examples/homeassistant/custom_components /config/
# next line only if you don't already have it yet:
echo "duofern:" >/config/configuration.yaml
echo "duofern:" >> /config/configuration.yaml
# next use 4 digit hex code of your choice instead of ffff ("password" for your duofern net)
# if you are migrating from FHEM: Skip the "6f" from the beginning of the code,
# only use the last 4 characters
Expand Down
2 changes: 1 addition & 1 deletion pyduofern/__init__.py
Expand Up @@ -22,7 +22,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
__version__ = "0.25.2"
__version__ = "0.30.0"

__all__ = ['DuofernException', 'DuofernStick', 'DuofernStickAsync', 'duoACK']

Expand Down

0 comments on commit d7ab4b8

Please sign in to comment.