GithubHelp home page GithubHelp logo

pymochad's Introduction

pymochad

A python library for sending commands to the mochad TCP gateway daemon for the X10 CMA15A controller:

https://sourceforge.net/projects/mochad/

Complete documentation is here: http://pymochad.readthedocs.io/en/latest/

Usage

Using PyMochad is pretty straightforward you just need to init a PyMochad object and then issue commands to it. For example:

from pymochad import controller

mochad = remote.PyMochad()
print(mochad.status())

will connect to a running mochad instance (running on your localhost) and print the device status.

You can also send a command directly to a device using a device class. For example:

from pymochad import controller
from pymochad import device

mochad = controller.PyMochad()
light_switch = device.Device(mochad, 'a1')
light_switch.send_cmd('on')

will connect to a running a mochad instance and send the on command to the light switch device at address a1 on the power line interface.

For a complete API documentation see: :ref:`pymochad_api`.

pymochad's People

Contributors

mtreinish avatar iainrach avatar rayun56 avatar aosadchyy avatar clach04 avatar

Watchers

 avatar Gert Wijsman avatar  avatar

pymochad's Issues

HA uses pymochad asynchrone

HA Bug report 2017.pdf

Bug report 2017-12-4
Mochad and Home Assistant
I have a situation with a running mochad installation on a server with a local ip on port 1099
(as defaults suggest)
I am migrating from OpenHab to Home Assistant (and before that openRemote) because I am a fan of MQTT and python.
OpenHab and mochad work fine so Home Assistant should be able to do the job too.
I have multiple iot devices I like to integrate but first I want to control the lights. I have 5 very old Marmitec (x10) devices and 3 less old Marmitek devices. Marmitek does not sell these x10 devices any more but I have them installed in my walls.
My super user (My Wife) will not approve my new solution if the lights wont turn on or off. So here my motivation to solve this issue with you.
I found out that with the HA is using a asynchronous way of starting up devices.
I added some nasty debug logging to the sources to find out what goes wrong.

2017-12-04 20:54:59 DEBUG (Thread-5) [pymochad.device] get status for c12
2017-12-04 20:54:59 DEBUG (Thread-2) [pymochad.device] get status for c1
2017-12-04 20:54:59 DEBUG (Thread-8) [pymochad.device] get status for c2
2017-12-04 20:54:59 DEBUG (Thread-5) [pymochad.controller] Send command from controller: getstatus c12
2017-12-04 20:54:59 DEBUG (Thread-2) [pymochad.controller] Send command from controller: getstatus c1
2017-12-04 20:54:59 DEBUG (Thread-8) [pymochad.controller] Send command from controller: getstatus c2
2017-12-04 20:54:59 DEBUG (Thread-5) [pymochad.controller] Start read data from controller
2017-12-04 20:54:59 DEBUG (Thread-2) [pymochad.controller] Start read data from controller
2017-12-04 20:54:59 DEBUG (Thread-2) [pymochad.controller] data read: off
on
on
2017-12-04 20:54:59 DEBUG (Thread-8) [pymochad.controller] Start read data from controller
2017-12-04 20:54:59 DEBUG (Thread-2) [homeassistant.components.light.mochad] Got device status: off
on
on for c1

just a snapshot of the logging but you can see what goes wrong. Status for lights c12, c1 and c2 are queried. So the commands are sent off to pymochad. And stuff is read.
But thread-2 (light c1) got all results off, on and on.
So I tried some locking to make stuff atomic.

def _get_device_status(self):
"""Get the status of the light from mochad."""
from threading import Lock
lock = Lock()
lock.acquire()
_LOGGER.debug("Start getting light device status for %s", self._address)
status = self.device.get_status().rstrip()
_LOGGER.debug("Got device status: %s for %s", status, self._address)
lock.release()
return status == 'on'

So I got a logging like this:

2017-12-04 21:00:43 DEBUG (Thread-7) [homeassistant.components.switch.mochad] Start getting switch device status for c2
2017-12-04 21:00:43 DEBUG (Thread-7) [pymochad.device] get status for c2
2017-12-04 21:00:43 DEBUG (Thread-2) [homeassistant.components.switch.mochad] Start getting switch device status for c12
2017-12-04 21:00:43 DEBUG (Thread-5) [homeassistant.components.light.mochad] Start getting light device status for c1
2017-12-04 21:00:43 DEBUG (Thread-7) [pymochad.controller] Send command from controller: getstatus c2

So this is definitely not the solution.
My idea towards a solution is that pymochad (the external pipy module) should not accept new commands (requests) from HA before answering a former request.
Maybe someone can shine some lights on this? What is the best way to approach?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.