_base_device = $base; //$this->_latch_mobile = $this->getLatchMobile(); $this->_latch_wired = $this->getLatchWired(); //$this->_gate_mobile = $this->getGateMobile(); $this->_gate_wired = $this->getGateWired(); $this->_wifi_ssid = $this->getWifiSsid(); $this->_model = $this->getModel(); $this->_led_enabled = $this->getLedEnabled(); } else { $this->eqlogic = $base; $this->_base_device = new BaseDevice($base); //$this->_latch_mobile = $base->getCmd(null, BaseDevice::LATCH_Mobile)->execCmd(); $this->_latch_wired = $base->getCmd(null, BaseDevice::LATCH_WIRED)->execCmd(); //$this->_gate_mobile = $base->getCmd(null, BaseDevice::GATE_MOBILE)->execCmd(); $this->_gate_wired = $base->getCmd(null, BaseDevice::GATE_WIRED)->execCmd(); $this->_wifi_ssid = $base->getCmd(null, BaseDevice::WIFI_SSID)->execCmd(); $this->_model = $base->getCmd(null, BaseDevice::MODEL)->execCmd(); $this->_led_enabled = $base->getCmd(null, BaseDevice::LED_ENABLED)->execCmd(); } } public function createEquipment() { $eqLogic = $this->_base_device->createEquipment(); $order = 2; //$latchMobileId = $eqLogic->addCommand('Portillon', BaseDevice::LATCH_MOBILE, $order++, 'info', 'binary'); $latchWiredId = $eqLogic->addCommand('Portillon', BaseDevice::LATCH_WIRED, $order++, 'info', 'binary'); $gateWiredId = $eqLogic->addCommand('Portail', BaseDevice::GATE_WIRED, $order++, 'info', 'binary'); $eqLogic->addCommand('Wifi SSID', BaseDevice::WIFI_SSID, $order++, 'info', 'string'); $eqLogic->addCommand('Model', BaseDevice::MODEL, $order++, 'info', 'string'); $ledEnabledId = $eqLogic->addCommand('Led', BaseDevice::LED_ENABLED, $order++, 'info', 'binary'); // actions //$eqLogic->addCommand('Ouverture Portillon', BaseDevice::LATCH_MOBILE . BaseDevice::ON_SUFFIX, $order++, 'action', 'other', null, null, null, $latchMobileId); //$eqLogic->addCommand('Fermeture Portillon', BaseDevice::LATCH_MOBILE . BaseDevice::OFF_SUFFIX, $order++, 'action', 'other', null, null, null, $latchMobileId); $eqLogic->addCommand('Portillon ON', BaseDevice::LATCH_WIRED . BaseDevice::ON_SUFFIX, $order++, 'action', 'other', null, null, null, $latchWiredId); $eqLogic->addCommand('Portillon OFF', BaseDevice::LATCH_WIRED . BaseDevice::OFF_SUFFIX, $order++, 'action', 'other', null, null, null, $latchWiredId); $eqLogic->addCommand('Portail ON', BaseDevice::GATE_WIRED . BaseDevice::ON_SUFFIX, $order++, 'action', 'other', null, null, null, $gateWiredId); $eqLogic->addCommand('Portail OFF', BaseDevice::GATE_WIRED . BaseDevice::OFF_SUFFIX, $order++, 'action', 'other', null, null, null, $gateWiredId); $eqLogic->addCommand('Led ON', BaseDevice::LED_ENABLED . BaseDevice::ON_SUFFIX, $order++, 'action', 'other', null, null, null, $ledEnabledId); $eqLogic->addCommand('Led OFF', BaseDevice::LED_ENABLED . BaseDevice::OFF_SUFFIX, $order++, 'action', 'other', null, null, null, $ledEnabledId); $this->eqlogic = $eqLogic; return $eqLogic; } public function refresh($fromApi = false) { if ($fromApi) { $api = new Somfy_API(); $base_device = $api->get_device($this->_base_device->getSiteId(), $this->_base_device->getId()); $this->_base_device = $base_device; } $this->_base_device->refresh($this->eqlogic); //$this->eqlogic->checkAndUpdateCmd(BaseDevice::LATCH_MOBILE, $this->getLatchMobile()); $this->eqlogic->checkAndUpdateCmd(BaseDevice::LATCH_WIRED, $this->getLatchWired()); $this->eqlogic->checkAndUpdateCmd(BaseDevice::GATE_WIRED, $this->getGateWired()); $this->eqlogic->checkAndUpdateCmd(BaseDevice::WIFI_SSID, $this->getWifiSsid()); $this->eqlogic->checkAndUpdateCmd(BaseDevice::MODEL, $this->getModel()); $this->eqlogic->checkAndUpdateCmd(BaseDevice::LED_ENABLED, $this->getLedEnabled()); } //private function getLatchMobile() { // return $this->_base_device->getSetting('global')->latch_mobile; //} private function getLatchWired() { return $this->_base_device->getSetting('global')->latch_wired; } private function getGateWired() { return $this->_base_device->getSetting('global')->gate_wired; } private function getWifiSsid() { return $this->_base_device->getSetting('global')->wifi_ssid; } private function getModel() { return $this->_base_device->getSetting('global')->model; } private function getLedEnabled() { return $this->_base_device->getSetting('global')->led_enabled; } private function buildSettings($latch_wired,$gate_wired,$led_enabled) { $settings = new stdClass(); $settings->settings = new stdClass(); $settings->settings->global = new stdClass(); //$settings->settings->global->latch_mobile = $latch_mobile ? true : false; $settings->settings->global->latch_wired = $latch_wired ? true : false; $settings->settings->global->gate_wired = $gate_wired ? true : false; $settings->settings->global->led_enabled = $led_enabled ? true : false; return json_encode($settings, JSON_NUMERIC_CHECK); } //public function updateLatchMobile($value) { // $api = new Somfy_API(); // $settings = $this->buildSettings($value); // if ($api->update_settings($this->_base_device->getSiteId(), $this->_base_device->getId(), $settings)["http_code"] == 200) { // $this->eqlogic->checkAndUpdateCmd(BaseDevice::LATCH_MOBILE, $value); // } //} public function updateLatchWired($value) { $api = new Somfy_API(); $settings = $this->buildSettings($value, $this->_gate_wired, $this->_led_enabled); if ($api->update_settings($this->_base_device->getSiteId(), $this->_base_device->getId(), $settings)["http_code"] == 200) { $this->eqlogic->checkAndUpdateCmd(BaseDevice::LATCH_WIRED, $value); } } public function updateGateWired($value) { $api = new Somfy_API(); $settings = $this->buildSettings($this->_latch_wired, $value, $this->_led_enabled); if ($api->update_settings($this->_base_device->getSiteId(), $this->_base_device->getId(), $settings)["http_code"] == 200) { $this->eqlogic->checkAndUpdateCmd(BaseDevice::GATE_WIRED, $value); } } public function updateLedEnabled($value) { $api = new Somfy_API(); $settings = $this->buildSettings($this->_latch_wired, $this->_gate_wired, $value); if ($api->update_settings($this->_base_device->getSiteId(), $this->_base_device->getId(), $settings)["http_code"] == 200) { $this->eqlogic->checkAndUpdateCmd(BaseDevice::LED_ENABLED, $value); } } }