simplefancontroller.sfc package

Submodules

simplefancontroller.sfc.controller module

class simplefancontroller.sfc.controller.SimpleFanController(settings: Optional[SFControllerSettings] = None)

Bases: object

Controller for 2-, and 4-pin fans using the GPIO pins on a Raspberry Pi. Fans can be added and removed to the included fan_storage

settings

settings of the controller

Type

SimpleFanControllerSettings

fans

specialized list that contains SFCFan objects

Type

SFCFanStorage

current_temperature

current CPU temperature

Type

float

db_client

database client for persisting fan intensities

Type

SFCDatabaseClient

thread_manager

manager of the fan control thread

Type

SFCThreadManager

data_manager

persists data

Type

SFCDataManager

attach_db_client(settings: SFCDBSettings)
current_temperature: Optional[float]
data_manager: SFCDataManager
db_clients: dict[str, simplefancontroller.sfc.database.SFCDatabaseClient]
export_data()

Exports the current settings to a local SQLite database.

fans: SFCFanStorage
get_db_client(name)
get_temperature()

Reads the current CPU temperature.

import_data()

Imports settings from the local SQLite database.

remove_db_client(name)
set_fan_intensities()

Updates fan intensities and publishes data to the attached SFCDatabaseClient.

Updates the intensities of all attached fans and writes the new intensities to the attached SFCDatabaseClient if activated.

property settings: SFControllerSettings
shutdown()

Shuts down the controller.

start()

Starts controlling the fans.

stop()

Stops controlling the fans.

thread_manager: SFCThreadManager
update_db_client(name: str, settings: SFCDBSettings)

simplefancontroller.sfc.data_manager module

class simplefancontroller.sfc.data_manager.SFCDataManager

Bases: object

delete_fan(fan_name: str)
delete_persistence(db_name: str)
delete_settings()
get_fan(fan_name: str) SFCFanSettings
get_fan_names() list[str]
get_fans() list[simplefancontroller.sfc.settings.SFCFanSettings]
get_persistence(db_name: str) SFCDBSettings
get_persistence_names() list[str]
get_settings() SFControllerSettings
save_fan(settings: SFCFanSettings)
save_persistence(settings: SFCDBSettings)
save_settings(settings: SFControllerSettings)
shutdown()

simplefancontroller.sfc.database module

class simplefancontroller.sfc.database.SFCDatabaseClient(settings: SFCDBSettings)

Bases: ABC

Abstract base class for SimpleFanController Database Clients.

connected

indicator that shows whether the client is connected to the database or not

Type

bool

settings

settings for the client

Type

SFCDBSettings

connect()

Connects to database

connected: bool
data_manager: SFCDataManager
disconnect()

Disconnects from database.

classmethod from_settings(settings: SFCDBSettings)
write(fan: SFCFan)

Writes a fan’s current intensity to a database.

Parameters

fan (SFCFan) – fan to persist

class simplefancontroller.sfc.database.SFCInfluxDBClient(settings: SFCDBSettings)

Bases: SFCDatabaseClient

InfluxDB client for SimpleFanController

client: InfluxDBClient
settings: SFCInfluxDBSettings

simplefancontroller.sfc.fans module

class simplefancontroller.sfc.fans.SFC2PinFan(settings)

Bases: SFCFan

Class for 2-pin fans.

device: Optional[OutputDevice]
class simplefancontroller.sfc.fans.SFCFan(settings: SFCFanSettings)

Bases: ABC

Base class for SFCFans.

settings

the fan’s settings

Type

SFCFanSettings

intensity

the intensity that the fan is operating on

Type

float

device

gpiozero Device to be controlled

Type

OutputDevice

connect()

Sets the device attribute of the correct Device class.

device: Union[None, OutputDevice, PWMOutputDevice]
classmethod from_settings(settings: SFCFanSettings)
property intensity: Optional[float]
property settings: SFCFanSettings
shutdown()

Stops the fan, releases the GPIO pin and removes the attached device.

Does nothing, if the device is already closed.

start()

Starts the fan.

property state
stop()

Stops the fan.

update_device()

Updates the Fan’s device with the Fan’s current settings.

update_status(temperature: float)

Calculates a new intensity and sets the pins.

class simplefancontroller.sfc.fans.SFCFanState(*, name: str, active: bool, intensity: float, is_stopped: bool)

Bases: BaseModel

active: bool
classmethod from_fan(fan)
intensity: float
is_stopped: bool
name: str
class simplefancontroller.sfc.fans.SFCPWMFan(settings)

Bases: SFCFan

Class for PWM controlled fans.

This class is used for 4-pin fans that can be controlled using Pule Width Modulation (PWM).

device: PWMOutputDevice

simplefancontroller.sfc.settings module

Settings for various parts of SFC

Settings objects have two purposes: - they are used for controlling different parts of SFC - they can be used as DTOs.

class simplefancontroller.sfc.settings.SFC2PinFanSettings(*, name: str, gpio_pin: int, active: bool = True, invert_signal: bool = False, off_threshold: int = 40, shutdown_lag: int = 5)

Bases: SFCFanSettings

off_threshold: int
shutdown_lag: int
class simplefancontroller.sfc.settings.SFCDBSettings(*, name: str, active: bool = False)

Bases: BaseModel, ABC

active: bool
name: str
class simplefancontroller.sfc.settings.SFCFanSettings(*, name: str, gpio_pin: int, active: bool = True, invert_signal: bool = False)

Bases: BaseModel, ABC

class Config

Bases: object

arbitrary_types_allowed = True
active: bool
gpio_pin: int
invert_signal: bool
name: str
class simplefancontroller.sfc.settings.SFCInfluxDBSettings(*, name: str, active: bool = False, hostname: str, token: str, bucket: str, organisation: str, port: int = 8086, measurement: str = 'fans')

Bases: SFCDBSettings

bucket: str
hostname: str
measurement: str
organisation: str
port: int
token: str
class simplefancontroller.sfc.settings.SFCPWMFanSettings(*, name: str, gpio_pin: int, active: bool = True, invert_signal: bool = False, pwm_frequency: int = 25000, off_threshold: int = 40, max_threshold: int = 80)

Bases: SFCFanSettings

classmethod max_gt_off_threshold(v)
max_threshold: int
classmethod off_lt_max_threshold(v)
off_threshold: int
pwm_frequency: int
class simplefancontroller.sfc.settings.SFCThreadManagerSettings(*, active: bool = False, refresh_delay: int = 10)

Bases: BaseModel

active: bool
refresh_delay: int
class simplefancontroller.sfc.settings.SFControllerSettings(*, debug: bool = True, active: bool = False, refresh_delay: int = 10, sensor_file: str = '/sys/class/thermal/thermal_zone0/temp')

Bases: BaseModel

active: bool
debug: bool
refresh_delay: int
sensor_file: str

simplefancontroller.sfc.storage module

class simplefancontroller.sfc.storage.SFCFanStorage(data_manager: SFCDataManager)

Bases: object

Storage for SFCFan instances.

Stores SFCFan instances in a list and provides an API for interacting with them.

data_manager

persists data

Type

SFCDataManager

_container

list that contains the SFCFan instances

Type

list

add_fan(fan: SFCFan)

Adds a fan to the Storage.

Parameters

fan (SFCFan) – fan to add

data_manager: SFCDataManager
get_fan(fan_name: str) SFCFan

Queries a fan instance by its name.

Parameters

fan_name (str) – name of fan to query

Returns

SFCFan with specified name

get_fan_names() Generator[str, None, None]

Returns the names of all SFCFan instances in the storage.

Yields

names of all SFCFan instances

get_fans()

Returns all SFCFan instances in the storage.

Yields

SFCFan instances stored in the storage

get_occupied_pins() list[int]

Returns a list of occupied GPIO pins

Yields

GPIO pins currently occupied by SimpleFanController

get_state() dict[str, simplefancontroller.sfc.fans.SFCFanState]

Returns the current fan intensities.

Yields

tuples consisting of SFCFan names and stringified fan intensities

remove_fan(fan_name: str)

Removes a fan from the storage by name.

Parameters

fan_name (str) – name of fan to remove

shutdown()

Shuts down all fans managed by this SFCFanManager instance.

start()

Stops all fans.

stop()

Starts all fans.

update_fan(fan_name: str, settings: SFCFanSettings)

Update a fan with new settings.

Parameters
  • fan_name – name of SFCFan to update

  • settings – settings to apply to SFCFan

simplefancontroller.sfc.thread_manager module

class simplefancontroller.sfc.thread_manager.SFCThreadManager(cpu_temp_fun: Callable, fan_ctl_fun: Callable, settings: Union[None, SFControllerSettings, SFCThreadManagerSettings] = None)

Bases: object

Manager for the fan controlling thread.

The SFCThreadManager starts and controls a thread dedicated to regularly polling the CPU temperature and updating the fan intensities.

cpu_temp_fun

callable that reads the current CPU temperature

Type

Callable

fan_ctl_fun

callable that controls the fan intensities

Type

Callable

settings

settings object

cpu_temp_fun: Callable
fan_ctl_fun: Callable
restart()

Restarts the controller thread.

property settings: SFCThreadManagerSettings
start()

Starts the controller thread.

stop()

Stops the controller thread.

Module contents