ItemModel.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. //
  2. // ItemModel.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 4/1/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "ItemModel.h"
  9. #import "JDObject.h"
  10. @implementation CmdClsValueModel
  11. //- (NSString *)cmdclsValueMsg {
  12. // ItemSubModel *subItem = [[ItemSubModel alloc] init];
  13. // subItem.cmdclsValue = _cmdclsValue;
  14. // subItem.cmdclsValueMsg = _cmdclsValueMsg;
  15. //
  16. // return subItem.cmdclsValueMsg;
  17. //}
  18. @end
  19. @implementation ItemSubModel
  20. + (JSONKeyMapper *)keyMapper {
  21. return [JSONKeyMapper mapperFromUnderscoreCaseToCamelCase];
  22. }
  23. - (NSString *)localStringOfDay:(NSString *)day {
  24. NSString *lstr = nil;
  25. if ([day isEqualToString:ksDayOfWeekMON]) {
  26. lstr = NSLocalizedString(@"월", @"월");
  27. } else if ([day isEqualToString:ksDayOfWeekTUE]) {
  28. lstr = NSLocalizedString(@"화", @"화");
  29. } else if ([day isEqualToString:ksDayOfWeekWED]) {
  30. lstr = NSLocalizedString(@"수", @"수");
  31. } else if ([day isEqualToString:ksDayOfWeekTHU]) {
  32. lstr = NSLocalizedString(@"목", @"목");
  33. } else if ([day isEqualToString:ksDayOfWeekFRI]) {
  34. lstr = NSLocalizedString(@"금", @"금");
  35. } else if ([day isEqualToString:ksDayOfWeekSAT]) {
  36. lstr = NSLocalizedString(@"토", @"토");
  37. } else if ([day isEqualToString:ksDayOfWeekSUN]) {
  38. lstr = NSLocalizedString(@"일", @"일");
  39. }
  40. return lstr;
  41. }
  42. - (NSString *)daysOfWeek {
  43. if (_daysOfWeek) {
  44. return _daysOfWeek;
  45. }
  46. NSMutableString *days = [[NSMutableString alloc] init];
  47. if (_cmdclsValue && ![_cmdclsValue isEmptyString]) {
  48. NSArray *darray = [_cmdclsValue componentsSeparatedByString:@","];
  49. for (NSString *day in darray) {
  50. NSString *prefix = [days isEmptyString] ? ksEmptyString : @", ";
  51. [days appendFormat:@"%@%@", prefix, [self localStringOfDay:day]];
  52. }
  53. }
  54. return days;
  55. }
  56. //- (NSString *)cmdclsValueMsg {
  57. //// if (!_cmdclsValueMsg || [_cmdclsValueMsg isEmptyString]) {
  58. // if (_dueDate && ![_dueDate isEmptyString]) {
  59. // _cmdclsValueMsg = _dueDate;
  60. // } else if (_daysOfWeek && ![_daysOfWeek isEmptyString]) {
  61. // _cmdclsValueMsg = _daysOfWeek;
  62. // } else if (_dueTime && ![_dueTime isEmptyString]) {
  63. // _cmdclsValueMsg = _dueTime;
  64. // } else if (_homeModes && ![_homeModes isEmptyString]) {
  65. // _cmdclsValueMsg = _homeModes;
  66. // } else if (_externHeat && ![_externHeat isEmptyString]) {
  67. // _cmdclsValueMsg = _externHeat;
  68. // }
  69. //// }
  70. // return _cmdclsValueMsg;
  71. //
  72. //// if (_dueDate && ![_dueDate isEmptyString]) {
  73. //// self.cmdclsValueMsg = _dueDate;
  74. ////
  75. //// } else if (_daysOfWeek && ![_daysOfWeek isEmptyString]) {
  76. //// self.cmdclsValueMsg = _daysOfWeek;
  77. ////
  78. //// } else if (_dueTime && ![_dueTime isEmptyString]) {
  79. //// self.cmdclsValueMsg = _dueTime;
  80. ////
  81. //// } else if (_homeModes && ![_homeModes isEmptyString]) {
  82. //// self.cmdclsValueMsg = _homeModes;
  83. ////
  84. //// } else if (_externHeat && ![_externHeat isEmptyString]) {
  85. //// self.cmdclsValueMsg = _externHeat;
  86. ////
  87. //// }
  88. //}
  89. #define ksCmdClassTypeFirmwareVersion @"FIRMWARE_VERSION"
  90. #define ksCmdClassTypeSwitchBinary @"SWITCH_BINARY"
  91. #define ksCmdClassTypeSwitchMultiLevel @"SWITCH_MULTILEVEL"
  92. #define ksCmdClassTypeSwitchColor @"SWITCH_COLOR"
  93. #define ksCmdClassTypeSensorBinary @"SENSOR_BINARY"
  94. #define ksCmdClassTypeSensorMultiLevel @"SENSOR_MULTILEVEL"
  95. #define ksCmdClassTypeThermostatMode @"THERMOSTAT_MODE"
  96. #define ksCmdClassTypeThermostatFanMode @"THERMOSTAT_FAN_MODE"
  97. #define ksCmdClassTypeThermostatSetPoint @"THERMOSTAT_SETPOINT"
  98. #define ksCmdClassTypeLock @"LOCK"
  99. #define ksCmdClassTypeMeterCurrent @"METER_CURRENT"
  100. #define ksCmdClassTypeMeterTotal @"METER_TOTAL"
  101. #define ksCmdClassTypeAVControlPlayback @"AV_CONTROL_PLAYBACK"
  102. #define ksCmdClassTypeHomeMode @"HOME_MODE"
  103. #define ksCmdClassTypeSpeedControl @"SPEED_CONTROL"
  104. #define ksCmdClassTypeValve @"VALVE"
  105. #define ksCmdClassTypeBattery @"BATTERY"
  106. #define ksCmdClassTypeDeviceStatus @"DEVICE_STATUS"
  107. #define ksCmdClassTypePresence @"PRESENCE"
  108. #define ksCmdClassTypeSystem @"SYSTEM"
  109. #define ksCmdClassTypeMeter @"METER"
  110. + (CmdClsType)cmdclsTypeForCode:(NSString *)code {
  111. CmdClsType type = -1;
  112. if ([code isEqualToString:ksCmdClassTypeFirmwareVersion]) {
  113. type = CmdClsTypeFirmwareVersion;
  114. } else if ([code isEqualToString:ksCmdClassTypeSwitchBinary]) {
  115. type = CmdClsTypeSwitchBinary;
  116. } else if ([code isEqualToString:ksCmdClassTypeSwitchMultiLevel]) {
  117. type = CmdClsTypeSwitchMultiLevel;
  118. } else if ([code isEqualToString:ksCmdClassTypeSwitchColor]) {
  119. type = CmdClsTypeSwitchColor;
  120. } else if ([code isEqualToString:ksCmdClassTypeSensorBinary]) {
  121. type = CmdClsTypeSensorBinary;
  122. } else if ([code isEqualToString:ksCmdClassTypeSensorMultiLevel]) {
  123. type = CmdClsTypeSensorMultiLevel;
  124. } else if ([code isEqualToString:ksCmdClassTypeThermostatMode]) {
  125. type = CmdClsTypeThermostatMode;
  126. } else if ([code isEqualToString:ksCmdClassTypeThermostatFanMode]) {
  127. type = CmdClsTypeThermostatFanMode;
  128. } else if ([code isEqualToString:ksCmdClassTypeThermostatSetPoint]) {
  129. type = CmdClsTypeThermostatSetPoint;
  130. } else if ([code isEqualToString:ksCmdClassTypeLock]) {
  131. type = CmdClsTypeLock;
  132. } else if ([code isEqualToString:ksCmdClassTypeMeterCurrent]) {
  133. type = CmdClsTypeMeterCurrent;
  134. } else if ([code isEqualToString:ksCmdClassTypeMeterTotal]) {
  135. type = CmdClsTypeMeterTotal;
  136. } else if ([code isEqualToString:ksCmdClassTypeAVControlPlayback]) {
  137. type = CmdClsTypeAVControlPlayback;
  138. } else if ([code isEqualToString:ksCmdClassTypeHomeMode]) {
  139. type = CmdClsTypeHomeMode;
  140. } else if ([code isEqualToString:ksCmdClassTypeSpeedControl]) {
  141. type = CmdClsTypeSpeedControl;
  142. } else if ([code isEqualToString:ksCmdClassTypeValve]) {
  143. type = CmdClsTypeValve;
  144. } else if ([code isEqualToString:ksCmdClassTypeBattery]) {
  145. type = CmdClsTypeBattery;
  146. } else if ([code isEqualToString:ksCmdClassTypeDeviceStatus]) {
  147. type = CmdClsTypeDeviceStatus;
  148. } else if ([code isEqualToString:ksCmdClassTypePresence]) {
  149. type = CmdClsTypePresence;
  150. } else if ([code isEqualToString:ksCmdClassTypeSystem]) {
  151. type = CmdClsTypeSystem;
  152. } else if ([code isEqualToString:ksCmdClassTypeMeter]) {
  153. type = CmdClsTypeMeter;
  154. }
  155. return type;
  156. }
  157. - (CmdClsType)cmdclsType {
  158. return [ItemSubModel cmdclsTypeForCode:_cmdclsCode];
  159. }
  160. - (NSInteger)cmdclsValueMsgLength {
  161. NSInteger length = 0;
  162. // NSArray<CmdClsValueModel> *array = nil;
  163. //
  164. // switch ([self cmdclsType]) {
  165. // case CmdClsTypeLock:
  166. // array = [self cmdclsValueListOfLock];
  167. // break;
  168. // default:
  169. // break;
  170. // }
  171. for (CmdClsValueModel *tmpCmdclsValue in self.cmdclsValueList) {
  172. if (tmpCmdclsValue.cmdclsValueMsg.length > length) {
  173. length = tmpCmdclsValue.cmdclsValueMsg.length;
  174. }
  175. }
  176. return length;
  177. }
  178. - (NSString *)cmdclsValueMsgLongest {
  179. NSString *hstring = nil;
  180. // NSArray<CmdClsValueModel> *array = nil;
  181. //
  182. // switch ([self cmdclsType]) {
  183. // case CmdClsTypeSwitchBinary:
  184. // array = [self cmdclsValueListOfSwitchBinary];
  185. // break;
  186. // case CmdClsTypeLock:
  187. // array = [self cmdclsValueListOfLock];
  188. // break;
  189. // default:
  190. // break;
  191. // }
  192. NSUInteger highest = 0;
  193. for (CmdClsValueModel *tmpCmdclsValue in self.cmdclsValueList) {
  194. if (tmpCmdclsValue.cmdclsValueMsg.length > highest) {
  195. highest = tmpCmdclsValue.cmdclsValueMsg.length;
  196. hstring = tmpCmdclsValue.cmdclsValueMsg;
  197. }
  198. }
  199. return hstring;
  200. }
  201. /*
  202. - (NSArray<CmdClsValueModel> *)cmdclsValueList {
  203. switch ([self cmdclsType]) {
  204. case CmdClsTypeThermostatMode:
  205. _cmdclsValueList = [self cmdclsValueListOfThermostatMode];
  206. break;
  207. case CmdClsTypeLock:
  208. _cmdclsValueList = [self cmdclsValueListOfLock];
  209. break;
  210. case CmdClsTypeSpeedControl:
  211. _cmdclsValueList = [self cmdclsValueListOfSpeedControl];
  212. break;
  213. case CmdClsTypeSwitchBinary:
  214. _cmdclsValueList = [self cmdclsValueListOfSwitchBinary];
  215. break;
  216. case CmdClsTypeValve:
  217. _cmdclsValueList = [self cmdclsValueListOfValve];
  218. break;
  219. default:
  220. break;
  221. }
  222. return _cmdclsValueList;
  223. }
  224. - (NSArray<CmdClsValueModel> *)cmdclsValueListOfThermostatMode {
  225. NSMutableArray<CmdClsValueModel> *array = [(NSMutableArray<CmdClsValueModel> *)[NSMutableArray alloc] init];
  226. NSInteger typeId = [_cmdclsTypeId integerValue];
  227. switch (typeId) {
  228. case 13001: {
  229. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"OFF",
  230. @"cmdcls_value_msg": NSLocalizedString(@"꺼짐", @"꺼짐")} error:nil]];
  231. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"COOL",
  232. @"cmdcls_value_msg": NSLocalizedString(@"냉방", @"냉방")} error:nil]];
  233. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"HEAT",
  234. @"cmdcls_value_msg": NSLocalizedString(@"난방", @"난방")} error:nil]];
  235. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"AUTO",
  236. @"cmdcls_value_msg": NSLocalizedString(@"자동", @"자동")} error:nil]];
  237. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"FAN_ONLY",
  238. @"cmdcls_value_msg": NSLocalizedString(@"환기", @"환기")} error:nil]];
  239. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"DRY_AIR",
  240. @"cmdcls_value_msg": NSLocalizedString(@"제습", @"제습")} error:nil]];
  241. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"AWAY",
  242. @"cmdcls_value_msg": NSLocalizedString(@"외출", @"외출")} error:nil]];
  243. }
  244. break;
  245. case 13002: {
  246. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"OFF",
  247. @"cmdcls_value_msg": NSLocalizedString(@"꺼짐", @"꺼짐")} error:nil]];
  248. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"COOL",
  249. @"cmdcls_value_msg": NSLocalizedString(@"냉방", @"냉방")} error:nil]];
  250. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"HEAT",
  251. @"cmdcls_value_msg": NSLocalizedString(@"난방", @"난방")} error:nil]];
  252. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"AUTO",
  253. @"cmdcls_value_msg": NSLocalizedString(@"자동", @"자동")} error:nil]];
  254. }
  255. break;
  256. case 13003: {
  257. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"OFF",
  258. @"cmdcls_value_msg": NSLocalizedString(@"꺼짐", @"꺼짐")} error:nil]];
  259. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"HEAT",
  260. @"cmdcls_value_msg": NSLocalizedString(@"난방", @"난방")} error:nil]];
  261. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"AWAY",
  262. @"cmdcls_value_msg": NSLocalizedString(@"외출", @"외출")} error:nil]];
  263. }
  264. break;
  265. case 13004: {
  266. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"OFF",
  267. @"cmdcls_value_msg": NSLocalizedString(@"꺼짐", @"꺼짐")} error:nil]];
  268. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"COOL",
  269. @"cmdcls_value_msg": NSLocalizedString(@"냉방", @"냉방")} error:nil]];
  270. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"FAN_ONLY",
  271. @"cmdcls_value_msg": NSLocalizedString(@"환기", @"환기")} error:nil]];
  272. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"DRY_AIR",
  273. @"cmdcls_value_msg": NSLocalizedString(@"제습", @"제습")} error:nil]];
  274. }
  275. break;
  276. }
  277. return array;
  278. }
  279. - (NSArray<CmdClsValueModel> *)cmdclsValueListOfSwitchBinary {
  280. NSMutableArray<CmdClsValueModel> *array = [(NSMutableArray<CmdClsValueModel> *)[NSMutableArray alloc] init];
  281. NSInteger typeId = [_cmdclsTypeId integerValue];
  282. switch (typeId) {
  283. case 17001:
  284. case 17002:
  285. case 17003:
  286. case 17004:
  287. case 17005:
  288. {
  289. for (CmdClsValueModel *cmdclsValue in self.cmdclsValueList) {
  290. if ([cmdclsValue.cmdclsValue isEqualToString:@"ON"]) {
  291. cmdclsValue.localizedCmdClsValueMsg = @"켬", @""
  292. }
  293. }
  294. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"ON",
  295. @"cmdcls_value_msg": NSLocalizedString(@"켬", @"켬")} error:nil]];
  296. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"OFF",
  297. @"cmdcls_value_msg": NSLocalizedString(@"끔", @"끔")} error:nil]];
  298. break;
  299. }
  300. }
  301. return array;
  302. }
  303. - (NSArray<CmdClsValueModel> *)cmdclsValueListOfLock {
  304. NSMutableArray<CmdClsValueModel> *array = [(NSMutableArray<CmdClsValueModel> *)[NSMutableArray alloc] init];
  305. NSInteger typeId = [_cmdclsTypeId integerValue];
  306. switch (typeId) {
  307. case 14001: {
  308. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"LOCKED",
  309. @"cmdcls_value_msg": @"잠김"} error:nil]];
  310. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"UNCLOCKED",
  311. @"cmdcls_value_msg": @"열림"} error:nil]];
  312. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"JAMMED",
  313. @"cmdcls_value_msg": @"걸림"} error:nil]];
  314. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"FORCED_OPEN",
  315. @"cmdcls_value_msg": @"수동"} error:nil]];
  316. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"UNSPECIFIED",
  317. @"cmdcls_value_msg": @"오류"} error:nil]];
  318. }
  319. break;
  320. case 14002:
  321. case 14003:
  322. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"LOCKED",
  323. @"cmdcls_value_msg": @"잠김"} error:nil]];
  324. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"UNCLOCKED",
  325. @"cmdcls_value_msg": @"열림"} error:nil]];
  326. break;
  327. }
  328. return array;
  329. }
  330. - (NSArray<CmdClsValueModel> *)cmdclsValueListOfSpeedControl {
  331. NSMutableArray<CmdClsValueModel> *array = [(NSMutableArray<CmdClsValueModel> *)[NSMutableArray alloc] init];
  332. NSInteger typeId = [_cmdclsTypeId integerValue];
  333. switch (typeId) {
  334. case 20001: {
  335. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"OFF",
  336. @"cmdcls_value_msg": @"꺼짐"} error:nil]];
  337. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"LOW",
  338. @"cmdcls_value_msg": @"약"} error:nil]];
  339. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"MEDIUM",
  340. @"cmdcls_value_msg": @"중"} error:nil]];
  341. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"HIGH",
  342. @"cmdcls_value_msg": @"강"} error:nil]];
  343. }
  344. break;
  345. }
  346. return array;
  347. }
  348. - (NSArray<CmdClsValueModel> *)cmdclsValueListOfValve {
  349. NSMutableArray<CmdClsValueModel> *array = [(NSMutableArray<CmdClsValueModel> *)[NSMutableArray alloc] init];
  350. NSInteger typeId = [_cmdclsTypeId integerValue];
  351. switch (typeId) {
  352. case 36001:
  353. case 36002:
  354. case 36003:
  355. {
  356. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"OPEN",
  357. @"cmdcls_value_msg": @"열기"} error:nil]];
  358. [array addObject:[[CmdClsValueModel alloc] initWithDictionary:@{@"cmdcls_value":@"CLOSE",
  359. @"cmdcls_value_msg": @"잠그기"} error:nil]];
  360. }
  361. break;
  362. }
  363. return array;
  364. }
  365. */
  366. - (NSString *)unit {
  367. if ([_unit isEqualToString:@"\\"]) {
  368. _unit = @"₩";
  369. }
  370. return _unit;
  371. }
  372. //- (NSString *)cmdclsValueMsgOfSensorBinary {
  373. // NSInteger typeId = [_cmdclsTypeId integerValue];
  374. // NSString *msg = ksEmptyString;
  375. // switch (typeId) {
  376. // case 11001:
  377. // case 11002:
  378. // case 11003:
  379. // case 11004:
  380. // case 11005:
  381. // case 11006:
  382. // case 11007:
  383. // case 11008:
  384. // case 11009:
  385. // case 11010:
  386. // case 11012:
  387. // case 11013:
  388. // case 11014:
  389. // case 11016:
  390. // if ([_cmdclsValue isEqualToString:@"TRUE"]) {
  391. // msg = NSLocalizedString(@"감지됨", @"감지됨");
  392. // } else if ([_cmdclsValue isEqualToString:@"FALSE"]) {
  393. // msg = NSLocalizedString(@"정상", @"정상");
  394. // } else {
  395. // msg = @"-";
  396. // }
  397. // break;
  398. // case 11011:
  399. // if ([_cmdclsValue isEqualToString:@"TRUE"]) {
  400. // msg = NSLocalizedString(@"열림", @"열림");
  401. // } else if ([_cmdclsValue isEqualToString:@"FALSE"]) {
  402. // msg = NSLocalizedString(@"닫힘", @"닫힘");
  403. // } else {
  404. // msg = @"-";
  405. // }
  406. // case 11015:
  407. // if ([_cmdclsValue isEqualToString:@"TRUE"]) {
  408. // msg = NSLocalizedString(@"들어옴", @"들어옴");
  409. // } else if ([_cmdclsValue isEqualToString:@"FALSE"]) {
  410. // msg = NSLocalizedString(@"나감", @"나감");
  411. // } else {
  412. // msg = @"-";
  413. // }
  414. // break;
  415. // }
  416. // return msg;
  417. //}
  418. - (NSString *)cmdclsValueMsgOfThermostatMode {
  419. NSInteger typeId = [_cmdclsTypeId integerValue];
  420. NSString *msg = ksEmptyString;
  421. switch (typeId) {
  422. case 13001:
  423. case 13002:
  424. case 13003:
  425. case 13004:
  426. if ([_cmdclsValue isEqualToString:@"OFF"]) {
  427. msg = NSLocalizedString(@"꺼짐", @"꺼짐");
  428. } else if ([_cmdclsValue isEqualToString:@"COOL"]) {
  429. msg = NSLocalizedString(@"냉방", @"냉방");
  430. } else if ([_cmdclsValue isEqualToString:@"HEAT"]) {
  431. msg = NSLocalizedString(@"난방", @"난방");
  432. } else if ([_cmdclsValue isEqualToString:@"AUTO"]) {
  433. msg = NSLocalizedString(@"자동", @"자동");
  434. } else if ([_cmdclsValue isEqualToString:@"FAN_ONLY"]) {
  435. msg = NSLocalizedString(@"환기", @"환기");
  436. } else if ([_cmdclsValue isEqualToString:@"DRY_AIR"]) {
  437. msg = NSLocalizedString(@"제습", @"제습");
  438. } else if ([_cmdclsValue isEqualToString:@"AWAY"]) {
  439. msg = NSLocalizedString(@"외출", @"외출");
  440. } else {
  441. msg = @"-";
  442. }
  443. break;
  444. }
  445. return msg;
  446. }
  447. - (NSString *)cmdclsValueMsgOfLock {
  448. NSInteger typeId = [_cmdclsTypeId integerValue];
  449. NSString *msg = ksEmptyString;
  450. switch (typeId) {
  451. case 14001:
  452. if ([_cmdclsValue isEqualToString:@"LOCKED"]) {
  453. msg = NSLocalizedString(@"잠김", @"잠김");
  454. } else if ([_cmdclsValue isEqualToString:@"UNLOCKED"]) {
  455. msg = NSLocalizedString(@"열림", @"열림");
  456. } else if ([_cmdclsValue isEqualToString:@"JAMMED"]) {
  457. msg = NSLocalizedString(@"걸림", @"걸림");
  458. } else if ([_cmdclsValue isEqualToString:@"FORCED_OPEN"]) {
  459. msg = NSLocalizedString(@"수동", @"수동");
  460. } else if ([_cmdclsValue isEqualToString:@"UNSPECIFIED"]) {
  461. msg = NSLocalizedString(@"오류", @"오류");
  462. } else {
  463. msg = @"-";
  464. }
  465. break;
  466. case 14002:
  467. case 14003:
  468. if ([_cmdclsValue isEqualToString:@"LOCKED"]) {
  469. msg = @"잠김";
  470. } else if ([_cmdclsValue isEqualToString:@"UNLOCKED"]) {
  471. msg = @"열림";
  472. } else {
  473. msg = @"-";
  474. }
  475. break;
  476. }
  477. return msg;
  478. }
  479. - (NSString *)cmdclsValueMsgOfSwitchBinary {//On/Off status
  480. NSInteger typeId = [_cmdclsTypeId integerValue];
  481. NSString *msg = ksEmptyString;
  482. switch (typeId) {
  483. case 17001://Default
  484. case 17002://Plug
  485. case 17003://Bulb
  486. case 17004://Light
  487. case 17005://Wall Switch
  488. if ([_cmdclsValue isEqualToString:@"ON"]) {
  489. msg = NSLocalizedString(@"켬", @"켬");
  490. } else if ([_cmdclsValue isEqualToString:@"OFF"]) {
  491. msg = NSLocalizedString(@"끔", @"끔");
  492. } else {
  493. msg = @"-";
  494. }
  495. break;
  496. }
  497. return msg;
  498. }
  499. - (NSString *)cmdclsValueMsgOfValve {//Openn/Close status
  500. NSInteger typeId = [_cmdclsTypeId integerValue];
  501. NSString *msg = ksEmptyString;
  502. switch (typeId) {
  503. case 36001://Default
  504. case 36002://NTELS_1
  505. case 36003://NTELS_2
  506. if ([_cmdclsValue isEqualToString:@"OPEN"]) {
  507. msg = NSLocalizedString(@"열기", @"열기");
  508. } else if ([_cmdclsValue isEqualToString:@"CLOSE"]) {
  509. msg = NSLocalizedString(@"잠그기", @"잠그기");
  510. } else {
  511. msg = @"-";
  512. }
  513. break;
  514. }
  515. return msg;
  516. }
  517. - (NSString *)cmdclsValueMsg {
  518. switch ([self cmdclsType]) {
  519. // case CmdClsTypeSensorBinary:
  520. // _cmdclsValueMsg = [self cmdclsValueMsgOfSensorBinary];
  521. // break;
  522. case CmdClsTypeThermostatMode:
  523. _cmdclsValueMsg = [self cmdclsValueMsgOfThermostatMode];
  524. break;
  525. case CmdClsTypeLock:
  526. _cmdclsValueMsg = [self cmdclsValueMsgOfLock];
  527. break;
  528. case CmdClsTypeSwitchBinary:
  529. _cmdclsValueMsg = [self cmdclsValueMsgOfSwitchBinary];
  530. break;
  531. case CmdClsTypeSpeedControl:
  532. _cmdclsValueMsg = [self cmdclsValueMsgOfSpeedControl];
  533. break;
  534. case CmdClsTypeAVControlPlayback:
  535. _cmdclsValueMsg = [self cmdclsValueMsgOfAVPlayback];
  536. break;
  537. case CmdClsTypeValve:
  538. _cmdclsValueMsg = [self cmdclsValueMsgOfValve];
  539. break;
  540. case CmdClsTypeSensorMultiLevel:
  541. case CmdClsTypeBattery:
  542. case CmdClsTypeSensorBinary:
  543. case CmdClsTypeMeter: {
  544. NSString *condition = [_conditionTypeCode isEqualToString:ksConditionTypeCodeGreatOrEqual] ? @"이상" : @"이하";
  545. _cmdclsValueMsg = [NSString stringWithFormat:@"%@%@ %@", _cmdclsValue, _unit, condition];
  546. }
  547. }
  548. return _cmdclsValueMsg;
  549. }
  550. - (NSString *)cmdclsValueMsgOfSpeedControl {
  551. NSInteger typeId = [_cmdclsTypeId integerValue];
  552. NSString *msg = ksEmptyString;
  553. switch (typeId) {
  554. case 20001:
  555. if ([_cmdclsValue isEqualToString:@"OFF"]) {
  556. msg = NSLocalizedString(@"꺼짐", @"꺼짐");
  557. } else if ([_cmdclsValue isEqualToString:@"LOW"]) {
  558. msg = NSLocalizedString(@"약", @"약");
  559. } else if ([_cmdclsValue isEqualToString:@"MEDIUM"]) {
  560. msg = NSLocalizedString(@"중", @"중");
  561. } else if ([_cmdclsValue isEqualToString:@"HIGH"]) {
  562. msg = NSLocalizedString(@"강", @"강");
  563. } else {
  564. msg = @"-";
  565. }
  566. break;
  567. }
  568. return msg;
  569. }
  570. - (NSString *)cmdclsValueMsgOfAVPlayback {
  571. NSInteger typeId = [_cmdclsTypeId integerValue];
  572. NSString *msg = ksEmptyString;
  573. switch (typeId) {
  574. case 21001:
  575. if ([_cmdclsValue isEqualToString:@"PLAYING"]) {
  576. msg = NSLocalizedString(@"재생 중", @"재생 중");
  577. } else if ([_cmdclsValue isEqualToString:@"PAUSED"]) {
  578. msg = NSLocalizedString(@"정지 됨", @"정지 됨");
  579. } else {
  580. msg = @"-";
  581. }
  582. break;
  583. }
  584. return msg;
  585. }
  586. - (BOOL)isOnline {
  587. return _onlineState && ![_onlineState isEmptyString] && [_onlineState isEqualToString:@"ON"];
  588. }
  589. - (NSString *)conditionTypeCode {
  590. if (!_conditionTypeCode) {
  591. switch ([self cmdclsType]) {
  592. case CmdClsTypeSwitchMultiLevel:
  593. case CmdClsTypeSensorMultiLevel:
  594. case CmdClsTypeBattery:
  595. case CmdClsTypeMeter:
  596. _conditionTypeCode = @"05";
  597. break;
  598. default:
  599. _conditionTypeCode = @"01";
  600. break;
  601. }
  602. }
  603. return _conditionTypeCode;
  604. }
  605. @end
  606. @implementation ItemModel
  607. + (JSONKeyMapper *)keyMapper {
  608. return [[JSONKeyMapper alloc] initWithDictionary:@{@"pred_item_sequence": @"predItemSequence",
  609. @"item_type_code": @"itemTypeCode",
  610. @"item_sub_type_code": @"itemSubTypeCode",
  611. @"item_name": @"itemName",
  612. @"item_sub": @"subItems",
  613. @"pred_action_sequence": @"predActionSequence",
  614. @"pred_scene_id": @"predSceneId",
  615. @"pred_rule_id": @"predRuleId",
  616. @"cnt" : @"cnt",
  617. @"total_cnt" : @"totalCnt",
  618. @"image_file_name": @"imageFileName",
  619. @"source_id": @"sourceId",
  620. @"source_name": @"sourceName",
  621. @"image_file_view_name": @"imageFileViewName"}];
  622. }
  623. + (NSString *)itemSubTypeString:(NSString *)itemSubTypeCode {
  624. NSString *string = ksEmptyString;
  625. if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
  626. string = @"Choose your things & action";
  627. } else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {
  628. string = @"Choose home mode";
  629. } else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeAppPush]) {
  630. string = @"Choose your things & action";
  631. } else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
  632. string = @"Choose your things & action";
  633. }
  634. return string;
  635. }
  636. - (NSInteger)sumPredDeviceCount {
  637. return _predDevices.count + [_cnt integerValue];
  638. }
  639. - (NSInteger)sumModesCount {
  640. return _modes.count + [_cnt integerValue];
  641. }
  642. - (NSInteger)sumPushesCount {
  643. return _pushes.count + [_cnt integerValue];
  644. }
  645. @end
  646. @implementation ItemListModel
  647. @end
  648. @implementation ItemSubListModel
  649. @end