Skip to content

Commit

Permalink
Transforming controls to entities
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Sep 29, 2021
1 parent 56b84c0 commit 23d6e50
Show file tree
Hide file tree
Showing 107 changed files with 5,783 additions and 1,534 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ jobs:
php-qa:
name: "Quality assurance for PHP code"
runs-on: "${{ matrix.operating-system }}"
continue-on-error: "${{ matrix.experimental }}"

strategy:
fail-fast: false
matrix:
php-version: ["7.4"]
operating-system: ["ubuntu-latest"]
fail-fast: false
experimental: [false]
include:
- php-version: "8.0"
operating-system: "ubuntu-latest"
experimental: true

steps:
- name: "Checkout"
Expand Down Expand Up @@ -83,12 +89,18 @@ jobs:
php-static-analysis:
name: "Static analysis for PHP code"
runs-on: "${{ matrix.operating-system }}"
continue-on-error: "${{ matrix.experimental }}"

strategy:
fail-fast: false
matrix:
php-version: ["7.4"]
operating-system: ["ubuntu-latest"]
fail-fast: false
experimental: [false]
include:
- php-version: "8.0"
operating-system: "ubuntu-latest"
experimental: true

steps:
- name: "Checkout"
Expand Down Expand Up @@ -141,6 +153,7 @@ jobs:
name: "Tests for PHP code"
runs-on: "${{ matrix.operating-system }}"
needs: ["php-qa", "php-static-analysis"]
continue-on-error: "${{ matrix.experimental }}"

strategy:
fail-fast: false
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

[![Build Status](https://badgen.net/github/checks/FastyBird/devices-module/master?cache=300&style=flat-square)](https://github.com/FastyBird/devices-module/actions)
[![Licence](https://badgen.net/github/license/FastyBird/devices-module?cache=300&style=flat-square)](https://github.com/FastyBird/devices-module/blob/master/LICENSE.md)
[![Code coverage](https://badgen.net/coveralls/c/github/FastyBird/devices-module?cache=300&style=flat-square)](https://coveralls.io/r/FastyBird/devices-module)

![PHP](https://badgen.net/packagist/php/FastyBird/devices-module?cache=300&style=flat-square)
[![PHP code coverage](https://badgen.net/coveralls/c/github/FastyBird/devices-module?cache=300&style=flat-square)](https://coveralls.io/r/FastyBird/devices-module)
[![PHP latest stable](https://badgen.net/packagist/v/FastyBird/devices-module/latest?cache=300&style=flat-square)](https://packagist.org/packages/FastyBird/devices-module)
[![PHP downloads total](https://badgen.net/packagist/dt/FastyBird/devices-module?cache=300&style=flat-square)](https://packagist.org/packages/FastyBird/devices-module)
[![PHPStan](https://img.shields.io/badge/phpstan-enabled-brightgreen.svg?style=flat-square)](https://github.com/phpstan/phpstan)

![JS](https://img.shields.io/badge/js-es6-blue.svg?style=flat-square)
[![JS latest stable](https://badgen.net/npm/v/@fastybird/devices-module?cache=300&style=flat-square)](https://www.npmjs.com/package/@fastybird/devices-module)
[![JS downloads total](https://badgen.net/npm/dt/@fastybird/devices-module?cache=300&style=flat-square)](https://www.npmjs.com/package/@fastybird/devices-module)
![Types](https://badgen.net/npm/types/@fastybird/devices-module?cache=300&style=flat-square)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
"minimum-stability": "stable",

"require": {
"php": ">=7.4.0",
"php": ">=7.4.0|>=8.0.0",
"ext-bcmath" : "*",
"contributte/translation": "^0.8",
"cweagans/composer-patches": "^1.7",
"fastybird/application-exchange": "^0.1",
"fastybird/database": "^0.1",
"fastybird/json-api": "^0.1",
"fastybird/modules-metadata": "^0.5",
"fastybird/modules-metadata": "^0.7",
"fastybird/simple-auth": "^0.1",
"fastybird/web-server": "^0.1",
"ipub/doctrine-timestampable": "^1.5",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"lint:ts": "tslint -c tslint.json 'public/**/*.ts'"
},
"dependencies": {
"@fastybird/modules-metadata": "^0.5",
"@fastybird/modules-metadata": "^0.7",
"@fastybird/vue-wamp-v1": "^0.1",
"@fastybird/vuex-orm-wamp": "^0.1",
"@vuex-orm/core": "^0.36",
Expand Down
12 changes: 12 additions & 0 deletions public/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import DeviceProperty from '@/lib/models/device-properties/DeviceProperty'
import deviceProperties from '@/lib/models/device-properties'
import DeviceConfiguration from '@/lib/models/device-configuration/DeviceConfiguration'
import devicesConfiguration from '@/lib/models/device-configuration'
import DeviceControl from '@/lib/models/device-controls/DeviceControl'
import devicesControl from '@/lib/models/device-controls'
import DeviceConnector from '@/lib/models/device-connector/DeviceConnector'
import deviceConnector from '@/lib/models/device-connector/index'
import Channel from '@/lib/models/channels/Channel'
Expand All @@ -15,8 +17,12 @@ import ChannelProperty from '@/lib/models/channel-properties/ChannelProperty'
import channelProperties from '@/lib/models/channel-properties'
import ChannelConfiguration from '@/lib/models/channel-configuration/ChannelConfiguration'
import channelsConfiguration from '@/lib/models/channel-configuration'
import ChannelControl from '@/lib/models/channel-controls/ChannelControl'
import channelsControl from '@/lib/models/channel-controls'
import Connector from '@/lib/models/connectors/Connector'
import connectors from '@/lib/models/connectors'
import ConnectorControl from '@/lib/models/connector-controls/ConnectorControl'
import connectorsControl from '@/lib/models/connector-controls'

// Import typing
import { ComponentsInterface, GlobalConfigInterface } from '@/types/devices-module'
Expand All @@ -34,11 +40,14 @@ const install: Plugin = function installVuexOrmWamp(components: ComponentsInterf
config.database.register(Device, devices)
config.database.register(DeviceProperty, deviceProperties)
config.database.register(DeviceConfiguration, devicesConfiguration)
config.database.register(DeviceControl, devicesControl)
config.database.register(DeviceConnector, deviceConnector)
config.database.register(Channel, channels)
config.database.register(ChannelProperty, channelProperties)
config.database.register(ChannelConfiguration, channelsConfiguration)
config.database.register(ChannelControl, channelsControl)
config.database.register(Connector, connectors)
config.database.register(ConnectorControl, connectorsControl)
}

// Create module definition for VuexORM.use()
Expand All @@ -52,11 +61,14 @@ export default plugin
// Export model classes
export {
ChannelConfiguration,
ChannelControl,
ChannelProperty,
Channel,
Connector,
ConnectorControl,
DeviceConfiguration,
DeviceConnector,
DeviceControl,
DeviceProperty,
Device,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export default class ChannelConfiguration extends Configuration implements Chann
})
}

static reset(): void {
ChannelConfiguration.dispatch('reset')
static reset(): Promise<void> {
return ChannelConfiguration.dispatch('reset')
}
}
5 changes: 4 additions & 1 deletion public/lib/models/channel-configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from 'jsona/lib/JsonaTypes'

import {
ChannelDataResponseInterface,
ChannelEntityTypes,
ChannelInterface,
} from '@/lib/models/channels/types'
Expand Down Expand Up @@ -77,7 +78,7 @@ interface ChannelRelationshipsResponseInterface extends TJsonApiRelation {
}

interface ChannelConfigurationRelationshipsResponseInterface extends TJsonApiRelationships {
device: ChannelRelationshipsResponseInterface
channel: ChannelRelationshipsResponseInterface
}

export interface ChannelConfigurationDataResponseInterface extends TJsonApiData {
Expand All @@ -89,10 +90,12 @@ export interface ChannelConfigurationDataResponseInterface extends TJsonApiData

export interface ChannelConfigurationResponseInterface extends TJsonApiBody {
data: ChannelConfigurationDataResponseInterface
included?: (ChannelDataResponseInterface)[]
}

export interface ChannelConfigurationsResponseInterface extends TJsonApiBody {
data: ChannelConfigurationDataResponseInterface[]
included?: (ChannelDataResponseInterface)[]
}

// UPDATE ENTITY INTERFACES
Expand Down
92 changes: 92 additions & 0 deletions public/lib/models/channel-controls/ChannelControl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {
Fields,
Model,
} from '@vuex-orm/core'

import Channel from '@/lib/models/channels/Channel'
import { ChannelInterface } from '@/lib/models/channels/types'
import {
ChannelControlEntityTypes,
ChannelControlInterface,
} from '@/lib/models/channel-controls/types'
import Device from '@/lib/models/devices/Device'
import { DeviceInterface } from '@/lib/models/devices/types'

// ENTITY MODEL
// ============
export default class ChannelControl extends Model implements ChannelControlInterface {
static get entity(): string {
return 'devices_channel_control'
}

static fields(): Fields {
return {
id: this.string(''),
type: this.string(ChannelControlEntityTypes.CONTROL),

name: this.string(''),

channel: this.belongsTo(Channel, 'id'),
channelBackward: this.hasOne(Channel, 'id', 'channelId'),

channelId: this.string(''),
}
}

id!: string
type!: ChannelControlEntityTypes

name!: string

channel!: ChannelInterface | null
channelBackward!: ChannelInterface | null

channelId!: string

get deviceInstance(): DeviceInterface | null {
if (this.channel === null) {
const channel = Channel
.query()
.where('id', this.channelId)
.first()

if (channel !== null) {
return Device
.query()
.where('id', channel.deviceId)
.first()
}

return null
}

return Device
.query()
.where('id', this.channel.deviceId)
.first()
}

static async get(channel: ChannelInterface, id: string): Promise<boolean> {
return await ChannelControl.dispatch('get', {
channel,
id,
})
}

static async fetch(channel: ChannelInterface): Promise<boolean> {
return await ChannelControl.dispatch('fetch', {
channel,
})
}

static transmitCommand(control: ChannelControl, value?: string | number | boolean | null): Promise<boolean> {
return ChannelControl.dispatch('transmitCommand', {
control,
value,
})
}

static reset(): Promise<void> {
return ChannelControl.dispatch('reset')
}
}
Loading

0 comments on commit 23d6e50

Please sign in to comment.