Last improvements

This commit is contained in:
Daniel Kluge 2022-01-06 21:15:17 +01:00
parent d13bc2d312
commit 6e576faefd
5 changed files with 30 additions and 17 deletions

View File

@ -10,11 +10,10 @@ const DVB = ({ stopId }: { stopId: number }) => {
const [departuresTable, setDeparturesTable] = React.useState([])
React.useEffect(() => {
//pullDepartures();
// TODO
//const dvbInterval = setInterval(pullDepartures, DVB_REFRESH_INTERVAL);
pullDepartures();
const dvbInterval = setInterval(pullDepartures, DVB_REFRESH_INTERVAL);
//return () => clearInterval(dvbInterval);
return () => clearInterval(dvbInterval);
}, [])
const processDepatures = (departures: Departure[]) => {

View File

@ -22,7 +22,6 @@ const PlantState = ({ hassUrl, token, plants }: { hassUrl: string, token: string
plantStates[plant] = data.attributes
}
console.log(plantStates);
setPlantStates(plantStates);
}

View File

@ -1,14 +1,19 @@
import * as React from "react"
//import useWebSocket from "react-use-websocket";
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"
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) => {
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(() => {
@ -18,10 +23,10 @@ const Spotify = ({ mqtt, Alternative }: { mqtt: SecretsMQTT, Alternative: any })
protocol: "mqtt"
});
client.on("message", handleMessage)
client.on("message", handleMessage);
client.on("connect", () => {
console.log("CONNECTED")
//console.log("CONNECTED")
client.publish("infoscreen/hello", "hello");
client.subscribe("infoscreen/spotify")
})
@ -29,7 +34,7 @@ const Spotify = ({ mqtt, Alternative }: { mqtt: SecretsMQTT, Alternative: any })
return () => {client.end()}
}, [])
if (true /*!lastJsonMessage || lastJsonMessage.playbackState !== "Play"*/) {
if (true || !lastSongInfo || lastSongInfo.playbackState !== "PLAYING") {
return Alternative;
}

View File

@ -6,7 +6,6 @@ import * as styles from "../styles/containers/WeatherAndTime.module.css";
const WEATHER_REFRESH_INTERVAL = 15 * 60 * 1000;
function getWeatherIcon(icon: string) {
//const isNight = document.querySelector(':root[data-theme="night"]') !== null
let weatherIcon: string;
switch (icon) {
case "clear-day":
@ -26,8 +25,13 @@ function getWeatherIcon(icon: string) {
break;
default: weatherIcon = icon
}
try {
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 }) => {
@ -57,12 +61,11 @@ const WeatherAndTime = ({ secrets }: { secrets: SecretsWeather }) => {
}, 1000);
pullWeather()
//TODO
//const weatherInterval = setInterval(pullWeather, WEATHER_REFRESH_INTERVAL);
const weatherInterval = setInterval(pullWeather, WEATHER_REFRESH_INTERVAL);
return () => {
clearInterval(dateInterval);
//clearInterval(weatherInterval);
clearInterval(weatherInterval);
}
}, [])

View File

@ -71,3 +71,10 @@ export interface PlantState {
temperature: string;
}
}
export interface SongInfo {
playbackState: "PLAYING" | "PAUSE" | "STOPPED";
title: string;
artists: string[];
album: string;
}