Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

# -*- coding: utf-8 -*- 

"""The Roomba Janitoo helper 

It handle all communications to the Roomba vacuum 

 

 

 

""" 

 

__license__ = """ 

    This file is part of Janitoo. 

 

    Janitoo 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. 

 

    Janitoo 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 Janitoo. If not, see <http://www.gnu.org/licenses/>. 

 

""" 

__author__ = 'Sébastien GALLET aka bibi21000' 

__email__ = 'bibi21000@gmail.com' 

__copyright__ = "Copyright © 2013-2014-2015-2016 Sébastien GALLET aka bibi21000" 

 

# Set default logging handler to avoid "No handler found" warnings. 

import logging 

logger = logging.getLogger(__name__) 

import os, sys 

import threading 

import time 

from datetime import datetime, timedelta 

from subprocess import Popen, PIPE 

import base64 

from subprocess import Popen, PIPE 

import re 

import socket 

from janitoo.thread import JNTThread 

from janitoo.options import get_option_autostart 

from janitoo.utils import HADD, HADD_SEP, json_dumps, json_loads 

from janitoo.node import JNTNode 

from janitoo.value import JNTValue 

from janitoo.component import JNTComponent 

from janitoo.bus import JNTBus 

from janitoo.classes import COMMAND_DESC 

 

from janitoo_tellstick import OID 

 

############################################################## 

#Check that we are in sync with the official command classes 

#Must be implemented for non-regression 

from janitoo.classes import COMMAND_DESC 

 

COMMAND_DISPLAY = 0x0061 

COMMAND_AV_CHANNEL = 0x2100 

COMMAND_AV_VOLUME = 0x2101 

COMMAND_NOTIFY = 0x3010 

 

assert(COMMAND_DESC[COMMAND_DISPLAY] == 'COMMAND_DISPLAY') 

assert(COMMAND_DESC[COMMAND_AV_CHANNEL] == 'COMMAND_AV_CHANNEL') 

assert(COMMAND_DESC[COMMAND_AV_VOLUME] == 'COMMAND_AV_VOLUME') 

assert(COMMAND_DESC[COMMAND_NOTIFY] == 'COMMAND_NOTIFY') 

############################################################## 

 

def make_device(**kwargs): 

    return TellstickDevice(**kwargs) 

 

def make_sensor(**kwargs): 

    return TellstickSensor(**kwargs) 

 

def make_switch(**kwargs): 

    return TellstickSwitch(**kwargs) 

 

def make_dimmer(**kwargs): 

    return TellstickDimmer(**kwargs) 

 

def make_shutter(**kwargs): 

    return TellstickShutter(**kwargs) 

 

def make_bell(**kwargs): 

    return TellstickBell(**kwargs) 

 

class TellstickDevice(JNTComponent): 

    """ Provides the interface for a DS18B20 device. """ 

 

    def __init__(self, bus=None, addr=None, **kwargs): 

        """ Constructor. 

 

        Arguments: 

            bus: 

                a 1-Wire instance representing the bus this device is 

                connected to 

            addr: 

                the 1-Wire device address (in 7 bits format) 

        """ 

        oid = kwargs.pop('oid', '%s.device'%OID) 

        product_name = kwargs.pop('product_name', "Telldus device") 

        product_type = kwargs.pop('product_type', "Telldus device") 

        product_manufacturer = kwargs.pop('product_manufacturer', "Janitoo") 

        name = kwargs.pop('name', "Telldus device") 

        JNTComponent.__init__(self, oid=oid, bus=bus, addr=addr, name=name, product_name=product_name, product_type=product_type, product_manufacturer=product_manufacturer) 

 

class TellstickSensor(JNTComponent): 

    """ Provides the interface for a DS18B20 device. """ 

 

    def __init__(self, bus=None, addr=None, **kwargs): 

        """ Constructor. 

 

        Arguments: 

            bus: 

                a 1-Wire instance representing the bus this device is 

                connected to 

            addr: 

                the 1-Wire device address (in 7 bits format) 

        """ 

        oid = kwargs.pop('oid', '%s.sensor'%OID) 

        product_name = kwargs.pop('product_name', "Telldus sensor") 

        product_type = kwargs.pop('product_type', "Telldus sensor") 

        product_manufacturer = kwargs.pop('product_manufacturer', "Janitoo") 

        name = kwargs.pop('name', "Telldus sensor") 

        JNTComponent.__init__(self, oid=oid, bus=bus, addr=addr, name=name, product_name=product_name, product_type=product_type, product_manufacturer=product_manufacturer) 

 

class TellstickSwitch(JNTComponent): 

    """ Provides the interface for a DS18B20 device. """ 

 

    def __init__(self, bus=None, addr=None, **kwargs): 

        """ Constructor. 

 

        Arguments: 

            bus: 

                a 1-Wire instance representing the bus this device is 

                connected to 

            addr: 

                the 1-Wire device address (in 7 bits format) 

        """ 

        oid = kwargs.pop('oid', '%s.switch'%OID) 

        product_name = kwargs.pop('product_name', "Telldus switch") 

        product_type = kwargs.pop('product_type', "Telldus switch") 

        product_manufacturer = kwargs.pop('product_manufacturer', "Janitoo") 

        name = kwargs.pop('name', "Telldus switch") 

        JNTComponent.__init__(self, oid=oid, bus=bus, addr=addr, name=name, product_name=product_name, product_type=product_type, product_manufacturer=product_manufacturer) 

 

class TellstickDimmer(JNTComponent): 

    """ Provides the interface for a DS18B20 device. """ 

 

    def __init__(self, bus=None, addr=None, **kwargs): 

        """ Constructor. 

 

        Arguments: 

            bus: 

                a 1-Wire instance representing the bus this device is 

                connected to 

            addr: 

                the 1-Wire device address (in 7 bits format) 

        """ 

        oid = kwargs.pop('oid', '%s.dimmer'%OID) 

        product_name = kwargs.pop('product_name', "Telldus dimmer") 

        product_type = kwargs.pop('product_type', "Telldus dimmer") 

        product_manufacturer = kwargs.pop('product_manufacturer', "Janitoo") 

        name = kwargs.pop('name', "Telldus dimmer") 

        JNTComponent.__init__(self, oid=oid, bus=bus, addr=addr, name=name, product_name=product_name, product_type=product_type, product_manufacturer=product_manufacturer) 

 

class TellstickShutter(JNTComponent): 

    """ Provides the interface for a DS18B20 device. """ 

 

    def __init__(self, bus=None, addr=None, **kwargs): 

        """ Constructor. 

 

        Arguments: 

            bus: 

                a 1-Wire instance representing the bus this device is 

                connected to 

            addr: 

                the 1-Wire device address (in 7 bits format) 

        """ 

        oid = kwargs.pop('oid', '%s.shutter'%OID) 

        product_name = kwargs.pop('product_name', "Telldus shutter") 

        product_type = kwargs.pop('product_type', "Telldus shutter") 

        product_manufacturer = kwargs.pop('product_manufacturer', "Janitoo") 

        name = kwargs.pop('name', "Telldus shutter") 

        JNTComponent.__init__(self, oid=oid, bus=bus, addr=addr, name=name, product_name=product_name, product_type=product_type, product_manufacturer=product_manufacturer) 

 

class TellstickBell(JNTComponent): 

    """ Provides the interface for a DS18B20 device. """ 

 

    def __init__(self, bus=None, addr=None, **kwargs): 

        """ Constructor. 

 

        Arguments: 

            bus: 

                a 1-Wire instance representing the bus this device is 

                connected to 

            addr: 

                the 1-Wire device address (in 7 bits format) 

        """ 

        oid = kwargs.pop('oid', '%s.bell'%OID) 

        product_name = kwargs.pop('product_name', "Telldus bell") 

        product_type = kwargs.pop('product_type', "Telldus bell") 

        product_manufacturer = kwargs.pop('product_manufacturer', "Janitoo") 

        name = kwargs.pop('name', "Telldus bell") 

        JNTComponent.__init__(self, oid=oid, bus=bus, addr=addr, name=name, product_name=product_name, product_type=product_type, product_manufacturer=product_manufacturer)