Last improvements
This commit is contained in:
parent
d13bc2d312
commit
6e576faefd
@ -10,11 +10,10 @@ const DVB = ({ stopId }: { stopId: number }) => {
|
|||||||
const [departuresTable, setDeparturesTable] = React.useState([])
|
const [departuresTable, setDeparturesTable] = React.useState([])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
//pullDepartures();
|
pullDepartures();
|
||||||
// TODO
|
const dvbInterval = setInterval(pullDepartures, DVB_REFRESH_INTERVAL);
|
||||||
//const dvbInterval = setInterval(pullDepartures, DVB_REFRESH_INTERVAL);
|
|
||||||
|
|
||||||
//return () => clearInterval(dvbInterval);
|
return () => clearInterval(dvbInterval);
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const processDepatures = (departures: Departure[]) => {
|
const processDepatures = (departures: Departure[]) => {
|
||||||
|
@ -22,7 +22,6 @@ const PlantState = ({ hassUrl, token, plants }: { hassUrl: string, token: string
|
|||||||
plantStates[plant] = data.attributes
|
plantStates[plant] = data.attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(plantStates);
|
|
||||||
setPlantStates(plantStates);
|
setPlantStates(plantStates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
//import useWebSocket from "react-use-websocket";
|
//import useWebSocket from "react-use-websocket";
|
||||||
import {connect} from "mqtt"
|
import {connect} from "mqtt"
|
||||||
import type { SecretsMQTT } from "../lib/interfaces"
|
import type { SecretsMQTT, SongInfo } from "../lib/interfaces"
|
||||||
import * as styles from "../styles/containers/Spotify.module.css"
|
import * as styles from "../styles/containers/Spotify.module.css"
|
||||||
|
|
||||||
const Spotify = ({ mqtt, Alternative }: { mqtt: SecretsMQTT, Alternative: any }) => {
|
const Spotify = ({ mqtt, Alternative }: { mqtt: SecretsMQTT, Alternative: any }) => {
|
||||||
const [lastSongInfo, setLastSongInfo] = React.useState<string>("")
|
const [lastSongInfo, setLastSongInfo] = React.useState<SongInfo|undefined>(undefined)
|
||||||
|
|
||||||
const handleMessage = (_topic: string, message: string) => {
|
const handleMessage = (_topic: string, message: string) => {
|
||||||
setLastSongInfo(message.toString())
|
try {
|
||||||
|
const songInfo: SongInfo = JSON.parse(message.toString());
|
||||||
|
setLastSongInfo(songInfo);
|
||||||
|
} catch {
|
||||||
|
console.warn(`Can't parse song info: ${message.toString()}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@ -18,10 +23,10 @@ const Spotify = ({ mqtt, Alternative }: { mqtt: SecretsMQTT, Alternative: any })
|
|||||||
protocol: "mqtt"
|
protocol: "mqtt"
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("message", handleMessage)
|
client.on("message", handleMessage);
|
||||||
|
|
||||||
client.on("connect", () => {
|
client.on("connect", () => {
|
||||||
console.log("CONNECTED")
|
//console.log("CONNECTED")
|
||||||
client.publish("infoscreen/hello", "hello");
|
client.publish("infoscreen/hello", "hello");
|
||||||
client.subscribe("infoscreen/spotify")
|
client.subscribe("infoscreen/spotify")
|
||||||
})
|
})
|
||||||
@ -29,7 +34,7 @@ const Spotify = ({ mqtt, Alternative }: { mqtt: SecretsMQTT, Alternative: any })
|
|||||||
return () => {client.end()}
|
return () => {client.end()}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (true /*!lastJsonMessage || lastJsonMessage.playbackState !== "Play"*/) {
|
if (true || !lastSongInfo || lastSongInfo.playbackState !== "PLAYING") {
|
||||||
return Alternative;
|
return Alternative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import * as styles from "../styles/containers/WeatherAndTime.module.css";
|
|||||||
const WEATHER_REFRESH_INTERVAL = 15 * 60 * 1000;
|
const WEATHER_REFRESH_INTERVAL = 15 * 60 * 1000;
|
||||||
|
|
||||||
function getWeatherIcon(icon: string) {
|
function getWeatherIcon(icon: string) {
|
||||||
//const isNight = document.querySelector(':root[data-theme="night"]') !== null
|
|
||||||
let weatherIcon: string;
|
let weatherIcon: string;
|
||||||
switch (icon) {
|
switch (icon) {
|
||||||
case "clear-day":
|
case "clear-day":
|
||||||
@ -26,8 +25,13 @@ function getWeatherIcon(icon: string) {
|
|||||||
break;
|
break;
|
||||||
default: weatherIcon = icon
|
default: weatherIcon = icon
|
||||||
}
|
}
|
||||||
const ImportedIcon = require(`../images/weather-icons/svg/wi-${weatherIcon}.svg`);
|
try {
|
||||||
return <ImportedIcon />
|
const ImportedIcon = require(`../images/weather-icons/svg/wi-${weatherIcon}.svg`);
|
||||||
|
return <ImportedIcon />
|
||||||
|
} catch {
|
||||||
|
const ImportedIcon = require("../images/weather-icons/svg/wi-alien.svg");
|
||||||
|
return <ImportedIcon />
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const WeatherAndTime = ({ secrets }: { secrets: SecretsWeather }) => {
|
const WeatherAndTime = ({ secrets }: { secrets: SecretsWeather }) => {
|
||||||
@ -57,12 +61,11 @@ const WeatherAndTime = ({ secrets }: { secrets: SecretsWeather }) => {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
pullWeather()
|
pullWeather()
|
||||||
//TODO
|
const weatherInterval = setInterval(pullWeather, WEATHER_REFRESH_INTERVAL);
|
||||||
//const weatherInterval = setInterval(pullWeather, WEATHER_REFRESH_INTERVAL);
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(dateInterval);
|
clearInterval(dateInterval);
|
||||||
//clearInterval(weatherInterval);
|
clearInterval(weatherInterval);
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
@ -70,4 +70,11 @@ export interface PlantState {
|
|||||||
moisture: string;
|
moisture: string;
|
||||||
temperature: string;
|
temperature: string;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SongInfo {
|
||||||
|
playbackState: "PLAYING" | "PAUSE" | "STOPPED";
|
||||||
|
title: string;
|
||||||
|
artists: string[];
|
||||||
|
album: string;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user