Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed Jan 25, 2024
1 parent cd66127 commit cd7d9e5
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 228 deletions.
62 changes: 29 additions & 33 deletions ONVIF Digital Input/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,6 @@ public function Create(): void
parent::Create();
$this->RegisterAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, []);
}
public function ApplyChanges(): void
{
//Never delete this line!
parent::ApplyChanges();
if (IPS_GetKernelRunlevel() != KR_READY) {
return;
}
if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') {
$this->SetStatus(IS_INACTIVE);
return;
}
if ($this->HasActiveParent()) {
$Capabilities = @$this->GetCapabilities();
if (!$Capabilities) {
$this->SetStatus(IS_EBASE + 1);
return;
}
$this->WriteAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, $Capabilities['DigitalInputs']);
foreach ($Capabilities['DigitalInputs'] as $Name => $DigitalInput) {
$Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name);
$Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident);
$this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0);
}

$Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic));
$this->SendDebug('EventConfig', $Events, 0);
if (count($Events) != 1) {
$this->SetStatus(IS_EBASE + 1);
} else {
$this->SetStatus(IS_ACTIVE);
}
}
}

public function ReceiveData(string $JSONString): string
{
Expand Down Expand Up @@ -120,4 +87,33 @@ public function GetConfigurationForm(): string

return json_encode($Form);
}
protected function InitFilterAndEvents(): void
{
parent::InitFilterAndEvents();
if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') {
$this->SetStatus(IS_INACTIVE);
return;
}
if ($this->HasActiveParent()) {
$Capabilities = @$this->GetCapabilities();
if (!$Capabilities) {
$this->SetStatus(IS_EBASE + 1);
return;
}
$this->WriteAttributeArray(\ONVIF\Input\Attribute::DigitalInputs, $Capabilities['DigitalInputs']);
foreach ($Capabilities['DigitalInputs'] as $Name => $DigitalInput) {
$Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name);
$Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident);
$this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0);
}

$Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic));
$this->SendDebug('EventConfig', $Events, 0);
if (count($Events) != 1) {
$this->SetStatus(IS_EBASE + 1);
} else {
$this->SetStatus(IS_ACTIVE);
}
}
}
}
80 changes: 38 additions & 42 deletions ONVIF Digital Output/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,6 @@ public function Create(): void
$this->RegisterAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, []);
}

public function ApplyChanges(): void
{
//Never delete this line!
parent::ApplyChanges();
if (IPS_GetKernelRunlevel() != KR_READY) {
return;
}
if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') {
$this->SetStatus(IS_INACTIVE);
return;
}
if ($this->HasActiveParent()) {
$Capabilities = @$this->GetCapabilities();
if (!$Capabilities) {
$this->SetStatus(IS_EBASE + 1);
return;
}
if ($Capabilities['XAddr'][\ONVIF\NS::DeviceIO]) {
$this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::DeviceIO];
$this->wsdl = \ONVIF\WSDL::DeviceIO;
} else {
$this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::Management];
$this->wsdl = \ONVIF\WSDL::Management;
}
$this->WriteAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, $Capabilities['RelayOutputs']);
foreach ($Capabilities['RelayOutputs'] as $Name => $RelayOutput) {
$Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name);
$Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident);
$this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0);
$this->EnableAction($Ident);
}
$Events = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties);
if (count($Events) != 1) {
$this->SetStatus(IS_EBASE + 1);
} else {
$this->SetStatus(IS_ACTIVE);
}
return;
}
$this->SetStatus(IS_ACTIVE);
}

public function SetRelayOutputState(string $Ident, bool $Value): bool
{
if (!array_key_exists($Ident, $this->ReadAttributeArray(\ONVIF\Output\Attribute::RelayOutputs))) {
Expand Down Expand Up @@ -201,4 +159,42 @@ public function GetConfigurationForm(): string

return json_encode($Form);
}

protected function InitFilterAndEvents(): void
{
parent::InitFilterAndEvents();
if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') {
$this->SetStatus(IS_INACTIVE);
return;
}
if ($this->HasActiveParent()) {
$Capabilities = @$this->GetCapabilities();
if (!$Capabilities) {
$this->SetStatus(IS_EBASE + 1);
return;
}
if ($Capabilities['XAddr'][\ONVIF\NS::DeviceIO]) {
$this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::DeviceIO];
$this->wsdl = \ONVIF\WSDL::DeviceIO;
} else {
$this->xAddr = $Capabilities['XAddr'][\ONVIF\NS::Management];
$this->wsdl = \ONVIF\WSDL::Management;
}
$this->WriteAttributeArray(\ONVIF\Output\Attribute::RelayOutputs, $Capabilities['RelayOutputs']);
foreach ($Capabilities['RelayOutputs'] as $Name => $RelayOutput) {
$Ident = str_replace([' - ', ':'], ['_', ''], (string) $Name);
$Ident = preg_replace('/[^a-zA-Z\d]/u', '_', $Ident);
$this->RegisterVariableBoolean($Ident, $Name, '~Switch', 0);
$this->EnableAction($Ident);
}
$Events = $this->ReadAttributeArray(\ONVIF\Device\Attribute::EventProperties);
if (count($Events) != 1) {
$this->SetStatus(IS_EBASE + 1);
} else {
$this->SetStatus(IS_ACTIVE);
}
return;
}
$this->SetStatus(IS_ACTIVE);
}
}
40 changes: 17 additions & 23 deletions ONVIF Events/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,6 @@
class ONVIFEvents extends ONVIFModuleBase
{
public const wsdl = '';
public function Create(): void
{
parent::Create();
}
public function ApplyChanges(): void
{
//Never delete this line!
parent::ApplyChanges();
if (IPS_GetKernelRunlevel() != KR_READY) {
return;
}
if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') {
$this->SetStatus(IS_INACTIVE);
} else {
$Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic));
$this->SendDebug('EventConfig', $Events, 0);
if (count($Events) == 0) {
$this->SetStatus(IS_INACTIVE);
} else {
$this->SetStatus(IS_ACTIVE);
}
}
}

public function ReceiveData(string $JSONString): string
{
Expand All @@ -56,4 +33,21 @@ public function GetConfigurationForm(): string
$this->SendDebug('FORM', json_last_error_msg(), 0);
return json_encode($Form);
}

protected function InitFilterAndEvents(): void
{
parent::InitFilterAndEvents();

if ($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic) == '') {
$this->SetStatus(IS_INACTIVE);
} else {
$Events = $this->GetEvents($this->ReadPropertyString(\ONVIF\Device\Property::EventTopic));
$this->SendDebug('EventConfig', $Events, 0);
if (count($Events) == 0) {
$this->SetStatus(IS_INACTIVE);
} else {
$this->SetStatus(IS_ACTIVE);
}
}
}
}
62 changes: 31 additions & 31 deletions ONVIF Image Grabber/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,6 @@ public function Create(): void
$this->RegisterTimer(\ONVIF\ImageGrabber\Timer::UpdateImage, 0, 'ONVIF_UpdateImage(' . $this->InstanceID . ');');
$this->ImageURL = false;
}
public function ApplyChanges(): void
{
//Never delete this line!
parent::ApplyChanges();
$MediaId = $this->GetMediaId();
IPS_SetMediaCached($MediaId, $this->ReadPropertyBoolean(\ONVIF\ImageGrabber\Property::UseCaching));

if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == '') {
$this->SetStatus(IS_INACTIVE);
$this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0);
return;
}
if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) == '') {
$this->SetStatus(IS_INACTIVE);
$this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0);
return;
}
if (IPS_GetKernelRunlevel() != KR_READY) {
return;
}

$this->ImageURL = $SnapshotURL = $this->GetSnapshotUri();
if ($SnapshotURL) {
$this->SetStatus(IS_ACTIVE);
$this->UpdateImage();
$this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, $this->ReadPropertyInteger(\ONVIF\ImageGrabber\Property::Interval) * 1000);
} else {
$this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0);
$this->SetStatus(IS_EBASE + 1);
}
}
public function UpdateImage(): bool
{
$URL = $this->ImageURL;
Expand Down Expand Up @@ -344,6 +313,37 @@ public function RequestAction(string $Ident, mixed $Value, bool &$done = false):
return;
}
}

protected function InitFilterAndEvents(): void
{
parent::InitFilterAndEvents();
$MediaId = $this->GetMediaId();
IPS_SetMediaCached($MediaId, $this->ReadPropertyBoolean(\ONVIF\ImageGrabber\Property::UseCaching));

if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::VideoSource) == '') {
$this->SetStatus(IS_INACTIVE);
$this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0);
return;
}
if ($this->ReadPropertyString(\ONVIF\ImageGrabber\Property::Profile) == '') {
$this->SetStatus(IS_INACTIVE);
$this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0);
return;
}
if (IPS_GetKernelRunlevel() != KR_READY) {
return;
}

$this->ImageURL = $SnapshotURL = $this->GetSnapshotUri();
if ($SnapshotURL) {
$this->SetStatus(IS_ACTIVE);
$this->UpdateImage();
$this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, $this->ReadPropertyInteger(\ONVIF\ImageGrabber\Property::Interval) * 1000);
} else {
$this->SetTimerInterval(\ONVIF\ImageGrabber\Timer::UpdateImage, 0);
$this->SetStatus(IS_EBASE + 1);
}
}
protected function IOChangeState(int $State): void
{
parent::IOChangeState($State);
Expand Down
Loading

0 comments on commit cd7d9e5

Please sign in to comment.