Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lumitek/ankuoo recswitch component #15764

Merged
merged 6 commits into from Oct 9, 2018
Merged

Added lumitek/ankuoo recswitch component #15764

merged 6 commits into from Oct 9, 2018

Conversation

marcolertora
Copy link
Contributor

@marcolertora marcolertora commented Jul 31, 2018

Description:

Added support for lumitek/ankuoo recswitch to homeassistant.
the device is known as:

  • Ankuoo MS6126 /
  • Ankuoo REC 4800009
  • Lumitek CSW201 NEO WiFi Control module

Searching on the web it look like the device is made by lumitek and branded and sold on amazon by ankuoo:

The chipset inside the device should be the HF-LPB100.

Home Assistant Support has been discussed and requested in this thread:

Example entry for configuration.yaml:

switch01:
  - platform: recswitch
    name: Garden Lights
    host: 192.168.X.X
    mac: 'F0:FE:6B:XX:XX:XX'

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#6548

Checklist:

  • The code change is tested and works locally.
  • New dependencies have been added to the REQUIREMENTS variable.
  • New dependencies are only imported inside functions that use them.
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

@homeassistant
Copy link
Contributor

Hi @marcolertora,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!


def get_gpio_status(self):
from pyrecswitch import RecSwitchProtocol
return self.send_packet(RecSwitchProtocol.get_gpio_status(self.device_config, flag=0))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (94 > 79 characters)


def set_gpio_status(self, state):
from pyrecswitch import RecSwitchProtocol
return self.send_packet(RecSwitchProtocol.set_gpio_status(self.device_config, flag=0, state=state))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (107 > 79 characters)


def heart_beat(self):
from pyrecswitch import RecSwitchProtocol
return self.send_packet(RecSwitchProtocol.heart_beat(self.device_config))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)


def send_packet(self, packet):
self.device_config.next_message_index()
return self.connection_pool.send_packet(packet, self.ip_address, self.port)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (83 > 79 characters)

if not self.gpio_state == response.state:
self.gpio_state = response.state
self.schedule_update_ha_state()
_LOGGER.info('command: {} set state to: {}'.format(RecSwitchCommand(command).name, self.gpio_state))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (116 > 79 characters)





Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line at end of file


hass.data[DATA_RSH] = RecSwitchUDPServerProtocol()
listener = hass.loop.create_datagram_endpoint(lambda: hass.data[DATA_RSH],
local_addr=(local_ip_address, local_ip_port))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (95 > 79 characters)


def packet_received(self, remote_address, device_config, command, response):
if device_config.mac_address in self.devices:
self.devices[device_config.mac_address].receive_packet(command, response)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (89 > 79 characters)

class RecSwitchUDPServerProtocol(RecSwitchServerProtocol):
devices = dict()

def packet_received(self, remote_address, device_config, command, response):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (84 > 79 characters)

def setup(hass, base_config):
from pyrecswitch import RecSwitchDeviceConfig, RecSwitchServerProtocol
config = base_config.get(DOMAIN, dict())
local_ip_port = config.get(CONF_PORT, RecSwitchDeviceConfig.default_udp_port)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

homeassistant/components/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
@marcolertora
Copy link
Contributor Author

updated the pyrecswitch and move there all the device logic

@marcolertora
Copy link
Contributor Author

Could you help me to understand what is the problem with the Travis CI failure?

@MartinHjelmare
Copy link
Member

Run script/gen_requirements.py. The instructions for this were in the PR template that was present when you opened the PR.

There are also some missing docstrings.

@marcolertora
Copy link
Contributor Author

fixed

homeassistant/components/recswitch.py Outdated Show resolved Hide resolved
Support for Ankuoo RecSwitch MS6126 devices.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.recswitch/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The url is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll write the documentation.. I promise!

homeassistant/components/recswitch.py Outdated Show resolved Hide resolved

async def async_setup(hass, base_config):
"""Setup recswitch network and start datagram endpoint."""
config = base_config.get(DOMAIN, dict())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config = base_config[DOMAIN]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but this change willl make the component config section required. I mean....

recswitch:

switch01:

  • platform: recswitch
    name: Garden Lights
    host: 192.168.X.X
    mac: 'F0:FE:6B:XX:XX:XX'

It should be right? or I miss something?
actually, I read more more than one time the developer doc but I'm still unsure about if I really need to create a component and a platform for my devices..

I found this way to share the udp socket server across more platform instances. This is required because all this devices send udp message to the same port to the host.

Suggestions are welcome!
Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to share some device connection between platform types a component is required. We are also moving to use config entries instead as an alternative to the config sections in yaml, and then a component is required.

If you're planning to add more platform types, keep the component. But if there will only be the switch platform it would also work to save the server instance in hass.data and reuse it for many switch platform instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, reusing the server instance for more switch is what I thought as alternative.

I don't known if exists other kind of devices based on this protocol (such as lights or sensors...) I've no connection with the manufactur I've just bought an ankuoo device thinking it was already supported (I misunderstood a thread on the forum ..) so I spent 'some' hours in reverse engineering..

May be sharing the server instance across switch devices is the easiest way.. I'll code in this way.

homeassistant/components/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
@marcolertora
Copy link
Contributor Author

Remove component leave only the platform

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can return the mac address in the unique id property.

I still think it's weird that we both have a callback for state updates and have the entity be polling. When is the callback called?

homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
@marcolertora
Copy link
Contributor Author

Yes it's a bit weird but the callback alone is not enough.
The callback is invoked when a "NOTIFY_CHANGE" message is received. The NOTIFY_CHANGE is sent from the switch to the broadcast address when it change its status.... most of the time.

I think the polling is required because of the broadcast propagation limit and the missing information about initial state. So, we can, at least, remove the callback and leave only the polling.
What you think about?

@MartinHjelmare
Copy link
Member

Sounds good to remove the callback.

@MartinHjelmare
Copy link
Member

Please don't squash commits after review has started. Squashing makes it hard to follow changes.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some minor comments left.

homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
homeassistant/components/switch/recswitch.py Outdated Show resolved Hide resolved
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, please add the module to .coveragerc.

@MartinHjelmare
Copy link
Member

Also add a link to a docs PR. All of these instructions were in the PR template that you removed. It would have been good to keep it.

@marcolertora
Copy link
Contributor Author

HI,
linked documentation PR and fixed coveragerc

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can be merged when build passes.

@balloob balloob merged commit 0c34c50 into home-assistant:dev Oct 9, 2018
@ghost ghost removed the in progress label Oct 9, 2018
@balloob balloob mentioned this pull request Oct 26, 2018
@ljalves
Copy link

ljalves commented Jan 19, 2019

In case someone is interested, I've made a new firmware for these devices.
For now it supports mqtt and http to control it. More info at:
https://github.com/ljalves/hfeasy

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants