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

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

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

"""The value 

 

""" 

 

__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 Sébastien GALLET aka bibi21000" 

 

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

import os 

import logging 

logger = logging.getLogger("janitoo") 

 

from janitoo.classes import GENRE_DESC, VALUE_DESC 

from janitoo.utils import json_dumps 

from janitoo.value import JNTValue 

from janitoo.value_factory import JNTValueFactoryEntry 

 

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

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

#Must be implemented for non-regression 

from janitoo.classes import COMMAND_DESC 

 

COMMAND_CONFIGURATION = 0x0070 

COMMAND_SENSOR_BINARY = 0x0030 

COMMAND_SENSOR_MULTILEVEL = 0x0031 

 

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

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

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

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

 

def make_sensor_temperature(**kwargs): 

    return JNTValueSensorTemperature(**kwargs) 

 

def make_sensor_voltage(**kwargs): 

    return JNTValueSensorVoltage(**kwargs) 

 

def make_sensor_current(**kwargs): 

    return JNTValueSensorCurrent(**kwargs) 

 

def make_sensor_percent(**kwargs): 

    return JNTValueSensorPercent(**kwargs) 

 

def make_sensor_frequency(**kwargs): 

    return JNTValueSensorFrequency(**kwargs) 

 

def make_sensor_rotation_speed(**kwargs): 

    return JNTValueSensorRotationSpeed(**kwargs) 

 

def make_sensor_integer(**kwargs): 

    return JNTValueSensorInteger(**kwargs) 

 

def make_sensor_byte(**kwargs): 

    return JNTValueSensorByte(**kwargs) 

 

def make_sensor_string(**kwargs): 

    return JNTValueSensorString(**kwargs) 

 

def make_sensor_orientation(**kwargs): 

    return JNTValueSensorOrientation(**kwargs) 

 

def make_sensor_memory(**kwargs): 

    return JNTValueSensorMemory(**kwargs) 

 

def make_sensor_float(**kwargs): 

    return JNTValueSensorFloat(**kwargs) 

 

class JNTValueSensorGeneric(JNTValueFactoryEntry): 

    """ 

    """ 

    def __init__(self, **kwargs): 

        """ 

        """ 

        genre = kwargs.pop('genre', 0x02) 

        is_readonly = kwargs.pop('is_readonly', True) 

        is_writeonly = kwargs.pop('is_writeonly', False) 

        JNTValueFactoryEntry.__init__(self, 

            genre=genre, 

            is_readonly=is_readonly, is_writeonly=is_writeonly, 

            **kwargs) 

 

    def create_poll_value(self, **kwargs): 

        """ 

        """ 

        default = kwargs.pop('default', 30) 

        return self._create_poll_value(default=default, **kwargs) 

 

class JNTValueSensorTemperature(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_temperature", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A temperature sensor') 

        label = kwargs.pop('label', 'Temp.') 

        units = kwargs.pop('units', '°C') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, units=units, 

            index=index, cmd_class=cmd_class, type=0x03, **kwargs) 

 

class JNTValueSensorVoltage(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_voltage", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A voltage sensor') 

        label = kwargs.pop('label', 'Voltage') 

        units = kwargs.pop('units', 'V') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, units=units, 

            index=index, cmd_class=cmd_class, type=0x03, **kwargs) 

 

class JNTValueSensorCurrent(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_current", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A current sensor') 

        label = kwargs.pop('label', 'Current') 

        units = kwargs.pop('units', 'A') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, units=units, 

            index=index, cmd_class=cmd_class, type=0x03, **kwargs) 

 

class JNTValueSensorPercent(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_percent", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A percent sensor') 

        label = kwargs.pop('label', 'Percentage') 

        units = kwargs.pop('units', '%') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, units=units, 

            index=index, cmd_class=cmd_class, type=0x03, **kwargs) 

 

class JNTValueSensorRotationSpeed(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_rotation_speed", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A rotation speed sensor') 

        label = kwargs.pop('label', 'Rot. speed') 

        units = kwargs.pop('units', 'rpm') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, units=units, 

            index=index, cmd_class=cmd_class, type=0x03, **kwargs) 

 

class JNTValueSensorFrequency(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_frequency", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A frequency sensor') 

        label = kwargs.pop('label', 'Frequency') 

        units = kwargs.pop('units', 'MHz') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, units=units, 

            index=index, cmd_class=cmd_class, type=0x03, **kwargs) 

 

class JNTValueSensorString(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_string", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A string sensor') 

        label = kwargs.pop('label', 'String') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, 

            index=index, cmd_class=cmd_class, type=0x08, **kwargs) 

 

class JNTValueSensorInteger(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_integer", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'An integer sensor') 

        label = kwargs.pop('label', 'Integer') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, 

            index=index, cmd_class=cmd_class, type=0x04, **kwargs) 

 

class JNTValueSensorByte(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_byte", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A byte sensor') 

        label = kwargs.pop('label', 'Byte') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, 

            index=index, cmd_class=cmd_class, type=0x02, **kwargs) 

 

class JNTValueSensorOrientation(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_orientation", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'An orientation sensor') 

        label = kwargs.pop('label', 'Orientation') 

        units = kwargs.pop('units', '°') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, 

            units=units, 

            index=index, cmd_class=cmd_class, type=0x04, **kwargs) 

 

class JNTValueSensorMemory(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_memory", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'An memory sensor') 

        label = kwargs.pop('label', 'Memory') 

        units = kwargs.pop('units', 'Bytes') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, 

            units=units, 

            index=index, cmd_class=cmd_class, type=0x04, **kwargs) 

 

class JNTValueSensorFloat(JNTValueSensorGeneric): 

    def __init__(self, entry_name="sensor_float", **kwargs): 

        """ 

        """ 

        help = kwargs.pop('help', 'A float sensor') 

        label = kwargs.pop('label', 'Float') 

        index = kwargs.pop('index', 0) 

        cmd_class = kwargs.pop('cmd_class', COMMAND_SENSOR_MULTILEVEL) 

        JNTValueSensorGeneric.__init__(self, entry_name=entry_name, help=help, label=label, 

            index=index, cmd_class=cmd_class, type=0x03, **kwargs)