Giter Club home page Giter Club logo

airpods-to's Introduction

AirPods Battery Manager

This project is a comprehensive solution for managing and displaying the battery status of AirPods across different platforms. It is implemented using Python and leverages several design patterns to ensure a clean, maintainable, and scalable codebase.

Technology

The project is built with Python, a powerful and flexible programming language that allows for cross-platform compatibility. It uses the Tkinter library for creating graphical user interfaces, and the PyBluez library for Bluetooth communication.

Design Patterns

The project uses the following design patterns:

Observer Pattern

The Observer pattern is used to implement a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing. In this project, the EventManager class acts as the subject, while the GuiListener, NotificationListener, and TerminalListener classes act as observers. Whenever the state of the AirPods changes, all registered listeners are notified.

Factory Pattern

The Factory pattern is used to create objects without specifying the exact class of object that will be created. In this project, the WindowComponentFactory class is used to create different types of window components (IconComponent and LabelComponent) without specifying the exact class of the component that will be created.

State Pattern

The State pattern is used to alter an object's behavior when its state changes. In this project, the HeadphonesBatteryState class and its subclasses (LowBatteryState, MediumBatteryState, HighBatteryState) are used to handle different battery states. The behavior of the GuiListener and NotificationListener classes changes depending on the current battery state.

Abstract Factory Pattern

The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. This pattern is particularly useful when the system needs to be independent from the way its objects are created, composed, and represented.

In this project, the Abstract Factory pattern is used to create platform-dependent BluetoothDataReceiver objects. The abstract factory, represented by an interface or an abstract class, declares a set of methods that return different abstract products. These products are then implemented in separate concrete factories.

Here's how it's used in the context of this project:

  • An abstract factory BluetoothDataReceiverFactory is defined. This factory has a method createBluetoothDataReceiver(), which returns an object of type BluetoothDataReceiver.

  • Concrete factories like WindowsBluetoothDataReceiverFactory, MacBluetoothDataReceiverFactory, and LinuxBluetoothDataReceiverFactory are implemented. Each of these factories override the createBluetoothDataReceiver() method to return a BluetoothDataReceiver that is specific to a particular platform.

  • The BluetoothDataReceiver is an abstract product with a method get_airpods_data(). This method is implemented differently in each platform-specific subclass (WindowsBluetoothDataReceiver, MacBluetoothDataReceiver, LinuxBluetoothDataReceiver) to handle the platform-specific details of receiving data from the AirPods via Bluetooth.

This way, the AirPodsManager class can remain platform-independent. It simply asks the factory for a BluetoothDataReceiver, and uses it to get the AirPods data, without needing to know any of the platform-specific details. The correct factory can be chosen at runtime based on the platform the software is running on.

UML Diagram

A UML diagram representing the structure of the project

UML Diagram

Installation

Use python 3.12 to run without any issues.

pip install -r requirements.txt

Usage

python main.py time_in_seconds gui_policy notification_policy

Example:

python main.py 15 low medium

airpods-to's People

Contributors

bartoszpiechnik25 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.