Skip to content

Commit

Permalink
Merge branch 'master' into new-integration-freemobile
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Nov 22, 2024
2 parents 6a71f7f + 8fff0ca commit 8c489f0
Show file tree
Hide file tree
Showing 33 changed files with 4,547 additions and 2 deletions.
Binary file added front/src/assets/integrations/cover/airplay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions front/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ import SonosDiscoveryPage from '../routes/integration/all/sonos/discover-page';
import GoogleCastDevicePage from '../routes/integration/all/google-cast/device-page';
import GoogleCastDiscoveryPage from '../routes/integration/all/google-cast/discover-page';

// Airplay integration
import AirplayDevicePage from '../routes/integration/all/airplay/device-page';
import AirplayDiscoveryPage from '../routes/integration/all/airplay/discover-page';

// ZWaveJS-UI integration
import ZwaveJSUIDevicePage from '../routes/integration/all/zwavejs-ui/device-page';
import ZwaveJSUIDiscoveryPage from '../routes/integration/all/zwavejs-ui/discover-page';
Expand Down Expand Up @@ -308,6 +312,9 @@ const AppRouter = connect(
<GoogleCastDevicePage path="/dashboard/integration/device/google-cast" />
<GoogleCastDiscoveryPage path="/dashboard/integration/device/google-cast/discover" />

<AirplayDevicePage path="/dashboard/integration/device/airplay" />
<AirplayDiscoveryPage path="/dashboard/integration/device/airplay/discover" />

<ZwaveJSUIDevicePage path="/dashboard/integration/device/zwavejs-ui" />
<ZwaveJSUIDiscoveryPage path="/dashboard/integration/device/zwavejs-ui/discover" />
<ZwaveJSUISetupPage path="/dashboard/integration/device/zwavejs-ui/setup" />
Expand Down
35 changes: 35 additions & 0 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,41 @@
"conflictError": "Das aktuelle Gerät ist bereits in Gladys vorhanden."
}
},
"airplay": {
"title": "Airplay",
"description": "Steuern Sie Airplay-Geräte in Ihrem lokalen Netzwerk",
"deviceTab": "Geräte",
"discoverTab": "Airplay Entdeckung",
"setupTab": "Einrichtung",
"documentation": "Airplay Dokumentation",
"discoverDeviceDescr": "Airplay-Geräte automatisch scannen",
"nameLabel": "Gerätename",
"namePlaceholder": "Geben Sie den Namen Ihres Geräts ein",
"hostLabel": "IP-Adresse",
"roomLabel": "Zimmer",
"saveButton": "Speichern",
"alreadyCreatedButton": "Bereits erstellt",
"deleteButton": "Löschen",
"device": {
"title": "Airplay-Geräte in Gladys",
"editButton": "Bearbeiten",
"noDeviceFound": "Kein Airplay-Gerät gefunden.",
"featuresLabel": "Funktionen"
},
"discover": {
"title": "Geräte in Ihrem lokalen Netzwerk erkannt",
"description": "Airplay-Geräte werden automatisch erkannt.",
"error": "Fehler beim Entdecken der Airplay-Geräte. Ist Ihr Airplay-Lautsprecher eingeschaltet und im lokalen Netzwerk erreichbar?",
"noDeviceFound": "Keine Airplay-Geräte gefunden.",
"errorWhileScanning": "Beim Scannen ist ein Fehler aufgetreten.",
"scan": "Scannen"
},
"error": {
"defaultError": "Beim Speichern des Geräts ist ein Fehler aufgetreten.",
"defaultDeletionError": "Beim Löschen des Geräts ist ein Fehler aufgetreten.",
"conflictError": "Das aktuelle Gerät ist bereits in Gladys vorhanden."
}
},
"zwavejs-ui": {
"title": "ZWave JS UI",
"description": "Steuern Sie Ihre Geräte in Z-Wave JS UI",
Expand Down
35 changes: 35 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,41 @@
"conflictError": "The current device is already in Gladys."
}
},
"airplay": {
"title": "Airplay",
"description": "Contrôler les appareils Airplay sur votre réseau local",
"deviceTab": "Devices",
"discoverTab": "Airplay Discovery",
"setupTab": "Setup",
"documentation": "Airplay Documentation",
"discoverDeviceDescr": "Automatically scan for Airplay devices",
"nameLabel": "Device Name",
"namePlaceholder": "Enter your device name",
"hostLabel": "IP Address",
"roomLabel": "Room",
"saveButton": "Save",
"alreadyCreatedButton": "Already Created",
"deleteButton": "Delete",
"device": {
"title": "Airplay Devices in Gladys",
"editButton": "Edit",
"noDeviceFound": "No Airplay device found.",
"featuresLabel": "Features"
},
"discover": {
"title": "Devices detected on your local network",
"description": "Airplay devices are automatically discovered.",
"error": "Error discovering Airplay devices. Is your Airplay speaker powered on and accessible on the local network?",
"noDeviceFound": "No Airplay devices have been discovered.",
"errorWhileScanning": "An error occurred while scanning.",
"scan": "Scan"
},
"error": {
"defaultError": "An error occurred while saving the device.",
"defaultDeletionError": "An error occurred while deleting the device.",
"conflictError": "The current device is already in Gladys."
}
},
"zwavejs-ui": {
"title": "ZWave JS UI",
"description": "Control your devices in Z-Wave JS UI",
Expand Down
35 changes: 35 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,41 @@
"conflictError": "L'appareil actuel est déjà dans Gladys."
}
},
"airplay": {
"title": "Airplay",
"description": "Contrôler les appareils Airplay sur votre réseau local",
"deviceTab": "Appareils",
"discoverTab": "Découverte Airplay",
"setupTab": "Configuration",
"documentation": "Documentation Airplay",
"discoverDeviceDescr": "Scanner automatiquement les appareils Airplay",
"nameLabel": "Nom de l'appareil",
"namePlaceholder": "Entrez le nom de votre appareil",
"hostLabel": "Adresse IP",
"roomLabel": "Pièce",
"saveButton": "Sauvegarder",
"alreadyCreatedButton": "Déjà créé",
"deleteButton": "Supprimer",
"device": {
"title": "Appareils Airplay dans Gladys",
"editButton": "Éditer",
"noDeviceFound": "Aucun appareil Airplay trouvé.",
"featuresLabel": "Fonctionnalités"
},
"discover": {
"title": "Appareils détectés sur votre réseau local",
"description": "Les appareils Airplay sont automatiquement découverts.",
"error": "Erreur de découverte des appareils Airplay. Est-ce que votre enceinte Airplay est sous tension et accessible sur le réseau local ?",
"noDeviceFound": "Aucun appareil Airplay n'a été découvert.",
"errorWhileScanning": "Une erreur est survenue lors du scan.",
"scan": "Scanner"
},
"error": {
"defaultError": "Une erreur s'est produite lors de l'enregistrement de l'appareil.",
"defaultDeletionError": "Une erreur s'est produite lors de la suppression de l'appareil.",
"conflictError": "L'appareil actuel est déjà dans Gladys."
}
},
"zwavejs-ui": {
"title": "ZWave JS UI",
"description": "Contrôler vos appareils dans Z-Wave JS UI",
Expand Down
5 changes: 5 additions & 0 deletions front/src/config/integrations/devices.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
"link": "google-cast",
"img": "/assets/integrations/cover/google-cast.jpg"
},
{
"key": "airplay",
"link": "airplay",
"img": "/assets/integrations/cover/airplay.jpg"
},
{
"key": "free-mobile",
"link": "free-mobile",
Expand Down
197 changes: 197 additions & 0 deletions front/src/routes/integration/all/airplay/AirplayDeviceBox.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { Component } from 'preact';
import { Text, Localizer, MarkupText } from 'preact-i18n';
import cx from 'classnames';
import get from 'get-value';

import { connect } from 'unistore/preact';

class AirplayDeviceBox extends Component {
componentWillMount() {
this.setState({
device: this.props.device
});
}

componentWillReceiveProps(nextProps) {
this.setState({
device: nextProps.device
});
}

updateName = e => {
this.setState({
device: {
...this.state.device,
name: e.target.value
}
});
};

updateRoom = e => {
this.setState({
device: {
...this.state.device,
room_id: e.target.value
}
});
};

saveDevice = async () => {
this.setState({
loading: true,
errorMessage: null
});
try {
let deviceDidNotExist = this.state.device.id === undefined;
const savedDevice = await this.props.httpClient.post(`/api/v1/device`, this.state.device);
if (deviceDidNotExist) {
savedDevice.alreadyExist = true;
}
this.setState({
device: savedDevice
});
} catch (e) {
let errorMessage = 'integration.airplay.error.defaultError';
if (e.response.status === 409) {
errorMessage = 'integration.airplay.error.conflictError';
}
this.setState({
errorMessage
});
}
this.setState({
loading: false
});
};

deleteDevice = async () => {
this.setState({
loading: true,
errorMessage: null,
tooMuchStatesError: false,
statesNumber: undefined
});
try {
if (this.state.device.created_at) {
await this.props.httpClient.delete(`/api/v1/device/${this.state.device.selector}`);
}
this.props.getAirplayDevices();
} catch (e) {
const status = get(e, 'response.status');
const dataMessage = get(e, 'response.data.message');
if (status === 400 && dataMessage && dataMessage.includes('Too much states')) {
const statesNumber = new Intl.NumberFormat().format(dataMessage.split(' ')[0]);
this.setState({ tooMuchStatesError: true, statesNumber });
} else {
this.setState({
errorMessage: 'integration.airplay.error.defaultDeletionError'
});
}
}
this.setState({
loading: false
});
};

render(
{ deviceIndex, editable, deleteButton, housesWithRooms },
{ device, loading, errorMessage, tooMuchStatesError, statesNumber }
) {
const validModel = device.features && device.features.length > 0;

return (
<div class="col-md-6">
<div class="card">
<div class="card-header">{device.name}</div>
<div
class={cx('dimmer', {
active: loading
})}
>
<div class="loader" />
<div class="dimmer-content">
<div class="card-body">
{errorMessage && (
<div class="alert alert-danger">
<Text id={errorMessage} />
</div>
)}
{tooMuchStatesError && (
<div class="alert alert-warning">
<MarkupText id="device.tooMuchStatesToDelete" fields={{ count: statesNumber }} />
</div>
)}
<div class="form-group">
<label class="form-label" for={`name_${deviceIndex}`}>
<Text id="integration.airplay.nameLabel" />
</label>
<Localizer>
<input
id={`name_${deviceIndex}`}
type="text"
value={device.name}
onInput={this.updateName}
class="form-control"
placeholder={<Text id="integration.airplay.namePlaceholder" />}
disabled={!editable || !validModel}
/>
</Localizer>
</div>

{housesWithRooms && (
<div class="form-group">
<label class="form-label" for={`room_${deviceIndex}`}>
<Text id="integration.airplay.roomLabel" />
</label>
<select
id={`room_${deviceIndex}`}
onChange={this.updateRoom}
class="form-control"
disabled={!editable || !validModel}
>
<option value="">
<Text id="global.emptySelectOption" />
</option>
{housesWithRooms &&
housesWithRooms.map(house => (
<optgroup label={house.name}>
{house.rooms.map(room => (
<option selected={room.id === device.room_id} value={room.id}>
{room.name}
</option>
))}
</optgroup>
))}
</select>
</div>
)}

<div class="form-group">
{device.alreadyExist && (
<button class="btn btn-primary mr-2" disabled="true">
<Text id="integration.airplay.alreadyCreatedButton" />
</button>
)}

{!device.alreadyExist && (
<button onClick={this.saveDevice} class="btn btn-success mr-2">
<Text id="integration.airplay.saveButton" />
</button>
)}

{deleteButton && (
<button onClick={this.deleteDevice} class="btn btn-danger">
<Text id="integration.airplay.deleteButton" />
</button>
)}
</div>
</div>
</div>
</div>
</div>
</div>
);
}
}

export default connect('httpClient', {})(AirplayDeviceBox);
Loading

0 comments on commit 8c489f0

Please sign in to comment.