Skip to content
This repository has been archived by the owner on May 23, 2020. It is now read-only.

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tikismoke committed Oct 27, 2016
0 parents commit 652e425
Show file tree
Hide file tree
Showing 19 changed files with 595 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pyc
*.swp
_build_doc
*~
*.20*

Empty file added .travis.yml
Empty file.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The changelog informations are available in docs/changelog.txt
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Domogik Plugin ebusd

## Purpose

This is a package for Domogik : http://www.domogik.org

Domogik is an open source home automation solution.

## Documentation

You can find the documentation source in the **docs/** folder. When the package will be installed, the documentation will be available in the **Documentation** menu of the Domogik administration for this package.
You may also find online documentation for this plugin. You will be able to find the documentation url on http://repo-public.domogik.org/dashboard

## Install the package

To install this package on your Domogik system, you can go in this GitHub repository releases page and get the link to a release .zip file. Then you just have to do :

dmg_package -i http://path.to/the/file.zip
Empty file added __init__.py
Empty file.
Empty file added bin/__init__.py
Empty file.
149 changes: 149 additions & 0 deletions bin/ebusd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


""" This file is part of B{Domogik} project (U{http://www.domogik.org}).
License
=======
B{Domogik} is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
B{Domogik} is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Domogik. If not, see U{http://www.gnu.org/licenses}.
Plugin purpose
==============
Plugin for ebus protocole throw ebusd
Implements
==========
@author: tikismoke (new dt domodroid at gmail dt com)
@copyright: (C) 2007-2016 Domogik project
@license: GPL(v3)
@organization: Domogik
"""
from domogik.common.plugin import Plugin
from domogikmq.message import MQMessage

from domogik_packages.plugin_ebusd.lib.ebusd import ebusdException
from domogik_packages.plugin_ebusd.lib.ebusd import ebusdclass

import threading
import time
import json


class ebusdManager(Plugin):
# -------------------------------------------------------------------------------------------------
def __init__(self):
"""
Init plugin
"""
Plugin.__init__(self, name='ebusd')

# check if the plugin is configured. If not, this will stop the plugin and log an error
if not self.check_configured():
return

# ### get all config keys
device = self.get_config("device")

# ### get the devices list
# for this plugin, if no devices are created we won't be able to use devices.
self.devices = self.get_device_list(quit_if_no_device=False)
self.log.info(u"==> device: %s" % format(self.devices))

# get the sensors id per device :
self.sensors = self.get_sensors(self.devices)
self.log.info(u"==> sensors: %s" % format(self.sensors))

# ### Open the ebus manager
try:
self.ebusdclass = ebusdclass(self.log, device)
except ebusdException as e:
self.log.error(e.value)
self.force_leave()
return

# try opening
try:
self.ebusdclass.open(device)
except ebusdException as ex:
self.log.error(ex.value)
self.force_leave()
return

# ### For each device
self.device_list = {}
thread_sensors = None
for a_device in self.devices:
device_name = a_device["name"]
device_id = a_device["id"]
device_type = a_device["device_type_id"]
sensor_address = self.get_parameter(a_device, "address")
self.device_list.update({device_id: {'name': device_name, 'named': sensor_address}})
self.log.info(
u"==> Device '{0}' (id:{1}/{2}), name = {3}".format(device_name, device_id, device_type, sensor_address))
self.log.debug(u"==> Sensor list of device '{0}': '{1}'".format(device_id, self.sensors[device_id]))
self.ebusdclass.add_sensor(device_id, device_name, device_type, sensor_address)

thread_sensors = threading.Thread(None,
self.ebusdclass.read_bus_for_sensor,
'Main_reading_sensors',
(self.send_pub_data, self.send_data, self.get_stop()),
{})
thread_sensors.start()
self.register_thread(thread_sensors)
self.ready()

def send_pub_data(self, device_id, value):
""" Send the sensors values over MQ
"""
self.log.debug(u"send_pub_data : '%s' for device_id: '%s' " % (value, device_id))
data = {}
value_dumps = json.dumps(value)
value_dict = json.loads(value_dumps)
for sensor in self.sensors[device_id]:
data[self.sensors[device_id][sensor]] = value_dict[sensor]
self.log.debug(u"value receive : '%s' for sensors: '%s' " % (value_dict[sensor], sensor))
self.log.debug(u"==> Update Sensor '%s' for device id %s (%s)" % (
format(data), device_id, self.device_list[device_id]["name"])) # {u'id': u'value'}

try:
self._pub.send_event('client.sensor', data)
except:
# We ignore the message if some values are not correct
self.log.debug(u"Bad MQ message to send.MQ data is : {0}".format(data))
pass

# -------------------------------------------------------------------------------------------------
def send_data(self, device_id, sensor_name, value):
""" Send the sensors values over MQ
"""
self.log.debug(u"send_data : '%s' for sensor '%s' for device_id: '%s' " % (value, sensor_name, device_id))
sensor_id = self.sensors[device_id][sensor_name]
data = {sensor_id: value}
try:
self._pub.send_event('client.sensor', data)
return True, None
except:
self.log.debug(
u"Error while sending sensor MQ message for sensor values : {0}".format(traceback.format_exc()))
return False, u"Error while sending sensor MQ message for sensor values : {0}".format(
traceback.format_exc())


if __name__ == "__main__":
ebusdManager()
Empty file added conversion/__init__.py
Empty file.
1 change: 1 addition & 0 deletions design/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
icon PNG format, 96*96 px, Be GPL compliant (don’t use private or non free existing icons)
8 changes: 8 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=========
Changelog
=========

0.1
===

* Plugin creation
23 changes: 23 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import sys
import os

extensions = [
'sphinx.ext.todo',
]

source_suffix = '.txt'

master_doc = 'index'

### part to update ###################################
project = u'domogik-plugin-ebusd'
copyright = u'2016, Tikismoke'
version = '0.1'
release = version
######################################################

pygments_style = 'sphinx'

html_theme = 'default'
html_static_path = ['_static']
Empty file added docs/dev.txt
Empty file.
71 changes: 71 additions & 0 deletions docs/ebusd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.. _index:

===================
Plugin ebusd
===================

Purpose
=======

.. raw:: html

<br />
<hr>

Dependencies
============

.. raw:: html

<br />
<hr>

Plugin configuration
====================

.. raw:: html

<br />
<hr>

Create the devices
==================

Device parameters configuration
-------------------------------

X parameters are needed for a domogik device creation ...


===================== =========================== ======================================================================
Key Type Description
===================== =========================== ======================================================================
key1 datatype ...
--------------------- --------------------------- ----------------------------------------------------------------------
key2 datatype ...
===================== =========================== ======================================================================


.. raw:: html

<br />
<hr>

Start the plugin
================

You can now start the plugin (start button) and use the created devices.

.. raw:: html

<br />
<hr>

Set up your widgets on the user interface
=========================================

You can now place the widgets of your devices features on the user interface.

.. raw:: html

<br />
12 changes: 12 additions & 0 deletions docs/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. _toc:

================
Table Of Content
================

.. toctree::

/ebusd
/dev
/tests
/changelog
Empty file added docs/tests.txt
Empty file.
Loading

0 comments on commit 652e425

Please sign in to comment.