CommandClassControlView.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. //
  2. // CommandClassControlView.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/16/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "DeviceModel.h"
  12. #import "CustomLabel.h"
  13. #import "CommonUtil.h"
  14. #import "CustomButton.h"
  15. #import "CommandClassControlView.h"
  16. #import "ThingsDetailViewController.h"
  17. #import "ThingsViewController.h"
  18. #import "MainViewController.h"
  19. #define MAX_CONTROL_REQUEST_TIME 10
  20. @implementation CommandClassControlView
  21. + (CommandClassControlView *)viewForCommandClass:(CmdClsType)cmdClsType {
  22. CommandClassControlView *controlView = nil;
  23. for (UIView *view in [CommonUtil nibViews:@"CommandClassControlView"]) {
  24. if (view.tag == cmdClsType) {
  25. controlView = (CommandClassControlView *)view;
  26. controlView.width = kfControlDefaultWidth;
  27. controlView.height = kfControlDefaultHeight;
  28. break;
  29. }
  30. }
  31. return controlView;
  32. }
  33. - (void)setDevice:(DeviceModel *)device {
  34. _device = device;
  35. }
  36. - (void)setNode:(NodeModel *)node {
  37. _node = node;
  38. }
  39. - (void)setSelectHub:(DeviceModel *)selectHub {
  40. _selectHub = selectHub;
  41. }
  42. - (void)setLayoutUI {
  43. }
  44. - (void)updateLayout {
  45. }
  46. //todo : 로딩화면 띄우기
  47. //예외처리 하기
  48. - (NSDictionary *)parameterForNodeCommand {
  49. NSDictionary *parameter = nil;
  50. if (_device) {
  51. NSLog(@"Device : %@", _device);
  52. parameter = @{
  53. @"device_id": _device.deviceId,
  54. @"node_id": _device.nodeId};
  55. } else if (_node) {
  56. NSLog(@"Node : %@", _node);
  57. parameter = @{@"device_id": _node.deviceId,
  58. @"node_id": _node.nodeId};
  59. }
  60. return parameter;
  61. }
  62. - (NSDictionary *)requestValueForNodeCommand:(NSString *)requestValue {
  63. NSDictionary *result = nil;
  64. if (_device) {
  65. result = @{_device.cmdclsId:requestValue};
  66. } else if (_node) {
  67. result = @{_node.cmdclsId:requestValue};
  68. }
  69. return result;
  70. }
  71. - (CGSize)sizeForIntrinsic {
  72. return CGSizeMake(kfControlMaxWidth, kfControlDefaultHeight);
  73. }
  74. - (CGSize)sizeForIntrinsicForItemCount:(NSInteger)count {
  75. return CGSizeMake(kfControlMaxWidth, kfControlDefaultHeight);
  76. }
  77. - (void)requestNodeCommand:(NSDictionary *)parameters requestValue:(NSString *)requestValue completionHandler:(NodeCommandCompletionBlock)completion failureHandler:(NodeCommandFailureBlock)failure {
  78. if (_device.isRequesting) {
  79. return;
  80. }
  81. _device.isRequesting = YES;
  82. [[[RACObserve(_device, contentValue) skip:1] take:1] subscribeNext:^(id x) {
  83. [self updateLayout];
  84. }];
  85. NSString *deviceId = parameters[@"device_id"];
  86. NSString *nodeId = parameters[@"node_id"];
  87. NSDictionary *param = @{@"request_value": requestValue};
  88. NSString *path = [NSString stringWithFormat:API_POST_NODE_COMMAND, deviceId, nodeId];
  89. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestPOST parameters:param modelClass:[DeviceModel class] showLoadingView:NO completion:^(id responseObject) {
  90. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  91. return;
  92. }
  93. DeviceModel *result = (DeviceModel *)responseObject;
  94. if (result && result.commandId && ![result.commandId isEmptyString]) {
  95. _device.requestTime = result.requestTime;
  96. ThingsViewController *vc = [JDFacade facade].mainViewController.tvc;
  97. if (vc && [vc isKindOfClass:[ThingsViewController class]]) {
  98. [vc requestPollingCommandStatusOfDeviceInBackground:_device];
  99. }
  100. }
  101. if (completion) {
  102. completion(responseObject);
  103. }
  104. } failure:^(id errorObject) {
  105. JDErrorModel *error = (JDErrorModel *)errorObject;
  106. [[JDFacade facade] alert:error.errorMessage];
  107. if (failure) {
  108. failure(error);
  109. }
  110. }];
  111. }
  112. - (void)requestNodeCommand:(NSDictionary *)parameters requestValue:(NSDictionary *)requestValue {
  113. if (_device.isRequesting) {
  114. return;
  115. }
  116. NSLog(@"Device : %@", _device);
  117. _device.isRequesting = YES;
  118. SocketRequestModel *request = [[SocketRequestModel alloc] initWithMsgType:MSG_TYPE_NODE_COMMAND];
  119. NSDictionary *param = @{@"device_id": parameters[@"device_id"],
  120. @"node_id":parameters[@"node_id"],
  121. @"command_type":CMD_TYPE_CONTROL,
  122. @"request_value":requestValue,
  123. @"cust_id": [[JDFacade facade].loginUser custId],
  124. @"ctrt_grp_id": [[JDFacade facade].loginUser ctrtGrpId]};
  125. [request setRequestMsg:param];
  126. [[SocketServiceHandler sharedManager] sendDataWithDelegate:request delegate:self];
  127. [self performSelector:@selector(chkRequstDeviceControlResult) withObject:nil afterDelay:MAX_CONTROL_REQUEST_TIME];
  128. }
  129. - (void)requestNodeCommand:(NSString *)requestValue {
  130. if (_device.isRequesting) {
  131. return;
  132. }
  133. NSLog(@"Device : %@", _device);
  134. _device.isRequesting = YES;
  135. [[[RACObserve(_device, contentValue) skip:1] take:1] subscribeNext:^(id x) {
  136. [self updateLayout];
  137. }];
  138. SocketRequestModel *request = [[SocketRequestModel alloc] initWithMsgType:MSG_TYPE_NODE_COMMAND];
  139. NSDictionary *param = @{@"device_id": _device.deviceId,
  140. @"node_id":_device.nodeId,
  141. @"command_type":CMD_TYPE_CONTROL,
  142. @"request_value":@{_device.cmdclsId:requestValue},
  143. @"cust_id": [[JDFacade facade].loginUser custId],
  144. @"ctrt_grp_id": [[JDFacade facade].loginUser ctrtGrpId]};
  145. [request setRequestMsg:param];
  146. [[SocketServiceHandler sharedManager] sendDataWithDelegate:request delegate:self];
  147. [self performSelector:@selector(chkRequstDeviceControlResult) withObject:nil afterDelay:MAX_CONTROL_REQUEST_TIME];
  148. }
  149. + (NSString *)cmdclsValueForType:(NSString *)dataTypeCode value:(CGFloat)value {
  150. NSString *result = nil;
  151. if ([dataTypeCode isEqualToString:ksDataTypeCodeInteger]) {
  152. result = [NSString stringWithFormat:@"%zd", (NSInteger)value];
  153. } else if ([dataTypeCode isEqualToString:ksDataTypeCodeFloat]) {
  154. result = [NSString stringWithFormat:@"%.1f", value];
  155. } else {
  156. result = [NSString stringWithFormat:@"%zd", (NSInteger)value];
  157. }
  158. return result;
  159. }
  160. - (void)updateThingsViewContoller {
  161. if ([[JDFacade facade].currentViewController isKindOfClass:[ThingsDetailViewController class]]) {
  162. ThingsViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[ThingsViewController class]];
  163. if (vc) {
  164. [vc prepareViewDidLoad];
  165. }
  166. }
  167. }
  168. -(void) chkRequstDeviceControlResult {
  169. if (_device.isRequesting) {
  170. _device.isRequesting = NO;
  171. ThingsViewController *vc = [JDFacade facade].mainViewController.tvc;
  172. if (vc && [vc isKindOfClass:[ThingsViewController class]]) {
  173. [vc requestDeviceControl];
  174. }
  175. }
  176. }
  177. - (void) socketDidReceiveMessage:(id)message result:(SocketModel *)result
  178. {
  179. if (result.isSuccess) {
  180. ThingsViewController *vc = [JDFacade facade].mainViewController.tvc;
  181. if (vc && [vc isKindOfClass:[ThingsViewController class]]) {
  182. [vc requestDeviceControl];
  183. }
  184. } else {
  185. _device.isRequesting = NO;
  186. }
  187. }
  188. @end
  189. @implementation CommandClassSwitchView
  190. - (void)willMoveToSuperview:(UIView *)newSuperview {
  191. if (!newSuperview)
  192. return;
  193. [self initControl];
  194. }
  195. - (void)initControl {
  196. _requestValueForOff = @"OFF";
  197. _requestValueForOn = @"ON";
  198. [self setLayoutUI];
  199. }
  200. - (void)setLayoutUI {
  201. _device = _device ? _device : _node;
  202. _isON = [_device.contentValue isEqualToString:_requestValueForOn];
  203. _device.cmdclsValue = _isON ? _requestValueForOff : _requestValueForOn;
  204. _lblContentValueMsg.text = _device.contentValueMsg;
  205. _btnSwitch.hidden = self.isReOrderMode;
  206. [self setSwitchBinary];
  207. }
  208. - (IBAction)btnSwitchTouched:(id)sender {
  209. NSLog(@"_device : %@", _device) ;
  210. if (![[JDFacade facade].loginUser onlineHomeHubFromSelectedHub:_selectHub]) {
  211. [[JDFacade facade] alert:@"허브가 오프라인 상태입니다. 허브 상태 확인 후 다시 시도해주세요." completionHander:nil];
  212. return;
  213. }
  214. NSString *requestValue = _isON ? _requestValueForOff : _requestValueForOn;
  215. _device.cmdclsValue = requestValue;
  216. // [self requestNodeCommand:self.parameterForNodeCommand requestValue:requestValue completionHandler:^(id result) {
  217. //
  218. //// _device.contentValue = requestValue;
  219. //// _isON = !_isON;
  220. //// _device.contentValue = _isON ? _requestValueForOn : _requestValueForOff;
  221. //// [self toggleSwitch];
  222. //
  223. // } failureHandler:nil];
  224. // [self requestNodeCommand:requestValue];
  225. [self requestNodeCommand:self.parameterForNodeCommand requestValue:[self requestValueForNodeCommand:requestValue]];
  226. }
  227. - (void)setSwitchBinary {
  228. _lblContentValueMsg.text = _device.contentValueMsg;
  229. // [_btnSwitch setTitle:_device.cmdclsValueMsg forState:UIControlStateNormal];
  230. if (_isON) {//OFF
  231. [_btnSwitch setImage:[UIImage imageNamed:@"img_things_list_btn_onoff_on"] forState:UIControlStateNormal];
  232. [self.lblContentValueMsg setColor:kUITextColor02 text:self.lblContentValueMsg.text];
  233. } else {//ON
  234. [_btnSwitch setImage:[UIImage imageNamed:@"img_things_list_btn_onoff_off"] forState:UIControlStateNormal];
  235. }
  236. }
  237. - (void)toggleSwitch {
  238. [self setSwitchBinary];
  239. [self updateThingsViewContoller];
  240. }
  241. - (void)updateLayout {
  242. _isON = !_isON;
  243. [self setSwitchBinary];
  244. }
  245. @end
  246. @implementation CommandClassSwitchMultiLevelView
  247. - (void)willMoveToSuperview:(UIView *)newSuperview {
  248. if (!newSuperview)
  249. return;
  250. [self initControl];
  251. }
  252. - (void)initControl {
  253. [self setLayoutUI];
  254. }
  255. - (void)setLayoutUI {
  256. _device = _device ? _device : _node;
  257. _device.cmdclsValue = _device.cmdclsValue ? _device.cmdclsValue : [CommandClassControlView cmdclsValueForType:_device.dataTypeCode value:[_device.controlMaxValue floatValue]/ 2];
  258. _currentValue = !_isConditionMode ? [_device.contentValue floatValue] : [_device.cmdclsValue floatValue];
  259. _minValue = [_device.controlMinValue floatValue];
  260. _maxValue = [_device.controlMaxValue floatValue];
  261. _step = [_device.controlStep floatValue];
  262. NSString *sMax = [CommandClassControlView cmdclsValueForType:_device.dataTypeCode value:_maxValue];
  263. CGFloat width = [CommonUtil getSizeFromString:sMax font:_btnLabel.titleLabel.font width:FLT_MAX].width + kfSwitchLabelPadding;
  264. CGFloat eWidth = width + kfCommandClassSwitchLeftPadding + kfCommandClassSwitchRightPadding;
  265. eWidth = eWidth < kfControlDefaultWidth ? kfControlDefaultWidth : eWidth;
  266. _constraintBtnLabelWidth.constant = eWidth;
  267. CGRect sr = self.frame;
  268. sr.size.width = eWidth;
  269. self.frame = sr;
  270. [_btnLabel setTitle:[NSString stringWithFormat:@"%@%@", [CommandClassControlView cmdclsValueForType:_device.dataTypeCode value:_currentValue], _device.unit ? _device.unit : ksEmptyString] forState:UIControlStateNormal];
  271. }
  272. - (void)setEnable:(BOOL)enable {
  273. _enable = enable;
  274. _btnMinus.userInteractionEnabled = _enable;
  275. _btnPlus.userInteractionEnabled = _enable;
  276. if (_enable) {
  277. [_btnLabel setTitleColor:kUITextColor02 forState:UIControlStateNormal];
  278. [_btnMinus setImage:[UIImage imageNamed:@"tp_01_img_control_unit_minus"] forState:UIControlStateNormal];
  279. [_btnPlus setImage:[UIImage imageNamed:@"tp_01_img_control_unit_plus"] forState:UIControlStateNormal];
  280. } else {
  281. [_btnLabel setTitleColor:kUITextColor03 forState:UIControlStateNormal];
  282. [_btnMinus setImage:[UIImage imageNamed:@"tp_01_img_control_unit_minus_disable"] forState:UIControlStateNormal];
  283. [_btnPlus setImage:[UIImage imageNamed:@"tp_01_img_control_unit_plus_disable"] forState:UIControlStateNormal];
  284. }
  285. }
  286. - (IBAction)btnPlusTouchDown:(id)sender {
  287. if (!_pressTimer) {
  288. _pressTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(addValue) userInfo:nil repeats:YES];
  289. }
  290. }
  291. - (void)btnMinusTouchDown:(id)sender {
  292. if (!_pressTimer) {
  293. _pressTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(subtractValue) userInfo:nil repeats:YES];
  294. }
  295. }
  296. - (IBAction)btnPlusTouchUp:(id)sender {
  297. [_pressTimer invalidate];
  298. _pressTimer = nil;
  299. [self addValue];
  300. [self requestCommand];
  301. }
  302. - (IBAction)btnMinusTouchUp:(id)sender {
  303. [_pressTimer invalidate];
  304. _pressTimer = nil;
  305. [self subtractValue];
  306. [self requestCommand];
  307. }
  308. - (void)addValue {
  309. _currentValue = _currentValue + _step > _maxValue ? _minValue : _currentValue + _step;
  310. [_btnLabel setTitle:[NSString stringWithFormat:@"%@%@", [CommandClassControlView cmdclsValueForType:_device.dataTypeCode value:_currentValue], _device.unit ? _device.unit : ksEmptyString] forState:UIControlStateNormal];
  311. if (_device) {
  312. _device.cmdclsValue = [CommandClassControlView cmdclsValueForType:_device.dataTypeCode value:_currentValue];
  313. [self updateThingsViewContoller];
  314. }
  315. }
  316. - (void)subtractValue {
  317. _currentValue = _currentValue - _step < _minValue ? _maxValue : _currentValue - _step;
  318. [_btnLabel setTitle:[NSString stringWithFormat:@"%@%@", [CommandClassControlView cmdclsValueForType:_device.dataTypeCode value:_currentValue], _device.unit ? _device.unit : ksEmptyString] forState:UIControlStateNormal];
  319. if (_device) {
  320. _device.cmdclsValue = [CommandClassControlView cmdclsValueForType:_device.dataTypeCode value:_currentValue];
  321. [self updateThingsViewContoller];
  322. }
  323. }
  324. - (void)requestCommand {
  325. if (_isConditionMode) //룰, 씬일 경우, 제어를 하지 않음
  326. return;
  327. NSString *requestValue = _device.cmdclsValue;
  328. // [self requestNodeCommand:self.parameterForNodeCommand requestValue:requestValue completionHandler:^(id result) {
  329. // _device.contentValue = [CommandClassControlView cmdclsValueForType:_device.dataTypeCode value:_currentValue];
  330. // } failureHandler:nil];
  331. // [self requestNodeCommand:requestValue];
  332. [self requestNodeCommand:self.parameterForNodeCommand requestValue:[self requestValueForNodeCommand:requestValue]];
  333. }
  334. @end
  335. @implementation CommandClassValveView
  336. - (void)willMoveToSuperview:(UIView *)newSuperview {
  337. if (!newSuperview)
  338. return;
  339. [self initControl];
  340. }
  341. - (void)initControl {
  342. _requestValueForOpen = @"OPEN";
  343. _requestValueForClose = @"CLOSE";
  344. [self setLayoutUI];
  345. }
  346. - (void)setLayoutUI {
  347. _device = _device ? _device : _node;
  348. _lblContentValueMsg.text = _device.contentValueMsg;
  349. _isOpened = [_device.contentValue isEqualToString:_requestValueForOpen];
  350. _device.cmdclsValue = _isOpened ? _requestValueForClose : _requestValueForOpen;
  351. if ([_device.contentValue isEqualToString:_requestValueForOpen]) {
  352. [self.lblContentValueMsg setColor:kUITextColor02 text:self.lblContentValueMsg.text];
  353. }
  354. _btnOpen.hidden = self.isReOrderMode;
  355. [self setSwitchBinary];
  356. }
  357. - (void)setSwitchBinary {
  358. if (_isOpened) {//Unlocked
  359. // [_btnOpen setImage:[UIImage imageNamed:@"img_things_list_btn_lockunlock_unlock"] forState:UIControlStateNormal];
  360. [_btnOpen setImage:[UIImage imageNamed:@"img_things_list_btn_onoff_on"] forState:UIControlStateNormal];
  361. } else {//Locked
  362. // [_btnOpen setImage:[UIImage imageNamed:@"img_things_list_btn_lockunlock_lock"] forState:UIControlStateNormal];
  363. [_btnOpen setImage:[UIImage imageNamed:@"img_things_list_btn_onoff_off"] forState:UIControlStateNormal];
  364. }
  365. }
  366. - (IBAction)btnOpenTouched:(id)sender {
  367. NSLog(@"btnOpenTouched");
  368. NSLog(@"_device : %@", _device) ;
  369. NSLog(@"_node : %@", _node) ;
  370. if (![[JDFacade facade].loginUser onlineHomeHubFromSelectedHub:_selectHub]) {
  371. [[JDFacade facade] alert:@"허브가 오프라인 상태입니다. 허브 상태 확인 후 다시 시도해주세요." completionHander:nil];
  372. return;
  373. }
  374. NSString *requestValue = _isOpened ? @"CLOSE" : @"OPEN";
  375. if ([_device.cmdclsTypeId isEqualToString:@"36002"]) {
  376. requestValue = @"CLOSE";
  377. if (!_isOpened) {
  378. [[JDFacade facade] toast:@"이미 잠긴 상태입니다"];
  379. return;
  380. }
  381. }
  382. _device.cmdclsValue = requestValue;
  383. // [self requestNodeCommand:self.parameterForNodeCommand requestValue:requestValue completionHandler:^(id result) {
  384. //
  385. //// if ([_device.cmdclsTypeId isEqualToString:@"14001"]) {//Lock.Default일 경우에만 컨트롤을 토글시킴.
  386. //// _isLocked = !_isLocked;
  387. //// _device.contentValue = _isLocked ? @"LOCKED" : @"UNLOCKED";
  388. //// } else if ([_device.cmdclsTypeId isEqualToString:@"14002"]) {
  389. //// _isLocked = YES;
  390. //// _device.contentValue = @"LOCKED";
  391. //// } else if ([_device.cmdclsTypeId isEqualToString:@"14003"]) {
  392. //// _isLocked = NO;
  393. //// _device.contentValue = @"UNLOCKED";
  394. //// }
  395. //
  396. // [self toggleOpenButton];
  397. //
  398. // } failureHandler:nil];
  399. // [self requestNodeCommand:requestValue];
  400. [self requestNodeCommand:self.parameterForNodeCommand requestValue:[self requestValueForNodeCommand:requestValue]];
  401. }
  402. - (void)toggleOpenButton {
  403. [self setSwitchBinary];
  404. // [_btnSwitch faceOffImage];
  405. [self updateThingsViewContoller];
  406. }
  407. @end
  408. #pragma mark - Sensors View
  409. @implementation CommandClassSensorBinaryView
  410. - (void)willMoveToSuperview:(UIView *)newSuperview {
  411. if (!newSuperview)
  412. return;
  413. [self initControl];
  414. }
  415. - (void)initControl {
  416. [self setLayoutUI];
  417. }
  418. - (void)setLayoutUI {
  419. _device = _device ? _device : _node;
  420. NSString *contentValue = _device.contentValueMsg;
  421. NSString *unit = _device.unit && ![_device.unit isEmptyString] ? _device.unit : ksEmptyString;
  422. unit = [contentValue isEqualToString:@"-"] ? ksEmptyString : unit;
  423. self.lblControl.text = [NSString stringWithFormat:@"%@ %@", contentValue, unit];
  424. if ([_device.contentValue isEqualToString:@"TRUE"]) {
  425. [self.lblControl setColor:kUITextColor02 text:self.lblControl.text];
  426. }
  427. }
  428. @end
  429. @implementation CommandClassSensorMultiLevelView
  430. - (void)setLayoutUI {
  431. _device = _device ? _device : _node;
  432. NSString *contentValue = (!_device.contentValue || [_device.contentValue isEmptyString] ||[_device.contentValue isEqualToString:@"none"]) ? @"-" : _device.contentValue;
  433. NSString *unit = _device.unit && ![_device.unit isEmptyString] ? _device.unit : ksEmptyString;
  434. unit = [contentValue isEqualToString:@"-"] ? ksEmptyString : unit;
  435. self.lblControl.text = [NSString stringWithFormat:@"%@%@", contentValue, unit];
  436. // if (self.constraintControlLabelWidth) {
  437. // self.constraintControlLabelWidth.constant = [CommonUtil getSizeFromString:self.lblControl.text font:self.lblControl.font width:kfControlMaxWidth].width;
  438. //
  439. // CGRect sr = self.frame;
  440. // sr.size.width = self.constraintControlLabelWidth.constant;
  441. // self.frame = sr;
  442. // }
  443. }
  444. @end
  445. @implementation CommandClassMeterCurrentView
  446. - (void)willMoveToSuperview:(UIView *)newSuperview {
  447. if (!newSuperview)
  448. return;
  449. [self initControl];
  450. }
  451. - (void)initControl {
  452. _lblMeter.textColor = kUITextColor02;
  453. [self setLayoutUI];
  454. }
  455. - (void)setLayoutUI {
  456. _device = _device ? _device : _node;
  457. NSString *contentValue = (!_device.contentValue || [_device.contentValue isEmptyString] ||[_device.contentValue isEqualToString:@"none"]) ? @"-" : _device.contentValue;
  458. NSString *unit = _device.unit && ![_device.unit isEmptyString] ? _device.unit : ksEmptyString;
  459. unit = [contentValue isEqualToString:@"-"] ? ksEmptyString : unit;
  460. if (_node) {//디바이스 상세일 경우,
  461. self.lblMeter.text = [NSString stringWithFormat:@"%@ %@", contentValue, unit];
  462. self.lblMeter.font = [UIFont systemFontOfSize:kUIFontSize07];
  463. } else if (_device) {
  464. self.lblMeter.text = [NSString stringWithFormat:@"%@ : %@ %@", _device.nodeName, contentValue, unit];
  465. [self.lblMeter setColor:kUITextColor02 text:contentValue];
  466. }
  467. // self.constraintControlLabelWidth.constant = [CommonUtil getSizeFromString:self.lblMeter.text font:self.lblMeter.font width:kfControlMaxWidth].width;
  468. //
  469. // CGRect sr = self.frame;
  470. // sr.size.width = self.constraintControlLabelWidth.constant;
  471. // self.frame = sr;
  472. }
  473. @end
  474. @implementation CommandClassMeterTotalView
  475. @end