Skip to content

Commit

Permalink
Using updated modules metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Aug 9, 2021
1 parent 8a92819 commit 2ebc945
Show file tree
Hide file tree
Showing 25 changed files with 94 additions and 92 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -22,7 +22,7 @@

Devices module is a combined [Nette framework](https://nette.org) extension and [Vex ORM](https://vuex-orm.org) plugin and also [Python](https://python.org) module for managing connected devices and their basic logic.

[FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) devices module is an [Apache2 licensed](http://www.apache.org/licenses/LICENSE-2.0) distributed extension, developed in [PHP](https://www.php.net) with [Nette framework](https://nette.org) and in [Typescript](https://www.typescriptlang.org).
[FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) devices module is an [Apache2 licensed](http://www.apache.org/licenses/LICENSE-2.0) distributed extension, developed in [PHP](https://www.php.net) with [Nette framework](https://nette.org), in [Typescript](https://www.typescriptlang.org) and also in [Python](https://python.org).

### Features:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -39,7 +39,7 @@
"fastybird/application-exchange": "^0.1",
"fastybird/database": "^0.1",
"fastybird/json-api": "^0.1",
"fastybird/modules-metadata": "^0.4",
"fastybird/modules-metadata": "^0.5",
"fastybird/simple-auth": "^0.1",
"fastybird/web-server": "^0.1",
"ipub/doctrine-timestampable": "^1.5",
Expand Down
2 changes: 1 addition & 1 deletion devices_module/__init__.py
Expand Up @@ -16,4 +16,4 @@
Devices module
"""

__version__ = "0.2.12"
__version__ = "0.2.13"
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@fastybird/devices-module",
"version": "0.2.12",
"version": "0.2.13",
"description": "Devices module data model plugin",
"keywords": [
"devices",
Expand Down Expand Up @@ -38,7 +38,7 @@
"lint:ts": "tslint -c tslint.json 'public/**/*.ts'"
},
"dependencies": {
"@fastybird/modules-metadata": "^0.4",
"@fastybird/modules-metadata": "^0.5",
"@fastybird/vue-wamp-v1": "^0.1",
"@fastybird/vuex-orm-wamp": "^0.1",
"@vuex-orm/core": "^0.36",
Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/channel-configuration/index.ts
Expand Up @@ -280,7 +280,7 @@ const moduleActions: ActionTree<ChannelConfigurationState, unknown> = {
device: device.key,
channel: channel.key,
configuration: payload.configuration.key,
expected: payload.value,
expected_value: payload.value,
},
})
.then((response: RpCallResponse<{ data: string }>): void => {
Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/channel-properties/index.ts
Expand Up @@ -280,7 +280,7 @@ const moduleActions: ActionTree<ChannelPropertyState, unknown> = {
device: device.key,
channel: channel.key,
property: payload.property.key,
expected: payload.value,
expected_value: payload.value,
},
})
.then((response: RpCallResponse<{ data: string }>): void => {
Expand Down
4 changes: 2 additions & 2 deletions public/lib/models/channel-properties/types.ts
Expand Up @@ -49,8 +49,8 @@ interface ChannelPropertyAttributesResponseInterface {
unit: string | null
format: string | null

value: string | number | boolean | null
expected: string | number | boolean | null
actualValue: string | number | boolean | null
expectedValue: string | number | boolean | null
pending: boolean
}

Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/device-configuration/index.ts
Expand Up @@ -272,7 +272,7 @@ const moduleActions: ActionTree<DeviceConfigurationState, unknown> = {
data: {
device: device.key,
configuration: payload.configuration.key,
expected: payload.value,
expected_value: payload.value,
},
})
.then((response: RpCallResponse<{ data: string }>): void => {
Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/device-properties/index.ts
Expand Up @@ -272,7 +272,7 @@ const moduleActions: ActionTree<DevicePropertyState, unknown> = {
data: {
device: device.key,
property: payload.property.key,
expected: payload.value,
expected_value: payload.value,
},
})
.then((response: RpCallResponse<{ data: string }>): void => {
Expand Down
4 changes: 2 additions & 2 deletions public/lib/models/device-properties/types.ts
Expand Up @@ -46,8 +46,8 @@ interface DevicePropertyAttributesResponseInterface {
unit: string | null
format: string | null

value: string | number | boolean | null
expected: string | number | boolean | null
actualValue: string | number | boolean | null
expectedValue: string | number | boolean | null
pending: boolean
}

Expand Down
56 changes: 28 additions & 28 deletions public/lib/models/properties/Property.ts
Expand Up @@ -29,8 +29,8 @@ export default class Property extends Model implements PropertyInterface {
unit: this.string(null).nullable(),
format: this.string(null).nullable(),

value: this.attr(null).nullable(),
expected: this.attr(null).nullable(),
actualValue: this.attr(null).nullable(),
expectedValue: this.attr(null).nullable(),
pending: this.boolean(false),

// Relations
Expand All @@ -49,8 +49,8 @@ export default class Property extends Model implements PropertyInterface {
unit!: string | null
format!: string | null

value!: string | number | boolean | null
expected!: string | number | boolean | null
actualValue!: string | number | boolean | null
expectedValue!: string | number | boolean | null
pending!: boolean

command!: PropertyCommandState | null
Expand Down Expand Up @@ -124,36 +124,36 @@ export default class Property extends Model implements PropertyInterface {
}

get binaryValue(): boolean {
if (this.value === null) {
if (this.actualValue === null) {
return false
}

if (this.isBoolean) {
if (typeof this.value === 'boolean') {
return this.value
if (typeof this.actualValue === 'boolean') {
return this.actualValue
}

return ['true', '1', 't', 'y', 'yes'].includes(this.value.toString().toLocaleLowerCase())
return ['true', '1', 't', 'y', 'yes'].includes(this.actualValue.toString().toLocaleLowerCase())
} else if (this.isEnum) {
return this.value === 'on'
return this.actualValue === 'on'
}

return false
}

get binaryExpected(): boolean | null {
if (this.expected === null) {
if (this.expectedValue === null) {
return null
}

if (this.isBoolean) {
if (typeof this.expected === 'boolean') {
return this.expected
if (typeof this.expectedValue === 'boolean') {
return this.expectedValue
}

return ['true', '1', 't', 'y', 'yes'].includes(this.expected.toString().toLocaleLowerCase())
return ['true', '1', 't', 'y', 'yes'].includes(this.expectedValue.toString().toLocaleLowerCase())
} else if (this.isEnum) {
return this.expected === 'on'
return this.expectedValue === 'on'
}

return false
Expand All @@ -169,10 +169,10 @@ export default class Property extends Model implements PropertyInterface {
) {
switch (this.identifier) {
case 'air_quality':
if (this.value as number > 7) {
if (this.actualValue as number > 7) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.unhealthy`).toString()
} else if (this.value as number > 4) {
} else if (this.actualValue as number > 4) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.moderate`).toString()
}
Expand All @@ -181,10 +181,10 @@ export default class Property extends Model implements PropertyInterface {
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.good`).toString()

case 'light_level':
if (this.value as number > 8) {
if (this.actualValue as number > 8) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.dusky`).toString()
} else if (this.value as number > 4) {
} else if (this.actualValue as number > 4) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.normal`).toString()
}
Expand All @@ -193,10 +193,10 @@ export default class Property extends Model implements PropertyInterface {
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.bright`).toString()

case 'noise_level':
if (this.value as number > 6) {
if (this.actualValue as number > 6) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.noisy`).toString()
} else if (this.value as number > 3) {
} else if (this.actualValue as number > 3) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.normal`).toString()
}
Expand All @@ -210,7 +210,7 @@ export default class Property extends Model implements PropertyInterface {
}

get analogExpected(): string | null {
if (this.expected === null) {
if (this.expectedValue === null) {
return null
}

Expand All @@ -223,10 +223,10 @@ export default class Property extends Model implements PropertyInterface {
) {
switch (this.identifier) {
case 'air_quality':
if (this.expected > 7) {
if (this.expectedValue > 7) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.unhealthy`).toString()
} else if (this.expected > 4) {
} else if (this.expectedValue > 4) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.moderate`).toString()
}
Expand All @@ -235,10 +235,10 @@ export default class Property extends Model implements PropertyInterface {
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.good`).toString()

case 'light_level':
if (this.expected > 8) {
if (this.expectedValue > 8) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.dusky`).toString()
} else if (this.expected > 4) {
} else if (this.expectedValue > 4) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.normal`).toString()
}
Expand All @@ -247,10 +247,10 @@ export default class Property extends Model implements PropertyInterface {
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.bright`).toString()

case 'noise_level':
if (this.expected > 6) {
if (this.expectedValue > 6) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.noisy`).toString()
} else if (this.expected > 3) {
} else if (this.expectedValue > 3) {
// @ts-ignore
return storeInstance.$i18n.t(`devicesModule.vendors.${this.deviceInstance.hardwareManufacturer}.properties.${this.identifier}.values.normal`).toString()
}
Expand All @@ -264,7 +264,7 @@ export default class Property extends Model implements PropertyInterface {
}

get formattedValue(): string {
const value = parseFloat(String(this.value))
const value = parseFloat(String(this.actualValue))
const decimals = 2
const decPoint = ','
const thousandsSeparator = ' '
Expand Down
4 changes: 2 additions & 2 deletions public/lib/models/properties/types.ts
Expand Up @@ -61,8 +61,8 @@ export interface PropertyInterface {
unit: string | null
format: string | null

value: string | number | boolean | null
expected: string | number | boolean | null
actualValue: string | number | boolean | null
expectedValue: string | number | boolean | null
pending: boolean

command: PropertyCommandState | null
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
fastybird-application-events>=0.1
fastybird-modules-metadata>=0.4
fastybird-modules-metadata>=0.5
pony>=0.7
setuptools>=57.4
2 changes: 1 addition & 1 deletion src/Controllers/ConnectorsV1Controller.php
Expand Up @@ -214,7 +214,7 @@ public function readRelationship(
}

/**
* @param string $id
* @param non-empty-string $id
*
* @return Entities\Connectors\IConnector
*
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/Finders/TChannelFinder.php
Expand Up @@ -31,7 +31,7 @@ trait TChannelFinder
{

/**
* @param string $id
* @param non-empty-string $id
* @param Entities\Devices\IDevice $device
*
* @return Entities\Channels\IChannel
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/Finders/TDeviceFinder.php
Expand Up @@ -31,7 +31,7 @@ trait TDeviceFinder
{

/**
* @param string $id
* @param non-empty-string $id
*
* @return Entities\Devices\IDevice
*
Expand Down
25 changes: 13 additions & 12 deletions src/Schemas/Channels/Properties/PropertySchema.php
Expand Up @@ -56,7 +56,8 @@ final class PropertySchema extends JsonApiSchemas\JsonApiSchema
public function __construct(
Routing\IRouter $router,
?Models\States\IPropertyRepository $propertyRepository
) {
)
{
$this->router = $router;
$this->propertyRepository = $propertyRepository;
}
Expand Down Expand Up @@ -90,17 +91,17 @@ public function getAttributes($property, JsonApi\Contracts\Schema\ContextInterfa
$state = $this->propertyRepository === null ? null : $this->propertyRepository->findOne($property->getId());

return [
'key' => $property->getKey(),
'identifier' => $property->getIdentifier(),
'name' => $property->getName(),
'settable' => $property->isSettable(),
'queryable' => $property->isQueryable(),
'data_type' => $property->getDataType() !== null ? $property->getDataType()->getValue() : null,
'unit' => $property->getUnit(),
'format' => is_array($property->getFormat()) ? implode(',', $property->getFormat()) : $property->getFormat(),
'value' => $state !== null ? $state->getValue() : null,
'expected' => $state !== null ? $state->getExpected() : null,
'pending' => $state !== null && $state->isPending(),
'key' => $property->getKey(),
'identifier' => $property->getIdentifier(),
'name' => $property->getName(),
'settable' => $property->isSettable(),
'queryable' => $property->isQueryable(),
'data_type' => $property->getDataType() !== null ? $property->getDataType()->getValue() : null,
'unit' => $property->getUnit(),
'format' => is_array($property->getFormat()) ? implode(',', $property->getFormat()) : $property->getFormat(),
'actual_value' => $state !== null ? $state->getActualValue() : null,
'expected_value' => $state !== null ? $state->getExpectedValue() : null,
'pending' => $state !== null && $state->isPending(),
];
}

Expand Down
25 changes: 13 additions & 12 deletions src/Schemas/Devices/Properties/PropertySchema.php
Expand Up @@ -56,7 +56,8 @@ final class PropertySchema extends JsonApiSchemas\JsonApiSchema
public function __construct(
Routing\IRouter $router,
?Models\States\IPropertyRepository $propertyRepository
) {
)
{
$this->router = $router;
$this->propertyRepository = $propertyRepository;
}
Expand Down Expand Up @@ -90,17 +91,17 @@ public function getAttributes($property, JsonApi\Contracts\Schema\ContextInterfa
$state = $this->propertyRepository === null ? null : $this->propertyRepository->findOne($property->getId());

return [
'key' => $property->getKey(),
'identifier' => $property->getIdentifier(),
'name' => $property->getName(),
'settable' => $property->isSettable(),
'queryable' => $property->isQueryable(),
'data_type' => $property->getDataType() !== null ? $property->getDataType()->getValue() : null,
'unit' => $property->getUnit(),
'format' => is_array($property->getFormat()) ? implode(',', $property->getFormat()) : $property->getFormat(),
'value' => $state !== null ? $state->getValue() : null,
'expected' => $state !== null ? $state->getExpected() : null,
'pending' => $state !== null && $state->isPending(),
'key' => $property->getKey(),
'identifier' => $property->getIdentifier(),
'name' => $property->getName(),
'settable' => $property->isSettable(),
'queryable' => $property->isQueryable(),
'data_type' => $property->getDataType() !== null ? $property->getDataType()->getValue() : null,
'unit' => $property->getUnit(),
'format' => is_array($property->getFormat()) ? implode(',', $property->getFormat()) : $property->getFormat(),
'actual_value' => $state !== null ? $state->getActualValue() : null,
'expected_value' => $state !== null ? $state->getExpectedValue() : null,
'pending' => $state !== null && $state->isPending(),
];
}

Expand Down

0 comments on commit 2ebc945

Please sign in to comment.