ItemModel.m 28 KB

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