Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
domotikad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
domotika
domotikad
Commits
1b6125b6
Commit
1b6125b6
authored
Feb 15, 2014
by
nextime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean code avoiding duplication and with better separation for board modules
parent
bae6cf0f
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
320 additions
and
658 deletions
+320
-658
boardtype.py
domotika/boards/boardtype.py
+297
-0
iboards.py
domotika/boards/iboards.py
+1
-1
iotype.py
domotika/boards/iotype.py
+0
-32
DMRv1.py
domotika/boards/modules/DMRv1.py
+5
-212
DMRv3.py
domotika/boards/modules/DMRv3.py
+5
-210
DMSnt84.py
domotika/boards/modules/DMSnt84.py
+8
-200
pluggable.py
domotika/boards/pluggable.py
+2
-1
domotika.py
domotika/domotika.py
+2
-2
No files found.
domotika/boards/boardtype.py
0 → 100644
View file @
1b6125b6
This diff is collapsed.
Click to expand it.
domotika/boards/iboards.py
View file @
1b6125b6
...
...
@@ -34,7 +34,7 @@ log = logging.getLogger( 'Core' )
class
IDMBoards
(
Interface
):
""" Base plugin Interface """
def
getBoard
(
self
,
host
,
port
,
pwd
):
def
getBoard
(
self
,
host
,
port
,
pwd
,
lang
):
"""
Return a DMBoard object
"""
...
...
domotika/boards/iotype.py
View file @
1b6125b6
...
...
@@ -26,38 +26,6 @@ from dmlib import constants as C
from
zope.interface
import
implements
import
iboards
log
=
logging
.
getLogger
(
'Core'
)
def
context2section
(
ctx
):
if
int
(
ctx
)
in
C
.
SECTIONS
.
keys
():
section
=
C
.
SECTIONS
[
int
(
ctx
)]
else
:
section
=
"none"
return
section
class
BaseBoard
(
object
):
""" """
implements
(
iboards
.
IBoard
)
analist
=
False
inplist
=
False
rellist
=
False
outlist
=
False
hasAnalogs
=
False
hasOutputs
=
False
hasInputs
=
False
hasPWMs
=
False
hasRelays
=
False
pwd
=
False
user
=
"system"
def
requestPage
(
self
,
uri
):
return
wu
.
getPage
(
uri
,
http_user
=
self
.
user
,
http_password
=
self
.
pwd
)
class
BoardAnalog
(
object
):
""" """
implements
(
iboards
.
IBoardAnalog
)
...
...
domotika/boards/modules/DMRv1.py
View file @
1b6125b6
...
...
@@ -22,16 +22,9 @@
##############################################################################
from
domotika.boards
import
iboards
from
domotika.boards.iotype
import
BaseBoard
,
BoardAnalog
,
BoardInput
,
BoardOutput
,
BoardRelay
,
context2section
from
domotika.db
import
dmdb
from
domotika.lang
import
lang
from
domotika.boards.boardtype
import
BaseBoard
,
ANABoard
,
INPBoard
,
OUTBoard
from
zope.interface
import
implements
from
twisted.plugin
import
IPlugin
from
dmlib.utils
import
webutils
as
wu
from
twisted.internet
import
defer
from
dmlib
import
constants
as
C
from
twisted.web
import
microdom
as
xml
import
logging
try
:
import
hashlib
...
...
@@ -42,221 +35,21 @@ except:
import
md5
import
sha1
log
=
logging
.
getLogger
(
'Core'
)
class
DMBoard
(
ANABoard
,
INPBoard
,
OUTBoard
,
BaseBoard
):
class
DMBoard
(
BaseBoard
):
analist
=
False
inplist
=
False
rellist
=
False
outlist
=
False
hasAnalogs
=
True
hasOutputs
=
True
hasInputs
=
True
hasRelays
=
True
hasAmperometers
=
False
def
__init__
(
self
,
host
,
port
,
pwd
,
lang
):
self
.
fwtype
=
'relaymaster'
self
.
host
=
host
self
.
port
=
port
self
.
pwd
=
pwd
self
.
lang
=
lang
def
initialize
(
self
):
d
=
self
.
_getBoardConfig
()
d
.
addCallback
(
self
.
_setBoardConfig
)
d
.
addCallback
(
self
.
_getIOConfig
)
d
.
addCallback
(
self
.
_setIOConfig
)
d
.
addCallback
(
self
.
_configComplete
)
return
d
def
_configComplete
(
self
,
*
a
):
return
defer
.
succeed
(
self
)
def
_setBoardConfig
(
self
,
res
):
self
.
boardXML
=
xml
.
parseXMLString
(
res
)
return
defer
.
succeed
(
True
)
def
_setIOConfig
(
self
,
res
):
xmlsha
=
sha1
()
xmlsha
.
update
(
res
)
self
.
iohash
=
xmlsha
.
hexdigest
()
self
.
ioXML
=
xml
.
parseXMLString
(
res
)
return
defer
.
succeed
(
True
)
def
_getBoardConfig
(
self
,
*
a
):
return
self
.
requestPage
(
"http://"
+
self
.
host
+
":"
+
str
(
self
.
port
)
+
"/ajax.xml"
)
def
_getIOConfig
(
self
,
*
a
):
return
self
.
requestPage
(
"http://"
+
self
.
host
+
":"
+
str
(
self
.
port
)
+
"/ioconf.xml"
)
def
getAnalogsNames
(
self
):
if
not
self
.
analist
:
ret
=
{}
for
i
in
[
13
,
14
]:
ana
=
BoardAnalog
()
ana
.
name
=
xml
.
getElementsByTagName
(
self
.
ioXML
,
'i'
+
str
(
i
))[
0
]
.
firstChild
()
.
toxml
()
ana
.
num
=
i
-
12
ana
.
host
=
self
.
host
ana
.
section
=
'none'
ana
.
enabled
=
1
ana
.
button_name
=
ana
.
name
.
replace
(
"."
,
" "
)
.
capitalize
()
ret
[
ana
.
num
]
=
ana
self
.
analist
=
ret
return
ret
return
self
.
analist
def
getInputsNames
(
self
):
if
not
self
.
inplist
:
ret
=
{}
for
i
in
xrange
(
1
,
13
):
inp
=
BoardInput
()
inp
.
name
=
xml
.
getElementsByTagName
(
self
.
ioXML
,
'i'
+
str
(
i
))[
0
]
.
firstChild
()
.
toxml
()
inp
.
num
=
i
inp
.
host
=
self
.
host
inp
.
section
=
'none'
inp
.
enabled
=
1
inp
.
button_name
=
inp
.
name
.
replace
(
"."
,
" "
)
.
capitalize
()
ret
[
inp
.
num
]
=
inp
self
.
inplist
=
ret
return
ret
return
self
.
inplist
def
getRelaysConfs
(
self
):
if
not
self
.
rellist
:
self
.
rellist
=
{}
self
.
getOutputsConfs
()
return
self
.
rellist
def
getOutputsConfs
(
self
):
if
not
self
.
outlist
:
if
not
self
.
rellist
:
self
.
rellist
=
{}
ret
=
{}
rel
=
{}
for
i
in
xrange
(
1
,
13
):
out
=
BoardOutput
()
out
.
num
=
i
out
.
hasRelays
=
True
out
.
hasPwms
=
False
out
.
hasAmperometers
=
self
.
hasAmperometers
rel
[
1
],
rel
[
2
]
=
BoardRelay
(),
BoardRelay
()
outstring
=
xml
.
getElementsByTagName
(
self
.
ioXML
,
'o'
+
str
(
i
))[
0
]
.
firstChild
()
.
toxml
()
if
';'
in
outstring
:
data
=
outstring
.
replace
(
" "
,
""
)
.
split
(
";"
)
else
:
data
=
outstring
.
replace
(
" "
,
""
)
.
split
(
"|"
)
out
.
dname
=
data
[
0
]
out
.
button_name
=
out
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
out
.
ctx
=
data
[
1
]
out
.
section
=
context2section
(
out
.
ctx
)
out
.
runtime1
=
data
[
2
]
out
.
runtime2
=
data
[
3
]
if
len
(
data
)
>
16
:
out
.
breakdelay1
=
data
[
4
]
out
.
rearm1
=
data
[
5
]
out
.
breakdelay2
=
data
[
6
]
out
.
rearm2
=
data
[
7
]
out
.
retard1
=
data
[
8
]
out
.
retard2
=
data
[
9
]
out
.
relay1
=
data
[
10
]
out
.
relay2
=
data
[
11
]
out
.
nanc1
=
data
[
12
]
out
.
nanc2
=
data
[
13
]
out
.
amax1
=
data
[
14
]
out
.
amax2
=
data
[
15
]
out
.
otype
=
data
[
16
]
out
.
enabled
=
data
[
17
]
else
:
out
.
breakdelay1
=
data
[
4
]
out
.
rearm1
=
0
out
.
breakdelay2
=
data
[
5
]
out
.
rearm2
=
0
out
.
retard1
=
data
[
6
]
out
.
retard2
=
data
[
7
]
out
.
relay1
=
data
[
8
]
out
.
relay2
=
data
[
9
]
out
.
nanc1
=
data
[
10
]
out
.
nanc2
=
data
[
11
]
out
.
amax1
=
data
[
12
]
out
.
amax2
=
data
[
13
]
out
.
otype
=
data
[
14
]
out
.
enabled
=
data
[
15
]
out
.
host
=
self
.
host
rel
[
1
]
.
host
,
rel
[
2
]
.
host
=
out
.
host
,
out
.
host
rel
[
1
]
.
dname
,
rel
[
2
]
.
dname
=
out
.
dname
,
out
.
dname
rel
[
1
]
.
ctx
,
rel
[
2
]
.
ctx
=
out
.
ctx
,
out
.
ctx
rel
[
1
]
.
section
,
rel
[
2
]
.
section
=
out
.
section
,
out
.
section
rel
[
1
]
.
runtime
=
out
.
runtime1
rel
[
2
]
.
runtime
=
out
.
runtime2
rel
[
1
]
.
breakdelay
=
out
.
breakdelay1
rel
[
1
]
.
rearm
=
out
.
rearm1
rel
[
2
]
.
breakdelay
=
out
.
breakdelay2
rel
[
2
]
.
rearm
=
out
.
rearm2
rel
[
1
]
.
retard
=
out
.
retard1
rel
[
2
]
.
retard
=
out
.
retard2
rel
[
1
]
.
num
=
out
.
relay1
rel
[
2
]
.
num
=
out
.
relay2
rel
[
1
]
.
nanc
=
out
.
nanc1
rel
[
2
]
.
nanc
=
out
.
nanc2
rel
[
1
]
.
amax
=
out
.
amax1
rel
[
2
]
.
amax
=
out
.
amax2
rel
[
1
]
.
otype
,
rel
[
2
]
.
otype
=
out
.
otype
,
out
.
otype
rel
[
1
]
.
enabled
,
rel
[
2
]
.
enabled
=
out
.
enabled
,
out
.
enabled
rel
[
1
]
.
outnum
,
rel
[
2
]
.
outnum
=
i
,
i
for
r
in
rel
.
keys
():
if
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_ONOFF
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_SIGNALING
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_NOTIFY
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_EXCLUSIVE
:
if
r
==
1
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_UP
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"up"
,
self
.
lang
)
else
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_DOWN
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"down"
,
self
.
lang
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_INCLUSIVE_ON
\
or
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_INCLUSIVE_OFF
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
str
(
r
)
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_OPEN_CLOSE_2_RELAYS
:
if
r
==
1
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_OPEN
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"open"
,
self
.
lang
)
else
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CLOSE
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"close"
,
self
.
lang
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
else
:
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_NULL
rel
[
r
]
.
act
=
C
.
IKAP_ACT_NULL
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
out
.
numrel
=
1
out
.
relays
=
[
rel
[
1
]]
self
.
rellist
[
rel
[
1
]
.
num
]
=
rel
[
1
]
if
int
(
out
.
otype
)
>=
C
.
DM_OUTPUT_TYPE_2_RELAY_EXCLUSIVE
:
out
.
numrel
=
2
out
.
relays
.
append
(
rel
[
2
])
self
.
rellist
[
rel
[
2
]
.
num
]
=
rel
[
2
]
ret
[
out
.
num
]
=
out
self
.
outlist
=
ret
return
self
.
outlist
fwtype
=
'relaymaster'
class
Board
(
object
):
implements
(
IPlugin
,
iboards
.
IDMBoards
)
def
getBoard
(
self
,
host
,
port
,
pwd
,
lang
):
return
DMBoard
(
host
,
port
,
pwd
,
lang
)
def
getBoard
(
self
,
core
,
host
,
port
,
pwd
,
lang
):
return
DMBoard
(
core
,
host
,
port
,
pwd
,
lang
)
board
=
Board
()
domotika/boards/modules/DMRv3.py
View file @
1b6125b6
...
...
@@ -22,15 +22,9 @@
##############################################################################
from
domotika.boards
import
iboards
from
domotika.boards.iotype
import
BaseBoard
,
BoardAnalog
,
BoardInput
,
BoardOutput
,
BoardRelay
,
context2section
from
domotika.db
import
dmdb
from
domotika.lang
import
lang
from
domotika.boards.boardtype
import
BaseBoard
,
ANABoard
,
INPBoard
,
OUTBoard
from
zope.interface
import
implements
from
twisted.plugin
import
IPlugin
from
dmlib.utils
import
webutils
as
wu
from
twisted.internet
import
defer
from
dmlib
import
constants
as
C
from
twisted.web
import
microdom
as
xml
try
:
...
...
@@ -43,218 +37,19 @@ except:
import
sha1
class
DMBoard
(
BaseBoard
):
class
DMBoard
(
INPBoard
,
ANABoard
,
OUTBoard
,
BaseBoard
):
analist
=
False
inplist
=
False
rellist
=
False
outlist
=
False
hasAnalogs
=
True
hasOutputs
=
True
hasInputs
=
True
hasRelays
=
True
hasAmperometers
=
True
def
__init__
(
self
,
host
,
port
,
pwd
,
lang
):
self
.
fwtype
=
'relaymaster'
self
.
host
=
host
self
.
port
=
port
self
.
pwd
=
pwd
self
.
lang
=
lang
def
initialize
(
self
):
d
=
self
.
_getBoardConfig
()
d
.
addCallback
(
self
.
_setBoardConfig
)
d
.
addCallback
(
self
.
_getIOConfig
)
d
.
addCallback
(
self
.
_setIOConfig
)
d
.
addCallback
(
self
.
_configComplete
)
return
d
def
_configComplete
(
self
,
*
a
):
return
defer
.
succeed
(
self
)
def
_setBoardConfig
(
self
,
res
):
self
.
boardXML
=
xml
.
parseXMLString
(
res
)
return
defer
.
succeed
(
True
)
def
_setIOConfig
(
self
,
res
):
xmlsha
=
sha1
()
xmlsha
.
update
(
res
)
self
.
iohash
=
xmlsha
.
hexdigest
()
self
.
ioXML
=
xml
.
parseXMLString
(
res
)
return
defer
.
succeed
(
True
)
def
_getBoardConfig
(
self
,
*
a
):
return
self
.
requestPage
(
"http://"
+
self
.
host
+
":"
+
str
(
self
.
port
)
+
"/ajax.xml"
)
def
_getIOConfig
(
self
,
*
a
):
return
self
.
requestPage
(
"http://"
+
self
.
host
+
":"
+
str
(
self
.
port
)
+
"/ioconf.xml"
)
def
getAnalogsNames
(
self
):
if
not
self
.
analist
:
ret
=
{}
for
i
in
[
13
,
14
]:
ana
=
BoardAnalog
()
ana
.
name
=
xml
.
getElementsByTagName
(
self
.
ioXML
,
'i'
+
str
(
i
))[
0
]
.
firstChild
()
.
toxml
()
ana
.
num
=
i
-
12
ana
.
host
=
self
.
host
ana
.
section
=
'none'
ana
.
enabled
=
1
ana
.
button_name
=
ana
.
name
.
replace
(
"."
,
" "
)
.
capitalize
()
ret
[
ana
.
num
]
=
ana
self
.
analist
=
ret
return
ret
return
self
.
analist
def
getInputsNames
(
self
):
if
not
self
.
inplist
:
ret
=
{}
for
i
in
xrange
(
1
,
13
):
inp
=
BoardInput
()
inp
.
name
=
xml
.
getElementsByTagName
(
self
.
ioXML
,
'i'
+
str
(
i
))[
0
]
.
firstChild
()
.
toxml
()
inp
.
num
=
i
inp
.
host
=
self
.
host
inp
.
section
=
'none'
inp
.
enabled
=
1
inp
.
button_name
=
inp
.
name
.
replace
(
"."
,
" "
)
.
capitalize
()
ret
[
inp
.
num
]
=
inp
self
.
inplist
=
ret
return
ret
return
self
.
inplist
def
getRelaysConfs
(
self
):
if
not
self
.
rellist
:
self
.
rellist
=
{}
self
.
getOutputsConfs
()
return
self
.
rellist
def
getOutputsConfs
(
self
):
if
not
self
.
outlist
:
if
not
self
.
rellist
:
self
.
rellist
=
{}
ret
=
{}
rel
=
{}
for
i
in
xrange
(
1
,
13
):
out
=
BoardOutput
()
out
.
hasRelays
=
True
out
.
hasPwms
=
False
out
.
hasAmperometers
=
self
.
hasAmperometers
out
.
num
=
i
rel
[
1
],
rel
[
2
]
=
BoardRelay
(),
BoardRelay
()
outstring
=
xml
.
getElementsByTagName
(
self
.
ioXML
,
'o'
+
str
(
i
))[
0
]
.
firstChild
()
.
toxml
()
if
';'
in
outstring
:
data
=
outstring
.
replace
(
" "
,
""
)
.
split
(
";"
)
else
:
data
=
outstring
.
replace
(
" "
,
""
)
.
split
(
"|"
)
out
.
dname
=
data
[
0
]
out
.
button_name
=
out
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
out
.
ctx
=
data
[
1
]
out
.
section
=
context2section
(
out
.
ctx
)
out
.
runtime1
=
data
[
2
]
out
.
runtime2
=
data
[
3
]
if
len
(
data
)
>
16
:
out
.
breakdelay1
=
data
[
4
]
out
.
rearm1
=
data
[
5
]
out
.
breakdelay2
=
data
[
6
]
out
.
rearm2
=
data
[
7
]
out
.
retard1
=
data
[
8
]
out
.
retard2
=
data
[
9
]
out
.
relay1
=
data
[
10
]
out
.
relay2
=
data
[
11
]
out
.
nanc1
=
data
[
12
]
out
.
nanc2
=
data
[
13
]
out
.
amax1
=
data
[
14
]
out
.
amax2
=
data
[
15
]
out
.
otype
=
data
[
16
]
out
.
enabled
=
data
[
17
]
else
:
out
.
breakdelay1
=
data
[
4
]
out
.
rearm1
=
0
out
.
breakdelay2
=
data
[
5
]
out
.
rearm1
=
0
out
.
retard1
=
data
[
6
]
out
.
retard2
=
data
[
7
]
out
.
relay1
=
data
[
8
]
out
.
relay2
=
data
[
9
]
out
.
nanc1
=
data
[
10
]
out
.
nanc2
=
data
[
11
]
out
.
amax1
=
data
[
12
]
out
.
amax2
=
data
[
13
]
out
.
otype
=
data
[
14
]
out
.
enabled
=
data
[
15
]
out
.
host
=
self
.
host
rel
[
1
]
.
host
,
rel
[
2
]
.
host
=
out
.
host
,
out
.
host
rel
[
1
]
.
dname
,
rel
[
2
]
.
dname
=
out
.
dname
,
out
.
dname
rel
[
1
]
.
ctx
,
rel
[
2
]
.
ctx
=
out
.
ctx
,
out
.
ctx
rel
[
1
]
.
section
,
rel
[
2
]
.
section
=
out
.
section
,
out
.
section
rel
[
1
]
.
runtime
=
out
.
runtime1
rel
[
2
]
.
runtime
=
out
.
runtime2
rel
[
1
]
.
breakdelay
=
out
.
breakdelay1
rel
[
1
]
.
rearm
=
out
.
rearm1
rel
[
2
]
.
breakdelay
=
out
.
breakdelay2
rel
[
2
]
.
rearm
=
out
.
rearm2
rel
[
1
]
.
retard
=
out
.
retard1
rel
[
2
]
.
retard
=
out
.
retard2
rel
[
1
]
.
num
=
out
.
relay1
rel
[
2
]
.
num
=
out
.
relay2
rel
[
1
]
.
nanc
=
out
.
nanc1
rel
[
2
]
.
nanc
=
out
.
nanc2
rel
[
1
]
.
amax
=
out
.
amax1
rel
[
2
]
.
amax
=
out
.
amax2
rel
[
1
]
.
otype
,
rel
[
2
]
.
otype
=
out
.
otype
,
out
.
otype
rel
[
1
]
.
enabled
,
rel
[
2
]
.
enabled
=
out
.
enabled
,
out
.
enabled
rel
[
1
]
.
outnum
,
rel
[
2
]
.
outnum
=
i
,
i
for
r
in
rel
.
keys
():
if
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_ONOFF
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_SIGNALING
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_NOTIFY
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_EXCLUSIVE
:
if
r
==
1
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_UP
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"up"
,
self
.
lang
)
else
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_DOWN
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"down"
,
self
.
lang
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_INCLUSIVE_ON
\
or
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_INCLUSIVE_OFF
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
str
(
r
)
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_OPEN_CLOSE_2_RELAYS
:
if
r
==
1
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_OPEN
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"open"
,
self
.
lang
)
else
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CLOSE
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"close"
,
self
.
lang
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
else
:
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_NULL
rel
[
r
]
.
act
=
C
.
IKAP_ACT_NULL
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
out
.
numrel
=
1
out
.
relays
=
[
rel
[
1
]]
self
.
rellist
[
rel
[
1
]
.
num
]
=
rel
[
1
]
if
int
(
out
.
otype
)
>=
C
.
DM_OUTPUT_TYPE_2_RELAY_EXCLUSIVE
:
out
.
numrel
=
2
out
.
relays
.
append
(
rel
[
2
])
self
.
rellist
[
rel
[
2
]
.
num
]
=
rel
[
2
]
ret
[
out
.
num
]
=
out
self
.
outlist
=
ret
return
self
.
outlist
fwtype
=
'relaymaster'
class
Board
(
object
):
implements
(
IPlugin
,
iboards
.
IDMBoards
)
def
getBoard
(
self
,
host
,
port
,
pwd
,
lang
):
return
DMBoard
(
host
,
port
,
pwd
,
lang
)
def
getBoard
(
self
,
core
,
host
,
port
,
pwd
,
lang
):
return
DMBoard
(
core
,
host
,
port
,
pwd
,
lang
)
board
=
Board
()
domotika/boards/modules/DMSnt84.py
View file @
1b6125b6
...
...
@@ -22,15 +22,9 @@
##############################################################################
from
domotika.boards
import
iboards
from
domotika.boards.iotype
import
BaseBoard
,
BoardAnalog
,
BoardInput
,
BoardOutput
,
BoardRelay
,
context2section
from
domotika.db
import
dmdb
from
domotika.lang
import
lang
from
domotika.boards.boardtype
import
BaseBoard
,
ANABoard
,
INPBoard
,
OUTBoard
from
zope.interface
import
implements
from
twisted.plugin
import
IPlugin
from
dmlib.utils
import
webutils
as
wu
from
twisted.internet
import
defer
from
dmlib
import
constants
as
C
from
twisted.web
import
microdom
as
xml
try
:
import
hashlib
...
...
@@ -42,208 +36,22 @@ except:
import
sha1
class
DMBoard
(
INPBoard
,
OUTBoard
,
BaseBoard
):
class
DMBoard
(
BaseBoard
):
analist
=
{}
inplist
=
False
rellist
=
False
outlist
=
False
hasAnalogs
=
False
hasOutputs
=
True
hasInputs
=
True
hasRelays
=
True
hasAmperometers
=
False
def
__init__
(
self
,
host
,
port
,
pwd
,
lang
):
self
.
fwtype
=
'relaymaster'
self
.
host
=
host
self
.
port
=
port
self
.
pwd
=
pwd
self
.
lang
=
lang
def
initialize
(
self
):
d
=
self
.
_getBoardConfig
()
d
.
addCallback
(
self
.
_setBoardConfig
)
d
.
addCallback
(
self
.
_getIOConfig
)
d
.
addCallback
(
self
.
_setIOConfig
)
d
.
addCallback
(
self
.
_configComplete
)
return
d
def
_configComplete
(
self
,
*
a
):
return
defer
.
succeed
(
self
)
def
_setBoardConfig
(
self
,
res
):
self
.
boardXML
=
xml
.
parseXMLString
(
res
)
return
defer
.
succeed
(
True
)
def
_setIOConfig
(
self
,
res
):
xmlsha
=
sha1
()
xmlsha
.
update
(
res
)
self
.
iohash
=
xmlsha
.
hexdigest
()
self
.
ioXML
=
xml
.
parseXMLString
(
res
)
return
defer
.
succeed
(
True
)
def
_getBoardConfig
(
self
,
*
a
):
return
self
.
requestPage
(
"http://"
+
self
.
host
+
":"
+
str
(
self
.
port
)
+
"/ajax.xml"
)
def
_getIOConfig
(
self
,
*
a
):
return
self
.
requestPage
(
"http://"
+
self
.
host
+
":"
+
str
(
self
.
port
)
+
"/ioconf.xml"
)
def
getAnalogsNames
(
self
):
return
self
.
analist
def
getInputsNames
(
self
):
if
not
self
.
inplist
:
ret
=
{}
for
i
in
xrange
(
1
,
9
):
inp
=
BoardInput
()
inp
.
name
=
xml
.
getElementsByTagName
(
self
.
ioXML
,
'i'
+
str
(
i
))[
0
]
.
firstChild
()
.
toxml
()
inp
.
num
=
i
inp
.
host
=
self
.
host
inp
.
section
=
'none'
inp
.
enabled
=
1
inp
.
button_name
=
inp
.
name
.
replace
(
"."
,
" "
)
.
capitalize
()
ret
[
inp
.
num
]
=
inp
self
.
inplist
=
ret
return
ret
return
self
.
inplist
def
getRelaysConfs
(
self
):
if
not
self
.
rellist
:
self
.
rellist
=
{}
self
.
getOutputsConfs
()
return
self
.
rellist
def
getOutputsConfs
(
self
):
if
not
self
.
outlist
:
if
not
self
.
rellist
:
self
.
rellist
=
{}
ret
=
{}
rel
=
{}
for
i
in
xrange
(
1
,
9
):
out
=
BoardOutput
()
out
.
hasRelays
=
True
out
.
hasPwms
=
False
out
.
hasAmperometers
=
self
.
hasAmperometers
out
.
num
=
i
rel
[
1
],
rel
[
2
]
=
BoardRelay
(),
BoardRelay
()
outstring
=
xml
.
getElementsByTagName
(
self
.
ioXML
,
'o'
+
str
(
i
))[
0
]
.
firstChild
()
.
toxml
()
if
';'
in
outstring
:
data
=
outstring
.
replace
(
" "
,
""
)
.
split
(
";"
)
else
:
data
=
outstring
.
replace
(
" "
,
""
)
.
split
(
"|"
)
out
.
dname
=
data
[
0
]
out
.
button_name
=
out
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
out
.
ctx
=
data
[
1
]
out
.
section
=
context2section
(
out
.
ctx
)
out
.
runtime1
=
data
[
2
]
out
.
runtime2
=
data
[
3
]
if
len
(
data
)
>
16
:
out
.
breakdelay1
=
data
[
4
]
out
.
rearm1
=
data
[
5
]
out
.
breakdelay2
=
data
[
6
]
out
.
rearm2
=
data
[
7
]
out
.
retard1
=
data
[
8
]
out
.
retard2
=
data
[
9
]
out
.
relay1
=
data
[
10
]
out
.
relay2
=
data
[
11
]
out
.
nanc1
=
data
[
12
]
out
.
nanc2
=
data
[
13
]
out
.
amax1
=
data
[
14
]
out
.
amax2
=
data
[
15
]
out
.
otype
=
data
[
16
]
out
.
enabled
=
data
[
17
]
else
:
out
.
breakdelay1
=
data
[
4
]
out
.
rearm1
=
0
out
.
breakdelay2
=
data
[
5
]
out
.
rearm1
=
0
out
.
retard1
=
data
[
6
]
out
.
retard2
=
data
[
7
]
out
.
relay1
=
data
[
8
]
out
.
relay2
=
data
[
9
]
out
.
nanc1
=
data
[
10
]
out
.
nanc2
=
data
[
11
]
out
.
amax1
=
data
[
12
]
out
.
amax2
=
data
[
13
]
out
.
otype
=
data
[
14
]
out
.
enabled
=
data
[
15
]
out
.
host
=
self
.
host
rel
[
1
]
.
host
,
rel
[
2
]
.
host
=
out
.
host
,
out
.
host
rel
[
1
]
.
dname
,
rel
[
2
]
.
dname
=
out
.
dname
,
out
.
dname
rel
[
1
]
.
ctx
,
rel
[
2
]
.
ctx
=
out
.
ctx
,
out
.
ctx
rel
[
1
]
.
section
,
rel
[
2
]
.
section
=
out
.
section
,
out
.
section
rel
[
1
]
.
runtime
=
out
.
runtime1
rel
[
2
]
.
runtime
=
out
.
runtime2
rel
[
1
]
.
breakdelay
=
out
.
breakdelay1
rel
[
1
]
.
rearm
=
out
.
rearm1
rel
[
2
]
.
breakdelay
=
out
.
breakdelay2
rel
[
2
]
.
rearm
=
out
.
rearm2
rel
[
1
]
.
retard
=
out
.
retard1
rel
[
2
]
.
retard
=
out
.
retard2
rel
[
1
]
.
num
=
out
.
relay1
rel
[
2
]
.
num
=
out
.
relay2
rel
[
1
]
.
nanc
=
out
.
nanc1
rel
[
2
]
.
nanc
=
out
.
nanc2
rel
[
1
]
.
amax
=
out
.
amax1
rel
[
2
]
.
amax
=
out
.
amax2
rel
[
1
]
.
otype
,
rel
[
2
]
.
otype
=
out
.
otype
,
out
.
otype
rel
[
1
]
.
enabled
,
rel
[
2
]
.
enabled
=
out
.
enabled
,
out
.
enabled
rel
[
1
]
.
outnum
,
rel
[
2
]
.
outnum
=
i
,
i
for
r
in
rel
.
keys
():
if
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_ONOFF
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_SIGNALING
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_NOTIFY
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_EXCLUSIVE
:
if
r
==
1
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_UP
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"up"
,
self
.
lang
)
else
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_DOWN
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"down"
,
self
.
lang
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_INCLUSIVE_ON
\
or
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_2_RELAY_INCLUSIVE_OFF
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CHANGE
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
str
(
r
)
elif
int
(
out
.
otype
)
==
C
.
DM_OUTPUT_TYPE_OPEN_CLOSE_2_RELAYS
:
if
r
==
1
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_OPEN
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"open"
,
self
.
lang
)
else
:
rel
[
r
]
.
act
=
int
(
C
.
IKAP_ACT_CLOSE
)
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
+
" "
+
lang
.
iostring
(
"close"
,
self
.
lang
)
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_ACTION
else
:
rel
[
r
]
.
msgtype
=
C
.
IKAP_MSG_NULL
rel
[
r
]
.
act
=
C
.
IKAP_ACT_NULL
rel
[
r
]
.
button_name
=
rel
[
r
]
.
dname
.
replace
(
"."
,
" "
)
.
capitalize
()
out
.
numrel
=
1
out
.
relays
=
[
rel
[
1
]]
self
.
rellist
[
rel
[
1
]
.
num
]
=
rel
[
1
]
if
int
(
out
.
otype
)
>=
C
.
DM_OUTPUT_TYPE_2_RELAY_EXCLUSIVE
:
out
.
numrel
=
2
out
.
relays
.
append
(
rel
[
2
])
self
.
rellist
[
rel
[
2
]
.
num
]
=
rel
[
2
]
ret
[
out
.
num
]
=
out
self
.
outlist
=
ret
return
self
.
outlist
fwtype
=
'relaymaster'
numAna
=
0
numInp
=
8
numOut
=
8
class
Board
(
object
):
implements
(
IPlugin
,
iboards
.
IDMBoards
)
def
getBoard
(
self
,
host
,
port
,
pwd
,
lang
):
return
DMBoard
(
host
,
port
,
pwd
,
lang
)
def
getBoard
(
self
,
core
,
host
,
port
,
pwd
,
lang
):
return
DMBoard
(
core
,
host
,
port
,
pwd
,
lang
)
board
=
Board
()
domotika/boards/pluggable.py
View file @
1b6125b6
...
...
@@ -11,11 +11,12 @@ else:
list
(
getPlugins
(
iboards
.
IDMBoards
,
modules
))
# To refresh cache
def
getBoardPlugin
(
name
):
def
getBoardPlugin
(
name
,
core
=
False
):
for
p
in
getPlugins
(
iboards
.
IDMBoards
,
modules
):
qual
=
"
%
s.
%
s"
%
(
p
.
__module__
,
p
.
__class__
.
__name__
)
log
.
info
(
"Calling Board Module "
+
qual
)
if
p
.
__module__
.
split
(
'.'
)[
-
1
]
==
name
:
p
.
core
=
core
return
p
return
None
...
...
domotika/domotika.py
View file @
1b6125b6
...
...
@@ -53,7 +53,7 @@ from asterisk import manager as ami
from
asterisk
import
fastagi
as
fagi
from
voiceui
import
voiceui
as
voice
from
boards
import
pluggable
as
pluggableBoards
from
boards.
io
type
import
context2section
from
boards.
board
type
import
context2section
from
mediasources
import
pluggable
as
pluggableMediasouces
import
sky
from
clouds.openweathermap
import
weather
...
...
@@ -796,7 +796,7 @@ class domotikaService(service.Service):
log
.
debug
(
" "
.
join
([
"ADDBoard"
,
str
(
name
),
str
(
btype
),
str
(
fwver
),
str
(
ip
)]))
p
=
pluggableBoards
.
getBoardPlugin
(
btype
)
if
p
:
pboard
=
p
.
getBoard
(
ip
,
webport
,
self
.
boardsyspwd
,
str
(
self
.
config
.
get
(
'general'
,
'language'
)))
pboard
=
p
.
getBoard
(
False
,
ip
,
webport
,
self
.
boardsyspwd
,
str
(
self
.
config
.
get
(
'general'
,
'language'
)))
log
.
info
(
"Support module for "
+
str
(
btype
)
+
" board LOADED"
)
pboard
.
initialize
()
.
addCallback
(
self
.
askForBoardData
,
btype
,
fwver
,
name
,
ptype
,
port
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment