Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyeao committed Jun 4, 2024
2 parents 0105746 + 4ee9ae3 commit 1c52183
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 42 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ name: Mark stale issues and pull requests

on:
schedule:
- cron: '40 13 * * *'
- cron: "00 16 * * *"

jobs:
stale:

close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/stale@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'
- uses: actions/stale@v5
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
35 changes: 20 additions & 15 deletions AboutWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
Title="About" Height="486" Width="400"
Title="About" Height="531" Width="400"
WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"

TextElement.Foreground="{DynamicResource MaterialDesign.Brush.Foreground}"
Background="{DynamicResource MaterialDesign.Brush.Background}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextElement.FontSize="12"
FontFamily="{materialDesign:MaterialDesignFont}"

TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}">
TextOptions.TextRenderingMode="Auto">

<Window.Resources>
<ResourceDictionary>
<!--<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<materialDesign:BundledTheme BaseTheme="Light" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.DataGrid.xaml" />
</ResourceDictionary.MergedDictionaries>


</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>-->
<!--</ResourceDictionary>-->
</Window.Resources>
<Grid Margin="0,0,0,2">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Height="434">
<Grid Margin="0,0,0,1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="77*"/>
</Grid.ColumnDefinitions>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Left" Height="494" Grid.Column="1" Margin="10,0,0,0">
<TextBlock Text="TEAMS2HA" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center"/>
<TextBlock x:Name="VersionTextBlock" FontSize="16" HorizontalAlignment="Center"/>
<TextBlock Text="Developed by Jimmy White" FontSize="16" HorizontalAlignment="Center"/>
Expand All @@ -38,7 +43,7 @@
<Run Text="TEAMS2HA"/>
</Hyperlink>
</TextBlock>
<ListBox x:Name="EntitiesListBox" Width="350" Height="275" MouseDoubleClick="EntitiesListBox_MouseDoubleClick" >
<ListBox x:Name="EntitiesListBox" Width="350" Height="331" MouseDoubleClick="EntitiesListBox_MouseDoubleClick" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Tag="{Binding}">
Expand All @@ -53,7 +58,7 @@
</ListBox.ItemTemplate>

</ListBox>
<Button Content="Close" HorizontalAlignment="Center" Margin="10" Width="100" Click="CloseButton_Click" Style="{DynamicResource MaterialDesignRaisedButton}"/>
<Button Content="Close" Width="100" materialDesign:ButtonAssist.CornerRadius="25" Click="CloseButton_Click" Style="{DynamicResource MaterialDesignRaisedButton}"/>
</StackPanel>

</Grid>
Expand Down
Binary file added Assets/appbg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 26 additions & 8 deletions CryptoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,38 @@ namespace TEAMS2HA
{
public static class CryptoHelper
{
public static string EncryptString(string plainText)
{
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
byte[] encryptedBytes = ProtectedData.Protect(plainTextBytes, null, DataProtectionScope.CurrentUser);

return Convert.ToBase64String(encryptedBytes);
}
#region Public Methods

public static string DecryptString(string encryptedText)
{
// Check if the input string is null or empty
if (string.IsNullOrEmpty(encryptedText))
{
// Return null or throw an exception as per your application's error handling policy
return null; // Or throw new ArgumentNullException(nameof(encryptedText));
}

byte[] encryptedBytes = Convert.FromBase64String(encryptedText);
byte[] decryptedBytes = ProtectedData.Unprotect(encryptedBytes, null, DataProtectionScope.CurrentUser);

return Encoding.UTF8.GetString(decryptedBytes);
}

public static string EncryptString(string plainText)
{
// Check if the input string is null or empty
if (string.IsNullOrEmpty(plainText))
{
// Return null or throw an exception as per your application's error handling policy
return null; // Or throw new ArgumentNullException(nameof(plainText));
}

byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
byte[] encryptedBytes = ProtectedData.Protect(plainTextBytes, null, DataProtectionScope.CurrentUser);

return Convert.ToBase64String(encryptedBytes);
}

#endregion Public Methods
}
}
}
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
[![CodeQL](https://github.com/jimmyeao/TEAMS2HA/actions/workflows/codeql.yml/badge.svg)](https://github.com/jimmyeao/TEAMS2HA/actions/workflows/codeql.yml)[![GitHub tag](https://img.shields.io/github/tag/jimmyeao/TEAMS2HA?include_prereleases=&sort=semver&color=blue)](https://github.com/jimmyeao/TEAMS2HA/releases/)
[![License](https://img.shields.io/badge/License-MIT-blue)](#license)
[![issues - HA-Game-SPy](https://img.shields.io/github/issues/jimmyeao/TEAMS2HA)](https://github.com/jimmyeao/TEAMS2HA/issues)
[![issues - Teams2HA](https://img.shields.io/github/issues/jimmyeao/TEAMS2HA)](https://github.com/jimmyeao/TEAMS2HA/issues)

<H1>Teams2HA</H1>

<h3>IMPORTANT!!</h3>

Please review Breaking changes ahead of the next version (723) which will be released this weekend (28th Mar 2024) https://github.com/jimmyeao/TEAMS2HA/blob/master/breaking.md
<br>



This is an agent that runs on windows and uses the Local teams API (https://support.microsoft.com/en-gb/office/connect-to-third-party-devices-in-microsoft-teams-aabca9f2-47bb-407f-9f9b-81a104a883d6?wt.mc_id=SEC-MVP-5004985) to retrieve the status of the user (In a meeting, Video On, Mute, blur etc) and push these into homeassistant sensors using MQTT.

Download the latest version from https://github.com/jimmyeao/TEAMS2HA/releases (app will auto update once installed)

![image](https://github.com/jimmyeao/TEAMS2HA/assets/5197831/f8a90d5c-25be-4b00-98a8-9521827ca0b9)
![image](https://github.com/jimmyeao/TEAMS2HA/assets/5197831/c79d09a4-0770-470f-a941-d21f85e1cf37)


<h2>Pairing</h2>

to pair, have the app running, launch a teams meeting (using meetnow?) and click Pair wtih teams. This will initiate a pairing request in teams, accept this, and then the app will store the key, in an encrypted format.

The application will minimize to the system stray.
The application will minimize to the system tray.

<h2>MQTT</h2>

Provide your MQTT instance details (IP, username and password) The password is encrypted before being saved to the settings file and is not stored in clear text.
We support plain MQTT, MQTT over TLS, MQTT over Websockets and MQTT over Websockets with TLS and the ability to ignore certificate errors if you are using self-signed certs (I would strongly advise you to use Lets Encrypt as a minimum)

<h2>Entities</h2>
Click the Entities button to see a list of entities this program will create:

![image](https://github.com/jimmyeao/TEAMS2HA/assets/5197831/a39632e7-f61c-4c0c-a953-555da53b3e0d)
![image](https://github.com/jimmyeao/TEAMS2HA/assets/5197831/5c87da53-e66a-4bc8-af4b-34af0ddc6d47)


You can either right click and copy or double click to copy the entity name to the clipboard.

Expand All @@ -32,6 +42,9 @@ You can right click the system tray icon for a selection of functions:

![image](https://github.com/jimmyeao/TEAMS2HA/assets/5197831/a8878f2e-38f6-4fce-a823-32f2008a0763)

This is how it should look in MQTT in Homeassistant

![image](https://github.com/jimmyeao/TEAMS2HA/assets/5197831/ce524451-a96a-4eac-bb94-67e36f449527)



Expand Down
8 changes: 8 additions & 0 deletions TEAMS2HA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PropertyGroup>

<ItemGroup>
<None Remove="appbg.png" />
<None Remove="Square150x150Logo.scale-200.ico" />
</ItemGroup>

Expand All @@ -38,6 +39,10 @@
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<Resource Include="appbg.png" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
Expand All @@ -55,6 +60,9 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Update="todo and bugs.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions TEAMS2HA.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 17.7.34302.85
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMS2HA", "TEAMS2HA.csproj", "{38D15280-C54C-403A-9676-DA1FFB23BB70}"
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup Project", "..\Setup Project\Setup Project.vdproj", "{8E191643-154A-48CB-8D16-448699150869}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,8 +15,6 @@ Global
{38D15280-C54C-403A-9676-DA1FFB23BB70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38D15280-C54C-403A-9676-DA1FFB23BB70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38D15280-C54C-403A-9676-DA1FFB23BB70}.Release|Any CPU.Build.0 = Release|Any CPU
{8E191643-154A-48CB-8D16-448699150869}.Debug|Any CPU.ActiveCfg = Debug
{8E191643-154A-48CB-8D16-448699150869}.Release|Any CPU.ActiveCfg = Release
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file added appbg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1>BREAKING CHANGES IN NEXT VERSION</h1>
In the next version of Teams2HA, we will be moving to a model more aligned with Homeassistant, instead of individual sensors and switches, these will be moved under a Device:
Sensores will also now be BINARY sensors

![image](https://github.com/jimmyeao/TEAMS2HA/assets/5197831/b14a824e-b939-4ba5-9515-b06bf4150270)

The Device will appear in the MQTT integration as the Prefix name, in LOWER case - this aligns with MQTT best praactices.

As a result, the sensor names will change if your previous prefix was upper or mixed case - please check them and update your automations as required. This should be the last time we have to do this.

As the old sensor names may still exist, you may need to remove them from MQTT - I use https://mqtt-explorer.com/ MQTT Explorer

Simply expand the view to **Homeassistant - switch** and remove all entries that start with your prefix, e.g. myprefix_isinmeeting, myprefix_isrecording on etc and then repeat for the entries under **homeasistant - sensor**

In the below example for switches, the highlighed area shows the new format, notice that "Ryzen" is the prefix I am using - any of these sensors or switches that exist outside of a topic that starts with your prefix can be removed

![image](https://github.com/jimmyeao/TEAMS2HA/assets/5197831/c2cd4559-7a1c-4b11-8ce5-4cc315eb3f4d)


3 changes: 3 additions & 0 deletions todo and bugs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Teamsrunning is set to no on launch, need to fix this - fixed
Pairing - after pairing is successful, UI is not updated to show that pairing is successful - fixed
Meeting permissions are not being updated to mqtt - fixed

0 comments on commit 1c52183

Please sign in to comment.