Skip to content

Commit

Permalink
Merge branch 'master' into sonoff-missing-devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Mar 21, 2020
2 parents 0e72e41 + 65624b6 commit e5fd100
Show file tree
Hide file tree
Showing 44 changed files with 365 additions and 232 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -43,7 +43,7 @@ This is just a simple scenario, possibilities with Gladys are just endless. Don'

Right now we are migrating from Gladys 3 to Gladys 4, a new release rewrote from scratch. If you want to install Gladys 3, visit [our website](https://gladysassistant.com).

To install Gladys 4 Alpha, read the following instructions.
To install Gladys 4 Beta, read the following instructions.

We use Docker to deploy Gladys 4, so it's easy to install it on any system.

Expand All @@ -69,7 +69,7 @@ It's only thanks to donation from the community that my open-source work is sust

To support the project, you can:

- Support monthly, 9.99€/month with the [Gladys Community Package](https://gladysassistant.com/gladys-community-package).
- Support monthly, 9.99€/month with [Gladys Plus](https://gladysassistant.com/pricing).
- Donate with Bitcoin: 3KQiX1FtbdXLXPH9UfLSyuzRMDRGY52EiA

## Links
Expand All @@ -82,4 +82,4 @@ To support the project, you can:

## Copyright & License

Copyright (c) 2013-2019 Gladys Assistant - Released under the [Apache 2.0 License](https://github.com/gladysassistant/Gladys/blob/master/LICENSE).
Copyright (c) 2013-2020 Gladys Assistant - Released under the [Apache 2.0 License](https://github.com/gladysassistant/Gladys/blob/master/LICENSE).
6 changes: 2 additions & 4 deletions .codecov.yml → codecov.yml
Expand Up @@ -3,12 +3,10 @@ coverage:
project:
server:
target: 90%
flags: server
flags:
- server

flags:
server:
paths:
- server
front:
paths:
- front
6 changes: 3 additions & 3 deletions front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions front/package.json
Expand Up @@ -4,10 +4,10 @@
"start": "per-env",
"start:production": "npm run -s serve",
"start:development": "npm run -s dev",
"build": "cross-env NODE_ENV=production preact build --no-prerender",
"serve": "preact build && preact serve",
"dev": "preact watch -p 1444",
"eslint": "eslint src --ext .json --ext .js",
"build": "cross-env NODE_ENV=production preact build --template src/template.html --no-prerender",
"serve": "npm run build && preact serve",
"dev": "preact watch -p 1444 --template src/template.html",
"eslint": "eslint src --ext .json --ext .js --ext .jsx",
"prettier-check": "prettier --check '**/*.js' '**/*.jsx' '**/*.json'",
"prettier": "prettier --write '**/*.js' '**/*.jsx' '**/*.json'",
"test": "jest --coverage"
Expand All @@ -26,7 +26,7 @@
"prettier": "^1.17.1"
},
"dependencies": {
"@gladysassistant/gladys-gateway-js": "^3.2.1",
"@gladysassistant/gladys-gateway-js": "^3.2.3",
"axios": "^0.18.0",
"classnames": "^2.2.6",
"cropperjs": "^1.5.1",
Expand Down
17 changes: 0 additions & 17 deletions front/src/actions/dashboard/edit-boxes/editDevicesInRoom.js
@@ -1,26 +1,9 @@
import { RequestStatus } from '../../../utils/consts';
import createBoxActions from '../boxActions';

function createActions(store) {
const boxActions = createBoxActions(store);

const actions = {
async getRooms(state) {
store.setState({
DashboardEditDeviceInRoomStatus: RequestStatus.Getting
});
try {
const rooms = await state.httpClient.get('/api/v1/room');
store.setState({
rooms,
DashboardEditDeviceInRoomStatus: RequestStatus.Success
});
} catch (e) {
store.setState({
DashboardEditDeviceInRoomStatus: RequestStatus.Error
});
}
},
updateBoxRoom(state, x, y, room) {
boxActions.updateBoxConfig(state, x, y, {
room
Expand Down
17 changes: 0 additions & 17 deletions front/src/actions/dashboard/edit-boxes/editTemperatureInRoom.js
@@ -1,26 +1,9 @@
import { RequestStatus } from '../../../utils/consts';
import createBoxActions from '../boxActions';

function createActions(store) {
const boxActions = createBoxActions(store);

const actions = {
async getRooms(state) {
store.setState({
DashboardEditTemperatureInRoomStatus: RequestStatus.Getting
});
try {
const rooms = await state.httpClient.get('/api/v1/room');
store.setState({
rooms,
DashboardEditTemperatureInRoomStatus: RequestStatus.Success
});
} catch (e) {
store.setState({
DashboardEditTemperatureInRoomStatus: RequestStatus.Error
});
}
},
updateBoxRoom(state, x, y, room) {
boxActions.updateBoxConfig(state, x, y, {
room
Expand Down
33 changes: 30 additions & 3 deletions front/src/actions/house.js
Expand Up @@ -121,6 +121,25 @@ function createActions(store) {
});
store.setState(newState);
},
editRoom(state, houseIndex, roomIndex, property, value) {
const newState = update(state, {
houses: {
[houseIndex]: {
rooms: {
[roomIndex]: {
[property]: {
$set: value
},
to_update: {
$set: true
}
}
}
}
}
});
store.setState(newState);
},
addHouse(state) {
const newState = update(state, {
houses: {
Expand Down Expand Up @@ -154,10 +173,12 @@ function createActions(store) {

const promises = house.rooms.map(async room => {
if (room.to_delete) {
return state.httpClient.delete(`/api/v1/room/${room.selector}`, room);
return state.httpClient.delete(`/api/v1/room/${room.selector}`);
}
if (!room.id) {
return state.httpClient.post(`/api/v1/house/${houseCreatedOrUpdated.selector}/room`, room);
} else if (room.to_update) {
return state.httpClient.patch(`/api/v1/room/${room.selector}`, { name: room.name });
}
return room;
});
Expand Down Expand Up @@ -193,8 +214,8 @@ function createActions(store) {
store.setState(newState);
} catch (e) {
const status = get(e, 'response.status');
const errorValue = get(e, 'response.data.error.value');
if (status === 409 && errorValue === 'room') {
const url = get(e, 'response.config.url');
if (status === 409 && url.endsWith('/room')) {
store.setState({
houseUpdateStatus: {
[house.id]: RequestStatus.RoomConflictError
Expand All @@ -206,6 +227,12 @@ function createActions(store) {
[house.id]: RequestStatus.ConflictError
}
});
} else if (status === 422 && url.includes('/room/')) {
store.setState({
houseUpdateStatus: {
[house.id]: RequestStatus.RoomValidationError
}
});
} else if (status === 422) {
store.setState({
houseUpdateStatus: {
Expand Down
5 changes: 4 additions & 1 deletion front/src/actions/login/loginGateway.js
Expand Up @@ -75,10 +75,13 @@ function createActions(store) {
// save informations in localstorage
state.session.saveLoginInformations(data);
// connect
state.session.connect();
await state.session.connect();
if (data.gladysUserId) {
// get user
const user = await state.httpClient.get('/api/v1/me');
store.setState({
user
});
// save user
state.session.saveUser(user);
// get profile picture
Expand Down
13 changes: 7 additions & 6 deletions front/src/actions/main.js
Expand Up @@ -40,20 +40,21 @@ function createActions(store) {
if (isUrlInArray(state.currentUrl, OPEN_PAGES)) {
return null;
}
await state.session.init();
if (!state.session.isConnected()) {
route('/login');
}
try {
await state.session.init();
if (!state.session.isConnected()) {
route('/login');
}
const tasks = [state.httpClient.get('/api/v1/me'), actionsProfilePicture.loadProfilePicture(state)];
const results = await Promise.all(tasks);
const [user] = await Promise.all(tasks);
store.setState({
user: results[0]
user
});
} catch (e) {
const status = get(e, 'response.status');
const error = get(e, 'response.error');
if (status === 401) {
state.session.reset();
route('/login');
} else if (error === 'GATEWAY_USER_NOT_LINKED') {
route('/link-gateway-user');
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 18 additions & 29 deletions front/src/components/boxs/device-in-room/EditDeviceInRoom.jsx
@@ -1,38 +1,27 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';
import actions from '../../../actions/dashboard/edit-boxes/editDevicesInRoom';
import BaseEditBox from '../baseEditBox';

const updateBoxRoom = (updateBoxRoomFunc, x, y) => e => {
updateBoxRoomFunc(x, y, e.target.value);
};
import BaseEditBox from '../baseEditBox';
import RoomSelector from '../../house/RoomSelector';

const EditDevicesInRoom = ({ children, ...props }) => (
<BaseEditBox {...props} titleKey="dashboard.boxTitle.devices-in-room">
<div class="form-group">
<label>Select the room you want to display here:</label>
<select onChange={updateBoxRoom(props.updateBoxRoom, props.x, props.y)} class="form-control">
<option value="">-------</option>
{props.rooms &&
props.rooms.map(room => (
<option selected={room.selector === props.box.room} value={room.selector}>
{room.name}
</option>
))}
</select>
</div>
</BaseEditBox>
);
import actions from '../../../actions/dashboard/edit-boxes/editDevicesInRoom';

@connect('rooms', actions)
class EditDeviceInRoomComponent extends Component {
componentDidMount() {
this.props.getRooms();
}
@connect('', actions)
class EditDeviceInRoom extends Component {
updateBoxRoom = room => {
this.props.updateBoxRoom(this.props.x, this.props.y, room.selector);
};

render(props, {}) {
return <EditDevicesInRoom {...props} />;
render(props) {
return (
<BaseEditBox {...props} titleKey="dashboard.boxTitle.devices-in-room">
<div class="form-group">
<label>Select the room you want to display here:</label>
<RoomSelector selectedRoom={props.box.room} updateRoomSelection={this.updateBoxRoom} />
</div>
</BaseEditBox>
);
}
}

export default EditDeviceInRoomComponent;
export default EditDeviceInRoom;
Expand Up @@ -50,9 +50,11 @@ const SensorDeviceType = ({ children, ...props }) => (
)}
{props.deviceFeature.category === DEVICE_FEATURE_CATEGORIES.MOTION_SENSOR && (
<td class="text-right">
{dayjs(props.deviceFeature.last_value_changed)
.locale(props.user.language)
.fromNow()}
{!props.deviceFeature.last_value_changed && <Text id="dashboard.boxes.devicesInRoom.noValue" />}
{props.deviceFeature.last_value_changed &&
dayjs(props.deviceFeature.last_value_changed)
.locale(props.user.language)
.fromNow()}
</td>
)}
</tr>
Expand Down
Expand Up @@ -4,8 +4,10 @@ import { Text } from 'preact-i18n';
import actions from '../../../actions/dashboard/edit-boxes/editTemperatureInRoom';
import BaseEditBox from '../baseEditBox';

const updateBoxRoom = (updateBoxRoomFunc, x, y) => e => {
updateBoxRoomFunc(x, y, e.target.value);
import RoomSelector from '../../house/RoomSelector';

const updateBoxRoom = (updateBoxRoomFunc, x, y) => room => {
updateBoxRoomFunc(x, y, room.selector);
};

const EditRoomTemperatureBox = ({ children, ...props }) => (
Expand All @@ -14,25 +16,16 @@ const EditRoomTemperatureBox = ({ children, ...props }) => (
<label>
<Text id="dashboard.boxes.temperatureInRoom.editRoomLabel" />
</label>
<select onChange={updateBoxRoom(props.updateBoxRoom, props.x, props.y)} class="form-control">
<option value="">-------</option>
{props.rooms &&
props.rooms.map(room => (
<option selected={room.selector === props.box.room} value={room.selector}>
{room.name}
</option>
))}
</select>
<RoomSelector
selectedRoom={props.box.room}
updateRoomSelection={updateBoxRoom(props.updateBoxRoom, props.x, props.y)}
/>
</div>
</BaseEditBox>
);

@connect('rooms', actions)
@connect('', actions)
class EditRoomTemperatureBoxComponent extends Component {
componentDidMount() {
this.props.getRooms();
}

render(props, {}) {
return <EditRoomTemperatureBox {...props} />;
}
Expand Down
@@ -1,11 +1,11 @@
import { Text } from 'preact-i18n';
import cx from 'classnames';

const documentationURL = 'https://documentation.gladysassistant.com';

const DeviceConfigurationLink = ({ children, documentKey, user, linkClass }) => (
<a
target="_blank"
rel="noopener noreferrer"
href={`${documentationURL}/${user.language}/configuration#${documentKey}`}
class={cx({
[linkClass]: linkClass
Expand Down

0 comments on commit e5fd100

Please sign in to comment.