Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom service jellystat #770

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion docs/customservices.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ within Homer:
- [PiAlert](#pialert)
- [Immich](#immich)
- [OpenHAB](#openhab)
- [Jellystat](#jellystat)
- [Home Assistant](#home-assistant)

If you experiencing any issue, please have a look to the [troubleshooting](troubleshooting.md) page.
Expand Down Expand Up @@ -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 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

You need to set the type to HomeAssistant, provide an api key and enable cors on Home Assistant.
Expand All @@ -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
```
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`
98 changes: 98 additions & 0 deletions src/components/services/Jellystat.vue
Original file line number Diff line number Diff line change
@@ -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>
Loading