From 0f79afc6884fd2da94d486114b8ea5ea07194630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 10 Apr 2021 16:09:33 +0200 Subject: [PATCH] Show integration usage (#17383) --- .gitignore | 1 + Rakefile | 19 ++++++++ sass/custom/_paulus.scss | 3 +- .../asides/component_navigation.html | 43 ++++++------------- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 6384f76a26c..4510dbe63d9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .gist-cache .pygments-cache public +source/_data/analytics_data.json source/_stash source/stylesheets/screen.css source/.jekyll-cache/ diff --git a/Rakefile b/Rakefile index 8df92944c02..dc17981edbf 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,9 @@ require "rubygems" require "bundler/setup" require "stringex" +require 'net/http' +require 'json' + ## -- Misc Configs -- ## public_dir = "public/" # compiled site directory @@ -28,6 +31,8 @@ task :generate do puts "## Generating Site with Jekyll" success = system "compass compile --css-dir #{source_dir}/stylesheets" abort("Generating CSS failed") unless success + success = system "rake analytics_data" + abort("Generating analytics data failed") unless success success = system "jekyll build" abort("Generating site failed") unless success if ENV["CONTEXT"] != 'production' @@ -63,6 +68,7 @@ task :preview, :listen do |t, args| puts "Starting to watch source with Jekyll and Compass." puts "Now listening on http://localhost:#{server_port}" system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css") + success = system "rake analytics_data" jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build -t --watch --incremental") compassPid = Process.spawn("compass watch") rackupPid = Process.spawn("rackup --port #{server_port} --host #{listen_addr}") @@ -168,6 +174,19 @@ task :clean do rm_rf [Dir.glob(".pygments-cache/**"), Dir.glob(".gist-cache/**"), Dir.glob(".sass-cache/**"), "source/stylesheets/screen.css"] end +desc "Download data from analytics.home-assistant.io" +task :analytics_data do + uri = URI('https://analytics.home-assistant.io/data.json') + + remote_data = JSON.parse(Net::HTTP.get(uri)) + last_entry=remote_data.keys().sort().reverse()[0] + + File.open("#{source_dir}/_data/analytics_data.json", "w") do |file| + file.write(JSON.generate(remote_data[last_entry])) + end + +end + def get_stdin(message) print message STDIN.gets.chomp diff --git a/sass/custom/_paulus.scss b/sass/custom/_paulus.scss index 2dba14063b2..4ad20e27657 100644 --- a/sass/custom/_paulus.scss +++ b/sass/custom/_paulus.scss @@ -455,8 +455,9 @@ div.note { } } } - } + } + .brand-logo-container { text-align: center; margin-top: 50px; diff --git a/source/_includes/asides/component_navigation.html b/source/_includes/asides/component_navigation.html index 75a809b5399..ff81043a5ae 100644 --- a/source/_includes/asides/component_navigation.html +++ b/source/_includes/asides/component_navigation.html @@ -18,39 +18,20 @@ {%- endif -%} - {%- if page.ha_iot_class -%} -
- IoT class: {{ page.ha_iot_class }} -
- {%- endif -%} +
+ The {{ page.name | default: page.title }} integration was introduced in Home Assistant {{ page.ha_release | default: "unknown" }}, + and it's used by + {{ 100 | times: site.data.analytics_data.integrations[page.ha_domain] | divided_by: site.data.analytics_data.reports_integrations | ceil }}% of the active installations. + Its IoT class is {{ page.ha_iot_class | default: "unknown" }} - {%- if page.ha_quality_scale -%} - - {%- endif -%} + {%- if page.ha_quality_scale %} + and scores {{page.ha_quality_scale}} on our quality scale + {%- endif -%}. - {%- if page.ha_release -%} -
- Introduced in release: {{ page.ha_release }} -
- {%- endif -%} - - {%- if page.ha_domain -%} -
- Source: View on GitHub -
- {%- endif -%} + {% if page.ha_domain %} + You can find the source for this integration on GitHub. + {%- endif -%} +
{%- if page.ha_category.first -%}