public static function syncSonos() { $sonos = self::getSonos(true); $controllers = $sonos->getControllers(); $speakers = sonos3::getSpeaker(); foreach ($controllers as $controller) { $eqLogic = sonos3::byLogicalId($controller->ip, 'sonos3'); if (!is_object($eqLogic)) { $eqLogic = new self(); $eqLogic->setLogicalId($controller->ip); $eqLogic->setName($controller->room . ' - ' . $controller->name); $object = object::byName($controller->room); if (is_object($object)) { $eqLogic->setObject_id($object->getId()); $eqLogic->setName($controller->name); } if (strpos($controller->name, 'PLAY:1') !== false) { $eqLogic->setConfiguration('model', 'PLAY1'); } if (strpos($controller->name, 'PLAY:3') !== false) { $eqLogic->setConfiguration('model', 'PLAY3'); } if (strpos($controller->name, 'PLAY:5') !== false) { $eqLogic->setConfiguration('model', 'PLAY5'); } if (strpos($controller->name, 'PLAYBAR') !== false) { $eqLogic->setConfiguration('model', 'PLAYBAR'); } if (strpos($controller->name, 'CONNECT') !== false) { $eqLogic->setConfiguration('model', 'CONNECT'); } if (strpos($controller->name, 'CONNECT:AMP') !== false) { $eqLogic->setConfiguration('model', 'CONNECTAMP'); } $eqLogic->setEqType_name('sonos3'); $eqLogic->setIsVisible(1); $eqLogic->setIsEnable(1); } $speakers_array = array(); foreach ($speakers as $speaker) { $speakers_array[$speaker->ip] = $speaker->room; } $eqLogic->setConfiguration('speakers', json_encode($speakers_array)); $eqLogic->save(); } }
public static function construct($_arrayMarket) { $market = new self(); if (!isset($_arrayMarket['id'])) { return; } $market->setId($_arrayMarket['id']); $market->setName($_arrayMarket['name']); $market->setType($_arrayMarket['type']); $market->datetime = json_encode($_arrayMarket['datetime'], JSON_UNESCAPED_UNICODE); $market->setDescription($_arrayMarket['description']); $market->setDownloaded($_arrayMarket['downloaded']); $market->setUser_id($_arrayMarket['user_id']); $market->setVersion($_arrayMarket['version']); $market->setCategorie($_arrayMarket['categorie']); $market->status = json_encode($_arrayMarket['status'], JSON_UNESCAPED_UNICODE); $market->setAuthor($_arrayMarket['author']); $market->setChangelog($_arrayMarket['changelog']); $market->setLogicalId($_arrayMarket['logicalId']); $market->setUtilization($_arrayMarket['utilization']); $market->setCertification($_arrayMarket['certification']); $market->setPurchase($_arrayMarket['purchase']); $market->setCost($_arrayMarket['cost']); $market->rating = $_arrayMarket['rating']; $market->setBuyer($_arrayMarket['buyer']); $market->setUpdateBy($_arrayMarket['updateBy']); $market->setPrivate($_arrayMarket['private']); $market->img = json_encode($_arrayMarket['img'], JSON_UNESCAPED_UNICODE); $market->link = json_encode($_arrayMarket['link'], JSON_UNESCAPED_UNICODE); $market->language = json_encode($_arrayMarket['language'], JSON_UNESCAPED_UNICODE); if (isset($_arrayMarket['hardwareCompatibility'])) { $market->hardwareCompatibility = json_encode($_arrayMarket['hardwareCompatibility'], JSON_UNESCAPED_UNICODE); } $market->change = ''; $market->setRealcost($_arrayMarket['realCost']); if (!isset($_arrayMarket['isAuthor'])) { $_arrayMarket['isAuthor'] = true; } $market->setIsAuthor($_arrayMarket['isAuthor']); return $market; }
public static function syncEwattch($_ip) { $request_http = new com_http($_ip . '/log.json?mode=10'); $result = json_decode($request_http->exec(1, 1), true); foreach ($result['resource']['electricity'] as $resource) { $eqLogic = self::byLogicalId('electricity_' . $resource['name'], 'ewattch'); if (!is_object($eqLogic)) { $eqLogic = new self(); $eqLogic->setName('electricity_' . $resource['name']); $eqLogic->setEqType_name('ewattch'); $eqLogic->setIsVisible(1); $eqLogic->setIsEnable(1); $eqLogic->setLogicalId('electricity_' . $resource['name']); $eqLogic->setConfiguration('ip', $_ip); $eqLogic->setCategory('energy', 1); $eqLogic->save(); } $index = $eqLogic->getCmd(null, 'index'); if (!is_object($index)) { $index = new ewattchCmd(); $index->setLogicalId('index'); $index->setIsVisible(1); $index->setName(__('Index', __FILE__)); } $index->setUnite('wh'); $index->setType('info'); $index->setSubType('numeric'); $index->setEventOnly(1); $index->setEqLogic_id($eqLogic->getId()); $index->save(); $cost = $eqLogic->getCmd(null, 'cost'); if (!is_object($cost)) { $cost = new ewattchCmd(); $cost->setLogicalId('cost'); $cost->setIsVisible(1); $cost->setName(__('Coût', __FILE__)); } $cost->setUnite('€'); $cost->setType('info'); $cost->setSubType('numeric'); $cost->setEventOnly(1); $cost->setEqLogic_id($eqLogic->getId()); $cost->save(); } foreach ($result['resource']['water'] as $resource) { $eqLogic = self::byLogicalId('water_' . $resource['name'], 'ewattch'); if (!is_object($eqLogic)) { $eqLogic = new self(); $eqLogic->setName('water_' . $resource['name']); $eqLogic->setEqType_name('ewattch'); $eqLogic->setIsVisible(1); $eqLogic->setIsEnable(1); $eqLogic->setLogicalId('water_' . $resource['name']); $eqLogic->setConfiguration('ip', $_ip); $eqLogic->setCategory('energy', 1); $eqLogic->save(); } $index = $eqLogic->getCmd(null, 'index'); if (!is_object($index)) { $index = new ewattchCmd(); $index->setLogicalId('index'); $index->setIsVisible(1); $index->setName(__('Index', __FILE__)); } $index->setUnite('L'); $index->setType('info'); $index->setSubType('numeric'); $index->setEventOnly(1); $index->setEqLogic_id($eqLogic->getId()); $index->save(); $cost = $eqLogic->getCmd(null, 'cost'); if (!is_object($cost)) { $cost = new ewattchCmd(); $cost->setLogicalId('cost'); $cost->setIsVisible(1); $cost->setName(__('Coût', __FILE__)); } $cost->setUnite('€'); $cost->setType('info'); $cost->setSubType('numeric'); $cost->setEventOnly(1); $cost->setEqLogic_id($eqLogic->getId()); $cost->save(); } foreach ($result['resource']['heating'] as $resource) { $eqLogic = self::byLogicalId('heating_' . $resource['name'], 'ewattch'); if (!is_object($eqLogic)) { $eqLogic = new self(); $eqLogic->setName('heating_' . $resource['name']); $eqLogic->setEqType_name('ewattch'); $eqLogic->setIsVisible(1); $eqLogic->setIsEnable(1); $eqLogic->setLogicalId('heating_' . $resource['name']); $eqLogic->setConfiguration('ip', $_ip); $eqLogic->setCategory('heating', 1); $eqLogic->save(); } $index = $eqLogic->getCmd(null, 'index'); if (!is_object($index)) { $index = new ewattchCmd(); $index->setLogicalId('index'); $index->setIsVisible(1); $index->setName(__('Index', __FILE__)); } $index->setUnite('wh'); $index->setType('info'); $index->setSubType('numeric'); $index->setEventOnly(1); $index->setEqLogic_id($eqLogic->getId()); $index->save(); } foreach ($result['resource']['environment'] as $resource) { $eqLogic = self::byLogicalId('environment_' . $resource['name'], 'ewattch'); if (!is_object($eqLogic)) { $eqLogic = new self(); $eqLogic->setName('environment_' . $resource['name']); $eqLogic->setEqType_name('ewattch'); $eqLogic->setIsVisible(1); $eqLogic->setIsEnable(1); $eqLogic->setLogicalId('environment_' . $resource['name']); $eqLogic->setConfiguration('ip', $_ip); $eqLogic->save(); } $value = $eqLogic->getCmd(null, 'value'); if (!is_object($value)) { $value = new ewattchCmd(); $value->setLogicalId('value'); $value->setIsVisible(1); $value->setName(__('Valeur', __FILE__)); } $value->setUnite($resource['units']); $value->setType('info'); $value->setSubType('numeric'); $value->setEventOnly(1); $value->setEqLogic_id($eqLogic->getId()); $value->save(); } }