Added custom service jellystat (#770)

Added custom service jellystat
This commit is contained in:
TheWhale01 2024-06-01 16:10:35 +02:00 committed by GitHub
parent e6adfd7bb7
commit 95fde896e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 116 additions and 1 deletions

View File

@ -36,6 +36,7 @@ within Homer:
- [PiAlert](#pialert) - [PiAlert](#pialert)
- [Immich](#immich) - [Immich](#immich)
- [OpenHAB](#openhab) - [OpenHAB](#openhab)
- [Jellystat](#jellystat)
- [Home Assistant](#home-assistant) - [Home Assistant](#home-assistant)
If you experiencing any issue, please have a look to the [troubleshooting](troubleshooting.md) page. If you experiencing any issue, please have a look to the [troubleshooting](troubleshooting.md) page.
@ -465,6 +466,22 @@ You need to set the type to OpenHAB, provide an api key and enable cors on OpenH
To create an API token on OpenHAB, follow the [official documentation here](https://www.openhab.org/docs/configuration/apitokens.html). To create an API token on OpenHAB, follow the [official documentation here](https://www.openhab.org/docs/configuration/apitokens.html).
To enable cors on OpenHAB, edit your services/runtime.cfg and uncomment or add this line: `org.openhab.cors:enable=true` To enable cors on OpenHAB, edit your services/runtime.cfg and uncomment or add this line: `org.openhab.cors:enable=true`
## Jellystat
The Jellystat serice display the number of concurrent streams on your jellyfin server.
The Jellystat server must be running behind a reverse proxy to add some cors headers:
- Access-Control-Allow-Origin: ${your_domain}
- Access-Control-Allow-Headers: Authorization
```yaml
- name: "Jellystat"
logo: "assets/tools/jellystat.png"
url: "http://192.168.1.154:3000"
type: "Jellystat"
apikey: "<---insert-api-key-here--->"
```
You can create an API key in the dashboard of you jellystat server: settings/API Keys -> Add Key
## Home Assistant ## Home Assistant
You need to set the type to HomeAssistant, provide an api key and enable cors on Home Assistant. You need to set the type to HomeAssistant, provide an api key and enable cors on Home Assistant.
@ -479,4 +496,4 @@ You need to set the type to HomeAssistant, provide an api key and enable cors on
separator: " " # optional, how to separate items separator: " " # optional, how to separate items
``` ```
To create an API token on HomeAssistant, follow the [official documentation here](https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token). To create an API token on HomeAssistant, follow the [official documentation here](https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token).
To enable cors on HomeAssistant, edit your `configuration.yml` and add the IP of Homer to `https: cors_allowed_origins` To enable cors on HomeAssistant, edit your `configuration.yml` and add the IP of Homer to `https: cors_allowed_origins`

View File

@ -0,0 +1,98 @@
<template>
<Generic :item="item">
<template #indicator>
<div class="notifs">
<strong
v-if="streams > 0"
class="notif playing"
:title="`${streams} active stream${streams > 1 ? 's' : ''}`"
>
{{ streams }}
</strong>
<i
v-if="error"
class="notif error fa-solid fa-triangle-exclamation"
title="Unable to fetch current status"
></i>
</div>
</template>
</Generic>
</template>
<script>
import service from "@/mixins/service.js";
import Generic from "./Generic.vue";
export default {
name: "Jellyfin",
mixins: [service],
props: {
item: Object,
},
components: {
Generic,
},
data: () => ({
stats: null,
error: false,
}),
computed: {
streams: function () {
if (!this.stats) {
return "";
}
let nb_streams = 0;
for (let stream of this.stats) {
if ("NowPlayingItem" in stream) nb_streams++;
}
return nb_streams;
},
},
created() {
this.fetchStatus();
},
methods: {
fetchStatus: async function () {
const headers = {
Authorization: `bearer ${this.item.apikey}`,
};
try {
const response = await this.fetch("/proxy/getSessions", { headers });
this.error = false;
this.stats = response;
} catch (e) {
this.error = true;
console.error(e);
}
},
},
};
</script>
<style scoped lang="scss">
.notifs {
position: absolute;
color: white;
font-family: sans-serif;
top: 0.3em;
right: 0.5em;
.notif {
display: inline-block;
padding: 0.2em 0.35em;
border-radius: 0.25em;
position: relative;
margin-left: 0.3em;
font-size: 0.8em;
&.playing {
background-color: #28a9a3;
}
&.error {
border-radius: 50%;
aspect-ratio: 1;
background-color: #e51111;
}
}
}
</style>