Skip to content

Commit

Permalink
Clear models (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 9, 2024
1 parent a35dcd4 commit 9997ac4
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/Helpers/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public function getIpAddress(MetadataDocuments\DevicesModule\Device $device): st
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return null;
}

$value = $property->getValue();
assert(is_string($value) || $value === null);
assert(is_string($value));

return $value;
}
Expand All @@ -88,14 +88,14 @@ public function getPort(MetadataDocuments\DevicesModule\Device $device): int
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return Entities\VieraDevice::DEFAULT_PORT;
}

$value = $property->getValue();
assert(is_int($value) || $value === null);
assert(is_int($value));

return $value ?? Entities\VieraDevice::DEFAULT_PORT;
return $value;
}

/**
Expand All @@ -114,14 +114,14 @@ public function isEncrypted(MetadataDocuments\DevicesModule\Device $device): boo
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return false;
}

$value = $property->getValue();
assert(is_bool($value) || $value === null);
assert(is_bool($value));

return $value ?? false;
return $value;
}

/**
Expand All @@ -140,12 +140,12 @@ public function getAppId(MetadataDocuments\DevicesModule\Device $device): string
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return null;
}

$value = $property->getValue();
assert(is_string($value) || $value === null);
assert(is_string($value));

return $value;
}
Expand All @@ -166,12 +166,12 @@ public function getEncryptionKey(MetadataDocuments\DevicesModule\Device $device)
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return null;
}

$value = $property->getValue();
assert(is_string($value) || $value === null);
assert(is_string($value));

return $value;
}
Expand All @@ -192,12 +192,12 @@ public function getModel(MetadataDocuments\DevicesModule\Device $device): string
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return null;
}

$value = $property->getValue();
assert(is_string($value) || $value === null);
assert(is_string($value));

return $value;
}
Expand All @@ -218,12 +218,12 @@ public function getManufacturer(MetadataDocuments\DevicesModule\Device $device):
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return null;
}

$value = $property->getValue();
assert(is_string($value) || $value === null);
assert(is_string($value));

return $value;
}
Expand All @@ -244,12 +244,12 @@ public function getMacAddress(MetadataDocuments\DevicesModule\Device $device): s
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return null;
}

$value = $property->getValue();
assert(is_string($value) || $value === null);
assert(is_string($value));

return $value;
}
Expand All @@ -270,12 +270,12 @@ public function getSerialNumber(MetadataDocuments\DevicesModule\Device $device):
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

if ($property === null) {
if ($property?->getValue() === null) {
return null;
}

$value = $property->getValue();
assert(is_string($value) || $value === null);
assert(is_string($value));

return $value;
}
Expand All @@ -296,12 +296,13 @@ public function getStateReadingDelay(MetadataDocuments\DevicesModule\Device $dev
MetadataDocuments\DevicesModule\DeviceVariableProperty::class,
);

$value = $property?->getValue();

if (!is_numeric($value)) {
if ($property?->getValue() === null) {
return Entities\VieraDevice::STATE_READING_DELAY;
}

$value = $property->getValue();
assert(is_numeric($value));

return floatval($value);
}

Expand Down

0 comments on commit 9997ac4

Please sign in to comment.