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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
# -*- encoding: utf-8 -*-
from __future__ import print_function, unicode_literals, division, absolute_import
from enocean.protocol.packet import Packet
from enocean.protocol.eep import EEP
from enocean.protocol.constants import RORG
from enocean.decorators import timing
@timing(1000)
def test_temperature():
''' Tests RADIO message for EEP -profile 0xA5 0x02 0x05 '''
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x0A, 0x07, 0x01,
0xEB,
0xA5, 0x00, 0x00, 0x55, 0x08, 0x01, 0x81, 0xB7, 0x44, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x2D, 0x00,
0x75
]))
assert packet.parse_eep(0x02, 0x05) == ['TMP']
assert round(packet.parsed['TMP']['value'], 1) == 26.7
assert packet.parsed['TMP']['raw_value'] == 85
assert packet.learn is False
assert packet.contains_eep is False
assert packet.rorg == 0xA5
assert packet.rorg == int(RORG.BS4)
assert packet.rorg_func == 0x02
assert packet.rorg_type == 0x05
assert packet.status == 0x00
assert packet.repeater_count == 0
assert packet.sender == [0x01, 0x81, 0xB7, 0x44]
assert packet.sender_hex == '01:81:B7:44'
@timing(1000)
def test_magnetic_switch():
''' Tests RADIO message for EEP -profile 0xD5 0x00 0x01 '''
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x07, 0x07, 0x01,
0x7A,
0xD5, 0x08, 0x01, 0x82, 0x5D, 0xAB, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x36, 0x00,
0x53
]))
assert packet.parse_eep(0x00, 0x01) == ['CO']
assert packet.parsed['CO']['value'] == 'open'
assert packet.parsed['CO']['raw_value'] == 0
assert packet.status == 0x00
assert packet.repeater_count == 0
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x07, 0x07, 0x01,
0x7A,
0xD5, 0x09, 0x01, 0x82, 0x5D, 0xAB, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x36, 0x00,
0xC7
]))
assert packet.parse_eep(0x00, 0x01) == ['CO']
assert packet.parsed['CO']['value'] == 'closed'
assert packet.parsed['CO']['raw_value'] == 1
assert packet.learn is False
assert packet.status == 0x00
assert packet.repeater_count == 0
@timing(1000)
def test_switch():
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x07, 0x07, 0x01,
0x7A,
0xF6, 0x50, 0x00, 0x29, 0x89, 0x79, 0x30,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x37, 0x00,
0x9D
]))
assert packet.parse_eep(0x02, 0x02) == ['R1', 'EB', 'R2', 'SA', 'T21', 'NU']
assert packet.parsed['SA']['value'] == 'No 2nd action'
assert packet.parsed['EB']['value'] == 'pressed'
assert packet.parsed['R1']['value'] == 'Button BI'
assert packet.parsed['T21']['value'] is True
assert packet.parsed['NU']['value'] is True
assert packet.learn is True
assert packet.status == 0x30
assert packet.repeater_count == 0
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x07, 0x07, 0x01,
0x7A,
0xF6, 0x00, 0x00, 0x29, 0x89, 0x79, 0x20,
0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0x00,
0x03
]))
assert packet.parse_eep(0x02, 0x02) == ['R1', 'EB', 'R2', 'SA', 'T21', 'NU']
assert packet.parsed['SA']['value'] == 'No 2nd action'
assert packet.parsed['EB']['value'] == 'released'
assert packet.parsed['T21']['value'] is True
assert packet.parsed['NU']['value'] is False
assert packet.learn is True
assert packet.status == 0x20
assert packet.repeater_count == 0
@timing(1000)
def test_eep_parsing():
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x0A, 0x07, 0x01,
0xEB,
0xA5, 0x08, 0x28, 0x46, 0x80, 0x01, 0x8A, 0x7B, 0x30, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x49, 0x00,
0x26
]))
assert packet.learn is True
assert packet.contains_eep is True
assert packet.rorg_func == 0x02
assert packet.rorg_type == 0x05
assert packet.status == 0x00
assert packet.repeater_count == 0
@timing(1000)
def test_eep_remaining():
# Magnetic switch -example
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x07, 0x07, 0x01,
0x7A,
0xD5, 0x08, 0x01, 0x82, 0x5D, 0xAB, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x36, 0x00,
0x53
]))
assert packet.parse_eep(0x00, 0x01) == ['CO']
# Temperature-example
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x0A, 0x07, 0x01,
0xEB,
0xA5, 0x00, 0x00, 0x55, 0x08, 0x01, 0x81, 0xB7, 0x44, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x2D, 0x00,
0x75
]))
# If this fails, the data is retained from the last Packet parsing!
assert packet.parse_eep(0x00, 0x01) == []
# Once we have parse with the correct func and type, this should pass.
assert packet.parse_eep(0x02, 0x05) == ['TMP']
@timing(1000)
def test_eep_direction():
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x0A, 0x07, 0x01,
0xEB,
0xA5, 0x32, 0x20, 0x89, 0x00, 0xDE, 0xAD, 0xBE, 0xEF, 0x00,
0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0x43
]))
assert packet.parse_eep(0x20, 0x01, 1) == ['CV', 'SO', 'ENIE', 'ES', 'BCAP', 'CCO', 'FTS', 'DWO', 'ACO', 'TMP']
assert packet.parsed['CV']['value'] == 50
assert packet.parse_eep(0x20, 0x01, 2) == ['SP', 'TMP', 'RIN', 'LFS', 'VO', 'VC', 'SB', 'SPS', 'SPN', 'RCU']
assert packet.parsed['SP']['value'] == 50
@timing(1000)
def test_vld():
status, buf, p = Packet.parse_msg(bytearray([
0x55,
0x00, 0x09, 0x07, 0x01,
0x56,
0xD2, 0x04, 0x00, 0x64, 0x01, 0x94, 0xE3, 0xB9, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x00,
0xE4
]))
assert p.rorg == RORG.VLD
assert p.parse_eep(0x01, 0x01) == ['PF', 'PFD', 'CMD', 'OC', 'EL', 'IO', 'LC', 'OV']
assert p.parsed['EL']['raw_value'] == 0
assert p.parsed['EL']['value'] == 'Error level 0: hardware OK'
assert p.parsed['PF']['raw_value'] == 0
assert p.parsed['PF']['value'] == 'Power Failure Detection disabled/not supported'
assert p.parsed['PFD']['raw_value'] == 0
assert p.parsed['PFD']['value'] == 'Power Failure Detection not detected/not supported/disabled'
assert p.parsed['IO']['raw_value'] == 0
assert p.parsed['IO']['value'] == 'Output channel 0 (to load)'
assert p.parsed['OV']['raw_value'] == 100
assert p.parsed['OV']['value'] == 'Output value 100% or ON'
assert p.parsed['OC']['raw_value'] == 0
assert p.parsed['OC']['value'] == 'Over current switch off: ready / not supported'
assert p.parsed['LC']['raw_value'] == 0
assert p.parsed['LC']['value'] == 'Local control disabled / not supported'
status, buf, p = Packet.parse_msg(bytearray([
0x55,
0x00, 0x09, 0x07, 0x01,
0x56,
0xD2, 0x04, 0x00, 0x00, 0x01, 0x94, 0xE3, 0xB9, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x00,
0xBF
]))
assert p.rorg == RORG.VLD
assert p.parse_eep(0x01, 0x01) == ['PF', 'PFD', 'CMD', 'OC', 'EL', 'IO', 'LC', 'OV']
assert p.parsed['EL']['raw_value'] == 0
assert p.parsed['EL']['value'] == 'Error level 0: hardware OK'
assert p.parsed['PF']['raw_value'] == 0
assert p.parsed['PF']['value'] == 'Power Failure Detection disabled/not supported'
assert p.parsed['PFD']['raw_value'] == 0
assert p.parsed['PFD']['value'] == 'Power Failure Detection not detected/not supported/disabled'
assert p.parsed['IO']['raw_value'] == 0
assert p.parsed['IO']['value'] == 'Output channel 0 (to load)'
assert p.parsed['OV']['raw_value'] == 0
assert p.parsed['OV']['value'] == 'Output value 0% or OFF'
assert p.parsed['OC']['raw_value'] == 0
assert p.parsed['OC']['value'] == 'Over current switch off: ready / not supported'
assert p.parsed['LC']['raw_value'] == 0
assert p.parsed['LC']['value'] == 'Local control disabled / not supported'
def test_fails():
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x07, 0x07, 0x01,
0x7A,
0xD5, 0x08, 0x01, 0x82, 0x5D, 0xAB, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x36, 0x00,
0x53
]))
eep = EEP()
# Mock initialization failure
eep.init_ok = False
assert eep.find_profile(packet._bit_data, 0xD5, 0x00, 0x01) is None
# TODO: Needs better test. A much better.
assert eep.set_values(profile=None, data=[True], status=[False, False], properties={'CV': False})
eep.init_ok = True
profile = eep.find_profile(packet._bit_data, 0xD5, 0x00, 0x01)
assert eep.set_values(profile, packet._bit_data, packet.status, {'ASD': 1})
assert eep.find_profile(packet._bit_data, 0xFF, 0x00, 0x01) is None
assert eep.find_profile(packet._bit_data, 0xD5, 0xFF, 0x01) is None
assert eep.find_profile(packet._bit_data, 0xD5, 0x00, 0xFF) is None
status, buf, packet = Packet.parse_msg(bytearray([
0x55,
0x00, 0x09, 0x07, 0x01,
0x56,
0xD2, 0x04, 0x00, 0x00, 0x01, 0x94, 0xE3, 0xB9, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x00,
0xBF
]))
assert eep.find_profile(packet._bit_data, 0xD2, 0x01, 0x01) is not None
assert eep.find_profile(packet._bit_data, 0xD2, 0x01, 0x01, command=-1) is None
|